Skip to content

Commit 5158108

Browse files
author
Pablo Orgaz
committed
Remove old test code
1 parent 9a62bc2 commit 5158108

File tree

6 files changed

+28
-103
lines changed

6 files changed

+28
-103
lines changed

app/src/test/java/org/sample/session/store/SessionStoreTest.kt

Lines changed: 0 additions & 70 deletions
This file was deleted.

mini-common/src/main/java/mini/Store.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ abstract class Store<S : Any> {
6565
}
6666

6767
@Suppress("UNCHECKED_CAST")
68-
protected open fun initialState(): S {
68+
open fun initialState(): S {
6969
val type = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]
7070
as Class<S>
7171
try {
@@ -89,11 +89,21 @@ abstract class Store<S : Any> {
8989
}
9090
}
9191

92-
/** Thread safe, since espresso runs in it's own thread */
92+
/** Test only method, don't use in app code */
9393
@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)
97101
}
98102
}
103+
104+
/** Set state back to initial default */
105+
@TestOnly
106+
fun resetState() {
107+
setTestState(initialState())
108+
}
99109
}

mini-common/src/main/java/mini/Threading.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ inline fun <T> Handler.postSync(crossinline block: () -> T) {
4444
}
4545
sem.acquireUninterruptibly()
4646
}
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+
}
4758
}

mini-common/src/test/kotlin/mini/DynamicActionReducerTest.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

mini-common/src/test/kotlin/mini/RxUtilsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RxUtilsTest {
1010

1111
data class TestModel(val someString: String? = null)
1212
data class TestState(val someTask: Task = taskIdle())
13-
class TestStore : Store<TestState>(Dispatcher())
13+
class TestStore : Store<TestState>()
1414

1515
private val testProcessor = PublishProcessor.create<TestModel>()
1616
private val subscriptionTracker = CompositeDisposable()

mini-common/src/test/kotlin/mini/StateMergerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class StateMergerTest {
77

88
@Test
99
fun merge_states_produces_the_correct_state() {
10-
class DummyStore : Store<String>(Dispatcher()) {
10+
class DummyStore : Store<String>() {
1111
override fun initialState() = ""
1212
}
1313

0 commit comments

Comments
 (0)