@@ -30,21 +30,21 @@ class StateInTest : TestBase() {
30
30
31
31
@Test
32
32
fun testUpstreamCompletedNoInitialValue () =
33
- testUpstreamCompletedOrFailedReset(failed = false , iv = false )
33
+ testUpstreamCompletedOrFailedReset(failed = false , withInitialValue = false )
34
34
35
35
@Test
36
36
fun testUpstreamFailedNoInitialValue () =
37
- testUpstreamCompletedOrFailedReset(failed = true , iv = false )
37
+ testUpstreamCompletedOrFailedReset(failed = true , withInitialValue = false )
38
38
39
39
@Test
40
40
fun testUpstreamCompletedWithInitialValue () =
41
- testUpstreamCompletedOrFailedReset(failed = false , iv = true )
41
+ testUpstreamCompletedOrFailedReset(failed = false , withInitialValue = true )
42
42
43
43
@Test
44
44
fun testUpstreamFailedWithInitialValue () =
45
- testUpstreamCompletedOrFailedReset(failed = true , iv = true )
45
+ testUpstreamCompletedOrFailedReset(failed = true , withInitialValue = true )
46
46
47
- private fun testUpstreamCompletedOrFailedReset (failed : Boolean , iv : Boolean ) = runTest {
47
+ private fun testUpstreamCompletedOrFailedReset (failed : Boolean , withInitialValue : Boolean ) = runTest {
48
48
val emitted = Job ()
49
49
val terminate = Job ()
50
50
val sharingJob = CompletableDeferred <Unit >()
@@ -56,7 +56,7 @@ class StateInTest : TestBase() {
56
56
}
57
57
val scope = this + sharingJob
58
58
val shared: StateFlow <String ?>
59
- if (iv ) {
59
+ if (withInitialValue ) {
60
60
shared = upstream.stateIn(scope, SharingStarted .Eagerly , null )
61
61
assertEquals(null , shared.value)
62
62
} else {
@@ -75,4 +75,15 @@ class StateInTest : TestBase() {
75
75
assertNull(sharingJob.getCompletionExceptionOrNull())
76
76
}
77
77
}
78
- }
78
+
79
+ @Test
80
+ fun testUpstreamFailedIMmediatelyWithInitialValue () = runTest {
81
+ val ceh = CoroutineExceptionHandler { _, _ -> expect(2 ) }
82
+ val flow = flow<Int > {
83
+ expect(1 )
84
+ throw TestException ()
85
+ }
86
+ assertFailsWith<TestException > { flow.stateIn(CoroutineScope (ceh)) }
87
+ finish(3 )
88
+ }
89
+ }
0 commit comments