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 {
37
40
38
41
@ Mock
39
- Observer <String > w ;
42
+ private Observer <String > w ;
40
43
@ Mock
41
- Observer <String > w2 ;
44
+ private Observer <String > w2 ;
42
45
43
46
// nulls lead to exceptions
44
- final Func1 <String , String > TO_UPPER_WITH_EXCEPTION = new Func1 <String , String >() {
47
+ private final static Func1 <String , String > TO_UPPER_WITH_EXCEPTION = new Func1 <String , String >() {
45
48
@ Override
46
49
public String call (String s ) {
47
50
if (s .equals ("x" )) {
@@ -50,6 +53,13 @@ public String call(String s) {
50
53
return s .toUpperCase ();
51
54
}
52
55
};
56
+
57
+ private final static Func1 <String , String > THROWS_NON_FATAL = new Func1 <String , String >() {
58
+ @ Override
59
+ public String call (String s ) {
60
+ throw new RuntimeException ();
61
+ }
62
+ };
53
63
54
64
@ Before
55
65
public void before () {
@@ -138,4 +148,20 @@ public void testDistinctUntilChangedOfSourceWithExceptionsFromKeySelector() {
138
148
inOrder .verify (w , never ()).onNext (anyString ());
139
149
inOrder .verify (w , never ()).onCompleted ();
140
150
}
151
+
152
+ @ Test
153
+ public void testDistinctUntilChangedWhenNonFatalExceptionThrownByKeySelectorIsNotReportedByUpstream () {
154
+ Observable <String > src = Observable .just ("a" , "b" , null , "c" );
155
+ final AtomicBoolean errorOccurred = new AtomicBoolean (false );
156
+ src
157
+ .doOnError (new Action1 <Throwable >() {
158
+ @ Override
159
+ public void call (Throwable t ) {
160
+ errorOccurred .set (true );
161
+ }
162
+ })
163
+ .distinctUntilChanged (THROWS_NON_FATAL )
164
+ .subscribe (w );
165
+ assertFalse (errorOccurred .get ());
166
+ }
141
167
}
0 commit comments