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 .anyString ;
20
21
import static org .mockito .Mockito .inOrder ;
23
24
import static org .mockito .Mockito .verify ;
24
25
import static org .mockito .MockitoAnnotations .initMocks ;
25
26
27
+ import java .util .concurrent .atomic .AtomicBoolean ;
26
28
27
29
import org .junit .Before ;
28
30
import org .junit .Test ;
31
33
32
34
import rx .Observable ;
33
35
import rx .Observer ;
36
+ import rx .functions .Action1 ;
34
37
import rx .functions .Func1 ;
35
38
36
39
public class OperatorDistinctUntilChangedTest {
@@ -50,6 +53,15 @@ public String call(String s) {
50
53
return s .toUpperCase ();
51
54
}
52
55
};
56
+
57
+ final Func1 <String , String > THROWS_NON_FATAL = new Func1 <String , String >() {
58
+ @ Override
59
+ public String call (String s ) {
60
+ throw new RuntimeException ();
61
+ }
62
+ };
63
+
64
+
53
65
54
66
@ Before
55
67
public void before () {
@@ -138,4 +150,20 @@ public void testDistinctUntilChangedOfSourceWithExceptionsFromKeySelector() {
138
150
inOrder .verify (w , never ()).onNext (anyString ());
139
151
inOrder .verify (w , never ()).onCompleted ();
140
152
}
153
+
154
+ @ Test
155
+ public void testDistinctUntilChangedWhenNonFatalExceptionThrownByKeySelectorIsNotReportedByUpstream () {
156
+ Observable <String > src = Observable .just ("a" , "b" , null , "c" );
157
+ final AtomicBoolean errorOccurred = new AtomicBoolean (false );
158
+ src
159
+ .doOnError (new Action1 <Throwable >() {
160
+ @ Override
161
+ public void call (Throwable t ) {
162
+ errorOccurred .set (true );
163
+ }
164
+ })
165
+ .distinctUntilChanged (THROWS_NON_FATAL )
166
+ .subscribe (w );
167
+ assertFalse (errorOccurred .get ());
168
+ }
141
169
}
0 commit comments