27
27
import rx .Subscription ;
28
28
import rx .android .plugins .RxAndroidPlugins ;
29
29
import rx .android .plugins .RxAndroidSchedulersHook ;
30
+ import rx .android .testutil .CountingAction ;
30
31
import rx .exceptions .OnErrorNotImplementedException ;
31
32
import rx .functions .Action0 ;
32
33
36
37
import static org .junit .Assert .assertSame ;
37
38
import static org .junit .Assert .assertTrue ;
38
39
import static org .junit .Assert .fail ;
39
- import static org .mockito .Mockito .mock ;
40
- import static org .mockito .Mockito .never ;
41
- import static org .mockito .Mockito .verify ;
42
40
import static org .robolectric .shadows .ShadowLooper .idleMainLooper ;
43
41
import static org .robolectric .shadows .ShadowLooper .pauseMainLooper ;
44
42
import static org .robolectric .shadows .ShadowLooper .runUiThreadTasks ;
@@ -67,57 +65,57 @@ public void tearDown() {
67
65
public void schedulePostsActionImmediately () {
68
66
Worker worker = scheduler .createWorker ();
69
67
70
- Action0 action = mock ( Action0 . class );
68
+ CountingAction action = new CountingAction ( );
71
69
worker .schedule (action );
72
70
73
71
runUiThreadTasks ();
74
- verify ( action ). call ( );
72
+ assertEquals ( 1 , action . get () );
75
73
}
76
74
77
75
@ Test
78
76
public void scheduleWithDelayPostsActionWithDelay () {
79
77
Worker worker = scheduler .createWorker ();
80
78
81
- Action0 action = mock ( Action0 . class );
79
+ CountingAction action = new CountingAction ( );
82
80
worker .schedule (action , 1 , MINUTES );
83
81
84
82
runUiThreadTasks ();
85
- verify ( action , never ()). call ( );
83
+ assertEquals ( 0 , action . get () );
86
84
87
85
idleMainLooper (MINUTES .toMillis (1 ));
88
86
runUiThreadTasks ();
89
- verify ( action ). call ( );
87
+ assertEquals ( 1 , action . get () );
90
88
}
91
89
92
90
@ Test
93
91
public void unsubscribeCancelsScheduledAction () {
94
92
Worker worker = scheduler .createWorker ();
95
93
96
- Action0 action = mock ( Action0 . class );
94
+ CountingAction action = new CountingAction ( );
97
95
Subscription subscription = worker .schedule (action );
98
96
subscription .unsubscribe ();
99
97
100
98
runUiThreadTasks ();
101
- verify ( action , never ()). call ( );
99
+ assertEquals ( 0 , action . get () );
102
100
}
103
101
104
102
@ Test
105
103
public void unsubscribeCancelsScheduledActionWithDelay () {
106
104
Worker worker = scheduler .createWorker ();
107
105
108
- Action0 action = mock ( Action0 . class );
106
+ CountingAction action = new CountingAction ( );
109
107
Subscription subscription = worker .schedule (action , 1 , MINUTES );
110
108
subscription .unsubscribe ();
111
109
112
110
runUiThreadTasksIncludingDelayedTasks ();
113
- verify ( action , never ()). call ( );
111
+ assertEquals ( 0 , action . get () );
114
112
}
115
113
116
114
@ Test
117
115
public void unsubscribeState () {
118
116
Worker worker = scheduler .createWorker ();
119
117
120
- Action0 action = mock ( Action0 . class );
118
+ Action0 action = new CountingAction ( );
121
119
Subscription subscription = worker .schedule (action );
122
120
assertFalse (subscription .isUnsubscribed ());
123
121
@@ -127,7 +125,7 @@ public void unsubscribeState() {
127
125
128
126
@ Test
129
127
public void schedulerHookIsUsed () {
130
- final Action0 newAction = mock ( Action0 . class );
128
+ final CountingAction newAction = new CountingAction ( );
131
129
final AtomicReference <Action0 > actionRef = new AtomicReference <>();
132
130
RxAndroidPlugins .getInstance ().registerSchedulersHook (new RxAndroidSchedulersHook () {
133
131
@ Override public Action0 onSchedule (Action0 action ) {
@@ -138,28 +136,28 @@ public void schedulerHookIsUsed() {
138
136
139
137
Worker worker = scheduler .createWorker ();
140
138
141
- Action0 action = mock ( Action0 . class );
139
+ CountingAction action = new CountingAction ( );
142
140
worker .schedule (action );
143
141
144
142
// Verify our action was passed to the schedulers hook.
145
143
assertSame (action , actionRef .get ());
146
144
147
145
// Verify the scheduled action was the one returned from the hook.
148
146
runUiThreadTasks ();
149
- verify ( newAction ). call ( );
150
- verify ( action , never ()). call ( );
147
+ assertEquals ( 1 , newAction . get () );
148
+ assertEquals ( 0 , action . get () );
151
149
}
152
150
153
151
@ Test
154
152
public void workerUnsubscriptionPreventsScheduling () {
155
153
Worker worker = scheduler .createWorker ();
156
154
worker .unsubscribe ();
157
155
158
- Action0 action = mock ( Action0 . class );
156
+ CountingAction action = new CountingAction ( );
159
157
worker .schedule (action );
160
158
161
159
runUiThreadTasks ();
162
- verify ( action , never ()). call ( );
160
+ assertEquals ( 0 , action . get () );
163
161
}
164
162
165
163
@ Test
@@ -176,41 +174,41 @@ public void workerUnsubscriptionDuringSchedulingCancelsScheduledAction() {
176
174
Scheduler .Worker worker = scheduler .createWorker ();
177
175
workerRef .set (worker );
178
176
179
- Action0 action = mock ( Action0 . class );
177
+ CountingAction action = new CountingAction ( );
180
178
worker .schedule (action );
181
179
182
180
runUiThreadTasks ();
183
- verify ( action , never ()). call ( );
181
+ assertEquals ( 0 , action . get () );
184
182
}
185
183
186
184
@ Test
187
185
public void workerUnsubscriptionCancelsScheduled () {
188
186
Worker worker = scheduler .createWorker ();
189
187
190
- Action0 action = mock ( Action0 . class );
188
+ CountingAction action = new CountingAction ( );
191
189
worker .schedule (action , 1 , MINUTES );
192
190
193
191
worker .unsubscribe ();
194
192
195
193
runUiThreadTasks ();
196
- verify ( action , never ()). call ( );
194
+ assertEquals ( 0 , action . get () );
197
195
}
198
196
199
197
@ Test
200
198
public void workerUnsubscriptionDoesNotAffectOtherWorkers () {
201
199
Scheduler .Worker workerA = scheduler .createWorker ();
202
- Action0 actionA = mock ( Action0 . class );
200
+ CountingAction actionA = new CountingAction ( );
203
201
workerA .schedule (actionA , 1 , MINUTES );
204
202
205
203
Scheduler .Worker workerB = scheduler .createWorker ();
206
- Action0 actionB = mock ( Action0 . class );
204
+ CountingAction actionB = new CountingAction ( );
207
205
workerB .schedule (actionB , 1 , MINUTES );
208
206
209
207
workerA .unsubscribe ();
210
208
211
209
runUiThreadTasksIncludingDelayedTasks ();
212
- verify ( actionA , never ()). call ( );
213
- verify ( actionB ). call ( );
210
+ assertEquals ( 0 , actionA . get () );
211
+ assertEquals ( 1 , actionB . get () );
214
212
}
215
213
216
214
@ Test
0 commit comments