13
13
14
14
package io .reactivex .flowable ;
15
15
16
+ import static org .junit .Assert .assertEquals ;
17
+
16
18
import java .util .HashMap ;
19
+ import java .util .concurrent .Callable ;
20
+ import java .util .concurrent .atomic .AtomicInteger ;
17
21
22
+ import org .junit .Assert ;
18
23
import org .junit .Test ;
19
24
25
+ import io .reactivex .Flowable ;
20
26
import io .reactivex .flowable .FlowableEventStream .Event ;
21
27
import io .reactivex .functions .*;
22
28
@@ -41,4 +47,83 @@ public void accept(HashMap<String, String> v) {
41
47
}
42
48
});
43
49
}
50
+
51
+ @ Test
52
+ public void testFlowableScanSeedDoesNotEmitErrorTwiceIfScanFunctionThrows () {
53
+ final RuntimeException e = new RuntimeException ();
54
+ Burst .item (1 ).error (e ).scan (0 , new BiFunction <Integer , Integer , Integer >() {
55
+
56
+ @ Override
57
+ public Integer apply (Integer n1 , Integer n2 ) throws Exception {
58
+ throw e ;
59
+ }})
60
+ .test ()
61
+ .assertNoValues ()
62
+ .assertError (e );
63
+ }
64
+
65
+ @ Test
66
+ public void testFlowableScanSeedDoesNotEmitTerminalEventTwiceIfScanFunctionThrows () {
67
+ final RuntimeException e = new RuntimeException ();
68
+ Burst .item (1 ).create ().scan (0 , new BiFunction <Integer , Integer , Integer >() {
69
+
70
+ @ Override
71
+ public Integer apply (Integer n1 , Integer n2 ) throws Exception {
72
+ throw e ;
73
+ }})
74
+ .test ()
75
+ .assertNoValues ()
76
+ .assertError (e );
77
+ }
78
+
79
+ @ Test
80
+ public void testFlowableScanSeedDoesNotProcessOnNextAfterTerminalEventIfScanFunctionThrows () {
81
+ final RuntimeException e = new RuntimeException ();
82
+ final AtomicInteger count = new AtomicInteger ();
83
+ Burst .items (1 , 2 ).create ().scan (0 , new BiFunction <Integer , Integer , Integer >() {
84
+
85
+ @ Override
86
+ public Integer apply (Integer n1 , Integer n2 ) throws Exception {
87
+ count .incrementAndGet ();
88
+ throw e ;
89
+ }})
90
+ .test ()
91
+ .assertNoValues ()
92
+ .assertError (e );
93
+ assertEquals (1 , count .get ());
94
+ }
95
+
96
+ @ Test
97
+ public void testFlowableScanSeedCompletesNormally () {
98
+ Flowable .just (1 ,2 ,3 ).scan (0 , new BiFunction <Integer , Integer , Integer >() {
99
+
100
+ @ Override
101
+ public Integer apply (Integer t1 , Integer t2 ) throws Exception {
102
+ return t1 + t2 ;
103
+ }})
104
+ .test ()
105
+ .assertValues (0 , 1 , 3 , 6 )
106
+ .assertComplete ();
107
+ }
108
+
109
+ @ Test
110
+ public void testFlowableScanSeedWhenScanSeedProviderThrows () {
111
+ final RuntimeException e = new RuntimeException ();
112
+ Flowable .just (1 ,2 ,3 ).scanWith (new Callable <Integer >() {
113
+ @ Override
114
+ public Integer call () throws Exception {
115
+ throw e ;
116
+ }
117
+ },
118
+ new BiFunction <Integer , Integer , Integer >() {
119
+
120
+ @ Override
121
+ public Integer apply (Integer t1 , Integer t2 ) throws Exception {
122
+ return t1 + t2 ;
123
+ }
124
+ })
125
+ .test ()
126
+ .assertError (e )
127
+ .assertNoValues ();
128
+ }
44
129
}
0 commit comments