1
- package rx .testing ;
1
+ package rx .operators ;
2
2
3
- import org .junit .Test ;
4
- import rx .Observable ;
5
- import rx .Observer ;
6
- import rx .Subscription ;
7
- import rx .subscriptions .Subscriptions ;
8
- import rx .util .functions .Func1 ;
3
+ import static org .junit .Assert .*;
9
4
10
5
import java .lang .Thread .UncaughtExceptionHandler ;
11
6
import java .util .ArrayList ;
12
7
import java .util .List ;
13
8
import java .util .concurrent .atomic .AtomicBoolean ;
14
9
import java .util .concurrent .atomic .AtomicReference ;
15
10
16
- import static org .junit .Assert .assertEquals ;
17
- import static org .junit .Assert .assertFalse ;
18
- import static org .junit .Assert .assertNotNull ;
11
+ import org .junit .Test ;
19
12
20
- public class TrustedObservableTester
13
+ import rx .Observable ;
14
+ import rx .Observer ;
15
+ import rx .Subscription ;
16
+ import rx .subscriptions .Subscriptions ;
17
+ import rx .util .functions .Func1 ;
18
+
19
+ /**
20
+ * Common utility functions for operator implementations and tests.
21
+ */
22
+ /* package */ class AbstractOperation
21
23
{
22
- private TrustedObservableTester () {}
24
+ private AbstractOperation () {
25
+ }
23
26
24
- public static < T > Func1 < Observer < T >, Subscription > assertTrustedObservable ( final Func1 < Observer < T >, Subscription > source )
25
- {
26
- return new Func1 <Observer <T >, Subscription >( )
27
+ public static class UnitTest {
28
+
29
+ public static < T > Func1 <Observer <T >, Subscription > assertTrustedObservable ( final Func1 < Observer < T >, Subscription > source )
27
30
{
28
- @ Override
29
- public Subscription call (Observer <T > observer )
31
+ return new Func1 <Observer <T >, Subscription >()
30
32
{
31
- return source .call (new TestingObserver <T >(observer ));
32
- }
33
- };
34
- }
33
+ @ Override
34
+ public Subscription call (Observer <T > observer )
35
+ {
36
+ return source .call (new TestingObserver <T >(observer ));
37
+ }
38
+ };
39
+ }
35
40
36
- public static class TestingObserver <T > implements Observer <T > {
41
+ public static class TestingObserver <T > implements Observer <T > {
37
42
38
- private final Observer <T > actual ;
39
- private final AtomicBoolean isFinished = new AtomicBoolean (false );
40
- private final AtomicBoolean isInCallback = new AtomicBoolean (false );
43
+ private final Observer <T > actual ;
44
+ private final AtomicBoolean isFinished = new AtomicBoolean (false );
45
+ private final AtomicBoolean isInCallback = new AtomicBoolean (false );
41
46
42
- public TestingObserver (Observer <T > actual ) {
43
- this .actual = actual ;
44
- }
47
+ public TestingObserver (Observer <T > actual ) {
48
+ this .actual = actual ;
49
+ }
45
50
46
- @ Override
47
- public void onCompleted () {
48
- assertFalse ("previous call to onCompleted() or onError()" , !isFinished .compareAndSet (false , true ));
49
- assertFalse ("concurrent callback pending" , !isInCallback .compareAndSet (false , true ));
50
- actual .onCompleted ();
51
- isInCallback .set (false );
52
- }
51
+ @ Override
52
+ public void onCompleted () {
53
+ assertFalse ("previous call to onCompleted() or onError()" , !isFinished .compareAndSet (false , true ));
54
+ assertFalse ("concurrent callback pending" , !isInCallback .compareAndSet (false , true ));
55
+ actual .onCompleted ();
56
+ isInCallback .set (false );
57
+ }
53
58
54
- @ Override
55
- public void onError (Exception e ) {
56
- assertFalse ("previous call to onCompleted() or onError()" , !isFinished .compareAndSet (false , true ));
57
- assertFalse ("concurrent callback pending" , !isInCallback .compareAndSet (false , true ));
58
- actual .onError (e );
59
- isInCallback .set (false );
60
- }
59
+ @ Override
60
+ public void onError (Exception e ) {
61
+ assertFalse ("previous call to onCompleted() or onError()" , !isFinished .compareAndSet (false , true ));
62
+ assertFalse ("concurrent callback pending" , !isInCallback .compareAndSet (false , true ));
63
+ actual .onError (e );
64
+ isInCallback .set (false );
65
+ }
61
66
62
- @ Override
63
- public void onNext (T args ) {
64
- assertFalse ("previous call to onCompleted() or onError()" , isFinished .get ());
65
- assertFalse ("concurrent callback pending" , !isInCallback .compareAndSet (false , true ));
66
- actual .onNext (args );
67
- isInCallback .set (false );
68
- }
67
+ @ Override
68
+ public void onNext (T args ) {
69
+ assertFalse ("previous call to onCompleted() or onError()" , isFinished .get ());
70
+ assertFalse ("concurrent callback pending" , !isInCallback .compareAndSet (false , true ));
71
+ actual .onNext (args );
72
+ isInCallback .set (false );
73
+ }
69
74
70
- }
75
+ }
71
76
72
- public static class UnitTest {
73
77
@ Test (expected = AssertionError .class )
74
78
public void testDoubleCompleted () {
75
79
Observable .create (assertTrustedObservable (new Func1 <Observer <String >, Subscription >()
@@ -141,7 +145,6 @@ public Subscription call(Observer<String> observer)
141
145
})).lastOrDefault ("end" );
142
146
}
143
147
144
-
145
148
@ Test (expected = AssertionError .class )
146
149
public void testErrorNext () {
147
150
Observable .create (assertTrustedObservable (new Func1 <Observer <String >, Subscription >()
@@ -250,4 +253,4 @@ public void onNext(String args)
250
253
}
251
254
}
252
255
}
253
- }
256
+ }
0 commit comments