This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class TestKittenDataSource( | |
private val scheduler: TestScheduler | |
) : KittenDataSource { | |
private var images by AtomicReference<List<String>?>(null) | |
private var seed by AtomicInt() | |
override fun load(limit: Int, page: Int): Maybe<String> = | |
singleFromFunction { images } | |
.notNull() | |
.map { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class KittenComponent internal constructor(dataSource: KittenDataSource) { | |
constructor() : this(KittenDataSource()) | |
fun onViewCreated(view: KittenView) { /* ... */ } | |
fun onStart() { /* ... */ } | |
fun onStop() { /* ... */ } | |
fun onViewDestroyed() { /* ... */ } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun isLoading_true_WHEN_loading() { | |
networkScheduler.isManualProcessing = true | |
network.generateImages() | |
val store = store() | |
assertTrue(store.state.isLoading) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun reloads_images_WHEN_Intent_Reload() { | |
network.generateImages() | |
val store = store() | |
val newImages = network.generateImages() | |
store.onNext(Intent.Reload) | |
assertEquals(State.Data.Images(urls = newImages), store.state.data) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun loads_images_WHEN_created() { | |
val images = network.generateImages() | |
val store = store() | |
assertEquals(State.Data.Images(urls = images), store.state.data) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KittenStoreTest { | |
private val network = TestKittenStoreNetwork() | |
private val parser = TestKittenStoreParser() | |
private fun store(): KittenStore = KittenStoreImpl(network, parser) | |
@BeforeTest | |
fun before() { | |
overrideSchedulers(main = { TestScheduler() }) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KittenStoreTest { | |
private val parser = TestKittenStoreParser() | |
private val networkScheduler = TestScheduler() | |
private val network = TestKittenStoreNetwork(networkScheduler) | |
private fun store(): KittenStore = KittenStoreImpl(network, parser) | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestKittenStoreParser : KittenStoreImpl.Parser { | |
override fun parse(json: String): Maybe<List<String>> = | |
json | |
.toSingle() | |
.filter { it != "" } | |
.map { it.split(SEPARATOR) } | |
.observeOn(TestScheduler()) | |
private companion object { | |
private const val SEPARATOR = ";" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Parser { | |
fun parse(json: String): Maybe<List<String>> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestKittenStoreNetwork( | |
private val scheduler: TestScheduler | |
) : KittenStoreImpl.Network { | |
var images: List<String>? by AtomicReference<List<String>?>(null) | |
private var seed: Int by AtomicInt() | |
override fun load(): Maybe<String> = | |
singleFromFunction { images } | |
.notNull() | |
.map { it.joinToString(separator = SEPARATOR) } |