Skip to content

Instantly share code, notes, and snippets.

@seoft
Created May 22, 2021 06:19
Show Gist options
  • Save seoft/a791ffba460d47eb056d2d5501dad461 to your computer and use it in GitHub Desktop.
Save seoft/a791ffba460d47eb056d2d5501dad461 to your computer and use it in GitHub Desktop.
MyTest.kt
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import io.reactivex.internal.functions.Functions
import io.reactivex.rxkotlin.subscribeBy
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.koin.test.KoinTest
import org.koin.test.inject
@RunWith(AndroidJUnit4::class)
class MyTest : KoinTest {
val settingRepository by inject<SettingRepository>()
val appContext by lazy { InstrumentationRegistry.getInstrumentation().targetContext } // not used here
@Rule
@JvmField
val rule = RxSchedulerRule()
@Test
fun testLatelySearchKeyword() {
settingRepository.clearLatelySearchKeyword().subscribe(Functions.EMPTY_ACTION)
settingRepository.getLatelySearchKeyword().subscribeBy(onSuccess = {
Assert.assertEquals(0, it.size)
})
settingRepository.addLatelySearchKeyword("111").subscribe(Functions.EMPTY_ACTION)
settingRepository.addLatelySearchKeyword("222").subscribe(Functions.EMPTY_ACTION)
settingRepository.addLatelySearchKeyword("333").subscribe(Functions.EMPTY_ACTION)
settingRepository.addLatelySearchKeyword("444").subscribe(Functions.EMPTY_ACTION)
settingRepository.addLatelySearchKeyword("111").subscribe(Functions.EMPTY_ACTION)
settingRepository.getLatelySearchKeyword().subscribeBy(onSuccess = {
Assert.assertEquals(listOf("111", "444", "333", "222"), it)
})
settingRepository.clearLatelySearchKeyword().subscribe(Functions.EMPTY_ACTION)
settingRepository.getLatelySearchKeyword().subscribeBy(onSuccess = {
Assert.assertEquals(0, it.size)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment