-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use typeOf as key instead of KClass in InstanceKeeper#getStore
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
55 changes: 55 additions & 0 deletions
55
...rc/commonTest/kotlin/com/arkivanov/mvikotlin/core/instancekeeper/InstanceKeeperExtTest.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.arkivanov.mvikotlin.core.instancekeeper | ||
|
||
import com.arkivanov.essenty.instancekeeper.InstanceKeeperDispatcher | ||
import com.arkivanov.mvikotlin.core.rx.Disposable | ||
import com.arkivanov.mvikotlin.core.rx.Observer | ||
import com.arkivanov.mvikotlin.core.store.Store | ||
import kotlin.test.Test | ||
import kotlin.test.assertNotSame | ||
import kotlin.test.assertSame | ||
|
||
@Suppress("TestFunctionName") | ||
class InstanceKeeperExtTest { | ||
|
||
private val keeper = InstanceKeeperDispatcher() | ||
|
||
@Test | ||
fun WHEN_getStore_with_same_type_THEN_same_instance() { | ||
val store1 = keeper.getStore { store<String, Float, Int>() } | ||
val store2 = keeper.getStore { store<String, Float, Int>() } | ||
|
||
assertSame(store1, store2) | ||
} | ||
|
||
@Test | ||
fun WHEN_getStore_with_different_types_THEN_instances_not_same() { | ||
val store1 = keeper.getStore { store<Int, String, Float>() } | ||
val store2 = keeper.getStore { store<String, Float, Int>() } | ||
|
||
assertNotSame<Store<*, *, *>>(store1, store2) | ||
} | ||
|
||
private fun <Intent : Any, State : Any, Label : Any> store(): Store<Intent, State, Label> = | ||
object : Store<Intent, State, Label> { | ||
override val state: State get() = error("Not implemented") | ||
override val isDisposed: Boolean get() = error("Not implemented") | ||
|
||
override fun states(observer: Observer<State>): Disposable = | ||
error("Not implemented") | ||
|
||
override fun labels(observer: Observer<Label>): Disposable = | ||
error("Not implemented") | ||
|
||
override fun accept(intent: Intent) { | ||
error("Not implemented") | ||
} | ||
|
||
override fun init() { | ||
error("Not implemented") | ||
} | ||
|
||
override fun dispose() { | ||
error("Not implemented") | ||
} | ||
} | ||
} |