15
15
*/
16
16
package rx .internal .operators ;
17
17
18
+ import static org .junit .Assert .assertFalse ;
18
19
import static org .mockito .Matchers .any ;
19
20
import static org .mockito .Matchers .anyInt ;
20
21
import static org .mockito .Mockito .inOrder ;
23
24
import static org .mockito .Mockito .times ;
24
25
import static org .mockito .Mockito .verify ;
25
26
27
+ import java .util .concurrent .atomic .AtomicBoolean ;
28
+
26
29
import org .junit .Test ;
27
30
import org .mockito .InOrder ;
28
31
29
32
import rx .Observable ;
30
33
import rx .Observer ;
34
+ import rx .functions .Action1 ;
31
35
import rx .functions .Func1 ;
36
+ import rx .observers .Subscribers ;
37
+ import rx .observers .TestSubscriber ;
32
38
33
39
public class OperatorSkipWhileTest {
34
40
@@ -51,6 +57,20 @@ public Boolean call(Integer value) {
51
57
return index ++ < 3 ;
52
58
}
53
59
};
60
+
61
+ private static final Func1 <Integer , Boolean > THROWS_NON_FATAL = new Func1 <Integer , Boolean >() {
62
+ @ Override
63
+ public Boolean call (Integer values ) {
64
+ throw new RuntimeException ();
65
+ }
66
+ };
67
+
68
+ private static final Func1 <Integer , Boolean > THROWS_FATAL = new Func1 <Integer , Boolean >() {
69
+ @ Override
70
+ public Boolean call (Integer values ) {
71
+ throw new OutOfMemoryError ();
72
+ }
73
+ };
54
74
55
75
@ Test
56
76
public void testSkipWithIndex () {
@@ -120,6 +140,33 @@ public void testSkipError() {
120
140
inOrder .verify (w , times (1 )).onError (any (RuntimeException .class ));
121
141
}
122
142
143
+ @ Test
144
+ public void testPredicateRuntimeError () {
145
+ Observable .just (1 ).skipWhile (THROWS_NON_FATAL ).subscribe (w );
146
+ InOrder inOrder = inOrder (w );
147
+ inOrder .verify (w , never ()).onNext (anyInt ());
148
+ inOrder .verify (w , never ()).onCompleted ();
149
+ inOrder .verify (w , times (1 )).onError (any (RuntimeException .class ));
150
+ }
151
+
152
+ @ Test (expected = OutOfMemoryError .class )
153
+ public void testPredicateFatalError () {
154
+ Observable .just (1 ).skipWhile (THROWS_FATAL ).unsafeSubscribe (Subscribers .empty ());
155
+ }
156
+
157
+ @ Test
158
+ public void testPredicateRuntimeErrorDoesNotGoUpstreamFirst () {
159
+ final AtomicBoolean errorOccurred = new AtomicBoolean (false );
160
+ TestSubscriber <Integer > ts = TestSubscriber .create ();
161
+ Observable .just (1 ).doOnError (new Action1 <Throwable >() {
162
+ @ Override
163
+ public void call (Throwable t ) {
164
+ errorOccurred .set (true );
165
+ }
166
+ }).skipWhile (THROWS_NON_FATAL ).subscribe (ts );
167
+ assertFalse (errorOccurred .get ());
168
+ }
169
+
123
170
@ Test
124
171
public void testSkipManySubscribers () {
125
172
Observable <Integer > src = Observable .range (1 , 10 ).skipWhile (LESS_THAN_FIVE );
0 commit comments