Skip to content

Commit

Permalink
feat: Convert from Mockito to Mockk and Assertj to assertk (#460)
Browse files Browse the repository at this point in the history
Updated kotlin tests to use mockk and assertk.
Also update the code to remove the Playback jobs and migrated those
to repositories.
  • Loading branch information
kingargyle authored Dec 17, 2024
1 parent 2aef511 commit c1a1173
Show file tree
Hide file tree
Showing 57 changed files with 1,022 additions and 2,480 deletions.
3 changes: 2 additions & 1 deletion emby-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ dependencies {
debugImplementation(libs.toothpick.smoothie)

releaseApi(libs.toothpick.javax.annotations)
// kapt(libs.toothpick.compiler)
ksp(libs.toothpick.ksp.compiler)

implementation(libs.android.priority.jobqueue)
Expand All @@ -81,7 +80,9 @@ dependencies {

testImplementation(libs.junit)
testImplementation(libs.assertj.core)
testImplementation(libs.assertk.jvm)
testImplementation(libs.mockito.core)
testImplementation(libs.mockk)
testImplementation(libs.robolectric)
testImplementation(libs.robolectric.shadows.framework)
testImplementation(libs.robolectric.shadows.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import kotlinx.coroutines.test.runTest
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.robolectric.shadows.ShadowLog

class EmbyServerDiscoverTest {

private lateinit var serverDiscovery : EmbyServerDiscover

@Before
fun setUp() {
ShadowLog.stream = System.out
serverDiscovery = EmbyServerDiscover()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.nineworlds.serenity.emby.server

import android.content.Context
import io.mockk.mockk
import org.greenrobot.eventbus.EventBus
import org.junit.Before
import org.junit.Test
Expand All @@ -10,6 +11,7 @@ import org.mockito.MockitoAnnotations.initMocks
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.shadows.ShadowLog
import toothpick.config.Module
import us.nineworlds.serenity.common.android.injection.ApplicationContext
import us.nineworlds.serenity.emby.test.InjectingTest
Expand All @@ -18,17 +20,15 @@ import us.nineworlds.serenity.emby.test.InjectingTest
@Config(sdk = [28])
class EmbyServerJobTest : InjectingTest() {

@Mock
lateinit var mockEventBus: EventBus

override val modules: List<Any>
get() = mutableListOf(TestModule())

lateinit var job: EmbyServerJob
private lateinit var job: EmbyServerJob

@Before
override fun setUp() {
initMocks(this)
ShadowLog.stream = System.out

super.setUp()
job = EmbyServerJob()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package us.nineworlds.serenity.emby.server.api

import androidx.test.core.app.ApplicationProvider
import org.assertj.core.api.Assertions.assertThat
import assertk.assertThat
import assertk.assertions.hasSize
import assertk.assertions.isNotEmpty
import assertk.assertions.isNotNull
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -15,37 +18,37 @@ import us.nineworlds.serenity.emby.server.model.AuthenticationResult
@Config(sdk = [28])
class EmbyAPIClientTest {

lateinit var client: EmbyAPIClient
private lateinit var client: EmbyAPIClient

@Before
fun setUp() {
ShadowLog.stream = System.out

client = EmbyAPIClient(context = ApplicationProvider.getApplicationContext())
client.updateBaseUrl("http://192.168.86.162:8096")
client.updateBaseUrl("http://192.168.68.95:8096")
}

@Test
fun retrieveAllPublicUsers() {
val result = client.fetchAllPublicUsers()
assertThat(result).isNotEmpty.hasSize(2)
assertThat(result).hasSize(2)
}

@Test fun loginAdminUser() {
val authenticateResult = authenticate()

assertThat(authenticateResult).isNotNull()
assertThat(authenticateResult.accesToken).isNotBlank()
assertThat(client.serverId).isNotBlank()
assertThat(client.accessToken).isNotBlank()
assertThat(client.userId).isNotBlank()
assertThat(authenticateResult.accesToken).isNotEmpty()
assertThat(client.serverId).isNotEmpty()
assertThat(client.accessToken).isNotNull()
assertThat(client.userId).isNotNull().isNotEmpty()
}

@Test fun testCurrentUsersViews() {
authenticate()

val result = client.currentUserViews()
assertThat(result.items).isNotEmpty
assertThat(result.items).isNotEmpty()
}

@Test fun availableFiltersForCurrentUser() {
Expand All @@ -61,8 +64,8 @@ class EmbyAPIClientTest {
authenticate()

val result = client.retrieveRootData()
assertThat(result).isNotNull
assertThat(result!!.directories).isNotEmpty
assertThat(result).isNotNull()
assertThat(result.directories).isNotEmpty()
}

@Test fun createCategoriesForParentId() {
Expand All @@ -74,7 +77,7 @@ class EmbyAPIClientTest {

val categories = client.retrieveCategoriesById(parentId)

assertThat(categories.directories).isNotEmpty
assertThat(categories.directories).isNotEmpty()
}

@Test fun fetchAllMovies() {
Expand All @@ -85,7 +88,7 @@ class EmbyAPIClientTest {

val movies = client.retrieveItemByIdCategory(parentId, "all", Types.EPISODE)

assertThat(movies.videos).isNotEmpty
assertThat(movies.videos).isNotEmpty()
}

@Test fun fetchAllLatestMovies() {
Expand All @@ -97,7 +100,7 @@ class EmbyAPIClientTest {

val itemResult = client.retrieveItemByIdCategory(key, "recentlyAdded", Types.MOVIES)

assertThat(itemResult.videos).isNotEmpty
assertThat(itemResult.videos).isNotEmpty()

}

Expand Down
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
appVersion = "3.0-M1"
annotationVersion = "1.9.1"
appcompatVersion = "1.7.0"
assertkJvmVersion = "0.24"
assertkJvmVersion = "0.28.1"
cardviewVersion = "1.0.0"
commonsIo = "2.13.0"
commonsLang3Version = "3.7"
Expand All @@ -17,7 +17,7 @@ juniversalchardetVersion = "1.0.3"
kotlinVersion = "1.9.25"
kotlinCoroutinesVersion = "1.7.3"
kotlinKSPVersion = "1.9.25-1.0.20"
androidPluginVersion = "8.7.3"
androidPluginVersion = "8.6.1"
leanbackPreferenceVersion = "1.1.0-rc01"
leanbackVersion = "1.1.0-rc02"
legacySupportV4Version = "1.0.0"
Expand Down Expand Up @@ -55,6 +55,7 @@ easydeviceInfoVersion = "2.4.1"
androidxTestCoreVersion = "1.6.1"
androidxRecyclerViewVersion = "1.3.2"
resourcefulVersion = "1.1.0"
mockkVersion = "1.13.13"

[libraries]
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "annotationVersion" }
Expand All @@ -69,7 +70,6 @@ androidx-leanback-preference = { module = "androidx.leanback:leanback-preference
androidx-legacy-support-v4 = { module = "androidx.legacy:legacy-support-v4", version.ref = "legacySupportV4Version" }
androidx-percentlayout = { module = "androidx.percentlayout:percentlayout", version.ref = "percentlayoutVersion" }
androidx-recycler-view = { module = "androidx.recyclerview:recyclerview", version.ref = "androidxRecyclerViewVersion"}
assertk-jvm = { module = "com.willowtreeapps.assertk:assertk-jvm", version.ref = "assertkJvmVersion" }
commons-io = { module = "commons-io:commons-io", version.ref = "commonsIo" }
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commonsLang3Version" }
exoplayer-core = { module = "com.google.android.exoplayer:exoplayer-core", version.ref = "exoplayerVersion"}
Expand Down Expand Up @@ -123,6 +123,7 @@ assertj-core = { group = "org.assertj", name = "assertj-core", version.ref = "as
assertj-android = { group = "com.squareup.assertj", name = "assertj-android", version.ref = "assertJAndroidVersion"}
mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockitoVersion" }
mockito-kotlin = { module = "com.nhaarman.mockitokotlin2:mockito-kotlin", version = "2.2.0"}
mockk = { module = "io.mockk:mockk", version.ref = "mockkVersion" }
robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectricVersion" }
robolectric-shadows-framework = { group = "org.robolectric", name = "shadows-framework", version.ref = "robolectricVersion" }
robolectric-shadows-api = { group = "org.robolectric", name = "shadowapi", version.ref = "robolectricVersion" }
Expand All @@ -133,5 +134,6 @@ androidx-test-core = { group = "androidx.test", name = "core", version.ref = "an
kotlin-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinCoroutinesVersion" }

toothpick-testing = { group = "com.github.stephanenicolas.toothpick", name = "toothpick-testing", version.ref = "toothPickVersion"}
assertk-jvm = { module = "com.willowtreeapps.assertk:assertk", version.ref = "assertkJvmVersion" }

[plugins]
16 changes: 9 additions & 7 deletions serenity-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id("com.android.application")
id("project-report")
id("com.google.devtools.ksp")
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("kotlin-allopen")
id("org.sonarqube")
id("com.google.firebase.crashlytics")
id("com.google.gms.google-services") version "4.4.0"
id("com.google.devtools.ksp")
}

apply(from = "../jacoco.gradle")
Expand All @@ -30,25 +30,27 @@ allOpen {
android {
namespace = "us.nineworlds.serenity"

compileSdk = libs.versions.targetSdkVersion.get().toInt()

defaultConfig {
versionCode = 3000000
versionName = "3.0.0-M1"
minSdk = libs.versions.minSdkVersion.get().toInt()
targetSdk = libs.versions.targetSdkVersion.get().toInt()
multiDexEnabled = true
multiDexKeepProguard = file("multidex_keep_file.txt")
}

buildFeatures {
viewBinding = true
}
buildFeatures {
viewBinding = true
}


sourceSets {
getByName("main").java.srcDirs("src/main/kotlin", "src/main/java")
getByName("test").java.srcDirs("src/test/kotlin", "src/test/java")
}

compileSdk = libs.versions.targetSdkVersion.get().toInt()

if (project.hasProperty("keystore")) {
signingConfigs {
Expand Down Expand Up @@ -96,7 +98,6 @@ android {
maxHeapSize = "1512m"
setForkEvery(100)
maxParallelForks = 2
jvmArgs("-noverify")
testLogging {
setExceptionFormat("full")
}
Expand Down Expand Up @@ -191,6 +192,7 @@ dependencies {
exclude(group = "xpp3")
}

testImplementation(libs.mockk)
testImplementation(libs.mockito.core)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.commons.lang3)
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit c1a1173

Please sign in to comment.