28
28
29
29
import rx .Observer ;
30
30
import rx .Subscription ;
31
+ import rx .observers .TestObserver ;
31
32
import rx .util .functions .Action1 ;
32
33
33
34
public class AsyncSubjectTest {
@@ -39,77 +40,77 @@ public void testNeverCompleted() {
39
40
AsyncSubject <String > subject = AsyncSubject .create ();
40
41
41
42
@ SuppressWarnings ("unchecked" )
42
- Observer <String > aObserver = mock (Observer .class );
43
- subject .toObservable ().subscribe (aObserver );
43
+ Observer <String > observer = mock (Observer .class );
44
+ subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
44
45
45
46
subject .onNext ("one" );
46
47
subject .onNext ("two" );
47
48
subject .onNext ("three" );
48
49
49
- verify (aObserver , Mockito .never ()).onNext (anyString ());
50
- verify (aObserver , Mockito .never ()).onError (testException );
51
- verify (aObserver , Mockito .never ()).onCompleted ();
50
+ verify (observer , Mockito .never ()).onNext (anyString ());
51
+ verify (observer , Mockito .never ()).onError (testException );
52
+ verify (observer , Mockito .never ()).onCompleted ();
52
53
}
53
54
54
55
@ Test
55
56
public void testCompleted () {
56
57
AsyncSubject <String > subject = AsyncSubject .create ();
57
58
58
59
@ SuppressWarnings ("unchecked" )
59
- Observer <String > aObserver = mock (Observer .class );
60
- subject .toObservable ().subscribe (aObserver );
60
+ Observer <String > observer = mock (Observer .class );
61
+ subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
61
62
62
63
subject .onNext ("one" );
63
64
subject .onNext ("two" );
64
65
subject .onNext ("three" );
65
66
subject .onCompleted ();
66
67
67
- verify (aObserver , times (1 )).onNext ("three" );
68
- verify (aObserver , Mockito .never ()).onError (any (Throwable .class ));
69
- verify (aObserver , times (1 )).onCompleted ();
68
+ verify (observer , times (1 )).onNext ("three" );
69
+ verify (observer , Mockito .never ()).onError (any (Throwable .class ));
70
+ verify (observer , times (1 )).onCompleted ();
70
71
}
71
72
72
73
@ Test
73
74
public void testNull () {
74
75
AsyncSubject <String > subject = AsyncSubject .create ();
75
76
76
77
@ SuppressWarnings ("unchecked" )
77
- Observer <String > aObserver = mock (Observer .class );
78
- subject .toObservable ().subscribe (aObserver );
78
+ Observer <String > observer = mock (Observer .class );
79
+ subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
79
80
80
81
subject .onNext (null );
81
82
subject .onCompleted ();
82
83
83
- verify (aObserver , times (1 )).onNext (null );
84
- verify (aObserver , Mockito .never ()).onError (any (Throwable .class ));
85
- verify (aObserver , times (1 )).onCompleted ();
84
+ verify (observer , times (1 )).onNext (null );
85
+ verify (observer , Mockito .never ()).onError (any (Throwable .class ));
86
+ verify (observer , times (1 )).onCompleted ();
86
87
}
87
88
88
89
@ Test
89
90
public void testSubscribeAfterCompleted () {
90
91
AsyncSubject <String > subject = AsyncSubject .create ();
91
92
92
93
@ SuppressWarnings ("unchecked" )
93
- Observer <String > aObserver = mock (Observer .class );
94
+ Observer <String > observer = mock (Observer .class );
94
95
95
96
subject .onNext ("one" );
96
97
subject .onNext ("two" );
97
98
subject .onNext ("three" );
98
99
subject .onCompleted ();
99
100
100
- subject .toObservable ().subscribe (aObserver );
101
+ subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
101
102
102
- verify (aObserver , times (1 )).onNext ("three" );
103
- verify (aObserver , Mockito .never ()).onError (any (Throwable .class ));
104
- verify (aObserver , times (1 )).onCompleted ();
103
+ verify (observer , times (1 )).onNext ("three" );
104
+ verify (observer , Mockito .never ()).onError (any (Throwable .class ));
105
+ verify (observer , times (1 )).onCompleted ();
105
106
}
106
107
107
108
@ Test
108
109
public void testSubscribeAfterError () {
109
110
AsyncSubject <String > subject = AsyncSubject .create ();
110
111
111
112
@ SuppressWarnings ("unchecked" )
112
- Observer <String > aObserver = mock (Observer .class );
113
+ Observer <String > observer = mock (Observer .class );
113
114
114
115
subject .onNext ("one" );
115
116
subject .onNext ("two" );
@@ -118,20 +119,20 @@ public void testSubscribeAfterError() {
118
119
RuntimeException re = new RuntimeException ("failed" );
119
120
subject .onError (re );
120
121
121
- subject .toObservable ().subscribe (aObserver );
122
+ subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
122
123
123
- verify (aObserver , times (1 )).onError (re );
124
- verify (aObserver , Mockito .never ()).onNext (any (String .class ));
125
- verify (aObserver , Mockito .never ()).onCompleted ();
124
+ verify (observer , times (1 )).onError (re );
125
+ verify (observer , Mockito .never ()).onNext (any (String .class ));
126
+ verify (observer , Mockito .never ()).onCompleted ();
126
127
}
127
128
128
129
@ Test
129
130
public void testError () {
130
131
AsyncSubject <String > subject = AsyncSubject .create ();
131
132
132
133
@ SuppressWarnings ("unchecked" )
133
- Observer <String > aObserver = mock (Observer .class );
134
- subject .toObservable ().subscribe (aObserver );
134
+ Observer <String > observer = mock (Observer .class );
135
+ subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
135
136
136
137
subject .onNext ("one" );
137
138
subject .onNext ("two" );
@@ -141,50 +142,50 @@ public void testError() {
141
142
subject .onError (new Throwable ());
142
143
subject .onCompleted ();
143
144
144
- verify (aObserver , Mockito .never ()).onNext (anyString ());
145
- verify (aObserver , times (1 )).onError (testException );
146
- verify (aObserver , Mockito .never ()).onCompleted ();
145
+ verify (observer , Mockito .never ()).onNext (anyString ());
146
+ verify (observer , times (1 )).onError (testException );
147
+ verify (observer , Mockito .never ()).onCompleted ();
147
148
}
148
149
149
150
@ Test
150
151
public void testUnsubscribeBeforeCompleted () {
151
152
AsyncSubject <String > subject = AsyncSubject .create ();
152
153
153
154
@ SuppressWarnings ("unchecked" )
154
- Observer <String > aObserver = mock (Observer .class );
155
- Subscription subscription = subject .toObservable ().subscribe (aObserver );
155
+ Observer <String > observer = mock (Observer .class );
156
+ Subscription subscription = subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
156
157
157
158
subject .onNext ("one" );
158
159
subject .onNext ("two" );
159
160
160
161
subscription .unsubscribe ();
161
162
162
- verify (aObserver , Mockito .never ()).onNext (anyString ());
163
- verify (aObserver , Mockito .never ()).onError (any (Throwable .class ));
164
- verify (aObserver , Mockito .never ()).onCompleted ();
163
+ verify (observer , Mockito .never ()).onNext (anyString ());
164
+ verify (observer , Mockito .never ()).onError (any (Throwable .class ));
165
+ verify (observer , Mockito .never ()).onCompleted ();
165
166
166
167
subject .onNext ("three" );
167
168
subject .onCompleted ();
168
169
169
- verify (aObserver , Mockito .never ()).onNext (anyString ());
170
- verify (aObserver , Mockito .never ()).onError (any (Throwable .class ));
171
- verify (aObserver , Mockito .never ()).onCompleted ();
170
+ verify (observer , Mockito .never ()).onNext (anyString ());
171
+ verify (observer , Mockito .never ()).onError (any (Throwable .class ));
172
+ verify (observer , Mockito .never ()).onCompleted ();
172
173
}
173
174
174
175
@ Test
175
176
public void testEmptySubjectCompleted () {
176
177
AsyncSubject <String > subject = AsyncSubject .create ();
177
178
178
179
@ SuppressWarnings ("unchecked" )
179
- Observer <String > aObserver = mock (Observer .class );
180
- subject .toObservable ().subscribe (aObserver );
180
+ Observer <String > observer = mock (Observer .class );
181
+ subject .toObservable ().subscribe (new TestObserver < String >( observer ) );
181
182
182
183
subject .onCompleted ();
183
184
184
- InOrder inOrder = inOrder (aObserver );
185
- inOrder .verify (aObserver , never ()).onNext (null );
186
- inOrder .verify (aObserver , never ()).onNext (any (String .class ));
187
- inOrder .verify (aObserver , times (1 )).onCompleted ();
185
+ InOrder inOrder = inOrder (observer );
186
+ inOrder .verify (observer , never ()).onNext (null );
187
+ inOrder .verify (observer , never ()).onNext (any (String .class ));
188
+ inOrder .verify (observer , times (1 )).onCompleted ();
188
189
inOrder .verifyNoMoreInteractions ();
189
190
}
190
191
0 commit comments