@@ -11,10 +11,9 @@ import org.junit.ClassRule
11
11
import org.junit.Rule
12
12
import org.junit.Test
13
13
import org.mockito.Mock
14
- import org.mockito.Mockito.`when`
15
- import org.mockito.Mockito.verify
14
+ import org.mockito.Mockito
15
+ import org.mockito.Mockito.*
16
16
import org.mockito.MockitoAnnotations
17
- import org.mockito.Spy
18
17
19
18
20
19
class ComponentRuntimeTest {
@@ -24,7 +23,7 @@ class ComponentRuntimeTest {
24
23
@get:Rule
25
24
val instantExecutorRule = InstantTaskExecutorRule ()
26
25
27
- @Spy lateinit var runtime: ComponentRuntime <TestState , TestMsg >
26
+ lateinit var runtime: ComponentRuntime <TestState , TestMsg >
28
27
@Mock lateinit var observer: Observer <TestState >
29
28
@Mock lateinit var component: Component <TestState , TestMsg , TestCmd >
30
29
@@ -41,7 +40,8 @@ class ComponentRuntimeTest {
41
40
MockitoAnnotations .initMocks(this )
42
41
`when `(component.initState()).thenReturn(TestState (3 , " init" ))
43
42
lifecycleOwner = TestLifecycleOwner ()
44
- runtime = RuntimeFactory .create(component)
43
+ runtime = Mockito .spy(RuntimeFactory .create(component))
44
+ runtime.bindTo(lifecycleOwner)
45
45
}
46
46
47
47
@Test
@@ -56,6 +56,14 @@ class ComponentRuntimeTest {
56
56
lifecycleOwner.markState(Lifecycle .State .DESTROYED )
57
57
verify(runtime).clear()
58
58
}
59
+
60
+ @Test
61
+ fun autoClearNotCalled () {
62
+ lifecycleOwner.markState(Lifecycle .State .INITIALIZED )
63
+ lifecycleOwner.markState(Lifecycle .State .CREATED )
64
+ lifecycleOwner.markState(Lifecycle .State .RESUMED )
65
+ verify(runtime, never()).clear()
66
+ }
59
67
}
60
68
61
69
data class TestState (val number : Int , val text : String ): State
0 commit comments