File tree Expand file tree Collapse file tree 6 files changed +28
-103
lines changed
app/src/test/java/org/sample/session/store Expand file tree Collapse file tree 6 files changed +28
-103
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ abstract class Store<S : Any> {
65
65
}
66
66
67
67
@Suppress(" UNCHECKED_CAST" )
68
- protected open fun initialState (): S {
68
+ open fun initialState (): S {
69
69
val type = (javaClass.genericSuperclass as ParameterizedType ).actualTypeArguments[0 ]
70
70
as Class <S >
71
71
try {
@@ -89,11 +89,21 @@ abstract class Store<S : Any> {
89
89
}
90
90
}
91
91
92
- /* * Thread safe, since espresso runs in it's own thread */
92
+ /* * Test only method, don't use in app code */
93
93
@TestOnly
94
- fun setTestState (other : S ) {
95
- onUiSync {
96
- setStateInternal(other)
94
+ fun setTestState (s : S ) {
95
+ if (isAndroid) {
96
+ onUiSync {
97
+ setStateInternal(s)
98
+ }
99
+ } else {
100
+ setStateInternal(s)
97
101
}
98
102
}
103
+
104
+ /* * Set state back to initial default */
105
+ @TestOnly
106
+ fun resetState () {
107
+ setTestState(initialState())
108
+ }
99
109
}
Original file line number Diff line number Diff line change @@ -44,4 +44,15 @@ inline fun <T> Handler.postSync(crossinline block: () -> T) {
44
44
}
45
45
sem.acquireUninterruptibly()
46
46
}
47
+ }
48
+
49
+ /* *
50
+ * Check if running on android device / emulator or jvm
51
+ */
52
+ internal val isAndroid by lazy {
53
+ try {
54
+ android.os.Build .VERSION .SDK_INT != 0
55
+ } catch (e: Throwable ) {
56
+ false
57
+ }
47
58
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class RxUtilsTest {
10
10
11
11
data class TestModel (val someString : String? = null )
12
12
data class TestState (val someTask : Task = taskIdle())
13
- class TestStore : Store <TestState >(Dispatcher () )
13
+ class TestStore : Store <TestState >()
14
14
15
15
private val testProcessor = PublishProcessor .create<TestModel >()
16
16
private val subscriptionTracker = CompositeDisposable ()
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class StateMergerTest {
7
7
8
8
@Test
9
9
fun merge_states_produces_the_correct_state () {
10
- class DummyStore : Store <String >(Dispatcher () ) {
10
+ class DummyStore : Store <String >() {
11
11
override fun initialState () = " "
12
12
}
13
13
You can’t perform that action at this time.
0 commit comments