|
18 | 18 |
|
19 | 19 | import static hu.akarnokd.rxjava.interop.RxJavaInterop.*; |
20 | 20 | import static org.junit.Assert.*; |
21 | | -import static org.mockito.Mockito.mock; |
22 | | -import static org.mockito.Mockito.verify; |
23 | | -import static org.mockito.Mockito.verifyZeroInteractions; |
| 21 | +import static org.mockito.Mockito.*; |
24 | 22 |
|
25 | 23 | import java.io.IOException; |
26 | 24 | import java.lang.reflect.*; |
|
30 | 28 | import org.reactivestreams.Subscription; |
31 | 29 |
|
32 | 30 | import io.reactivex.*; |
| 31 | +import io.reactivex.Completable; |
| 32 | +import io.reactivex.Single; |
33 | 33 | import io.reactivex.disposables.*; |
34 | 34 | import io.reactivex.functions.Function; |
| 35 | +import io.reactivex.functions.Predicate; |
35 | 36 | import io.reactivex.internal.subscriptions.BooleanSubscription; |
| 37 | +import io.reactivex.observers.BaseTestConsumer; |
36 | 38 | import rx.Observable; |
37 | 39 | import rx.Observable.*; |
38 | 40 | import rx.Subscriber; |
@@ -159,11 +161,23 @@ public void o1f2Empty() { |
159 | 161 | .assertResult(); |
160 | 162 | } |
161 | 163 |
|
| 164 | + @SuppressWarnings("unchecked") |
| 165 | + static void assertFailureAndMessage(BaseTestConsumer<?, ?> testConsumer, Class<? extends Throwable> errorClass, final String message) { |
| 166 | + testConsumer |
| 167 | + .assertFailure(errorClass) |
| 168 | + .assertError(new Predicate<Throwable>() { |
| 169 | + @Override |
| 170 | + public boolean test(Throwable error) throws Throwable { |
| 171 | + return error.getMessage().equals(message); |
| 172 | + } |
| 173 | + }); |
| 174 | + } |
| 175 | + |
162 | 176 | @Test |
163 | 177 | public void o1f2Error() { |
164 | | - toV2Flowable(rx.Observable.error(new RuntimeException("Forced failure"))) |
165 | | - .test() |
166 | | - .assertFailureAndMessage(RuntimeException.class, "Forced failure"); |
| 178 | + assertFailureAndMessage(toV2Flowable(rx.Observable.error(new RuntimeException("Forced failure"))) |
| 179 | + .test(), |
| 180 | + RuntimeException.class, "Forced failure"); |
167 | 181 | } |
168 | 182 |
|
169 | 183 | @Test |
@@ -216,9 +230,9 @@ public void o1o2Empty() { |
216 | 230 |
|
217 | 231 | @Test |
218 | 232 | public void o1o2Error() { |
219 | | - toV2Observable(rx.Observable.error(new RuntimeException("Forced failure"))) |
220 | | - .test() |
221 | | - .assertFailureAndMessage(RuntimeException.class, "Forced failure"); |
| 233 | + assertFailureAndMessage(toV2Observable(rx.Observable.error(new RuntimeException("Forced failure"))) |
| 234 | + .test(), |
| 235 | + RuntimeException.class, "Forced failure"); |
222 | 236 | } |
223 | 237 |
|
224 | 238 | @Test |
@@ -283,20 +297,20 @@ public void s1s2Normal() { |
283 | 297 | @Test |
284 | 298 | public void s1s2Cancel() { |
285 | 299 | rx.subjects.PublishSubject<Integer> ps = rx.subjects.PublishSubject.create(); |
286 | | - io.reactivex.observers.TestObserver<Integer> ts = toV2Single(ps.toSingle()).test(); |
| 300 | + io.reactivex.observers.TestObserver<Integer> to = toV2Single(ps.toSingle()).test(); |
287 | 301 |
|
288 | 302 | assertTrue("1.x PublishSubject has no observers!", ps.hasObservers()); |
289 | 303 |
|
290 | | - ts.cancel(); |
| 304 | + to.dispose(); |
291 | 305 |
|
292 | 306 | assertFalse("1.x PublishSubject has observers!", ps.hasObservers()); |
293 | 307 |
|
294 | 308 | } |
295 | 309 |
|
296 | 310 | @Test |
297 | 311 | public void s1s2Error() { |
298 | | - toV2Single(rx.Single.error(new RuntimeException("Forced failure"))).test() |
299 | | - .assertFailureAndMessage(RuntimeException.class, "Forced failure"); |
| 312 | + assertFailureAndMessage(toV2Single(rx.Single.error(new RuntimeException("Forced failure"))).test() |
| 313 | + , RuntimeException.class, "Forced failure"); |
300 | 314 | } |
301 | 315 |
|
302 | 316 | @Test |
@@ -340,20 +354,20 @@ public void s1m2Normal() { |
340 | 354 | @Test |
341 | 355 | public void s1m2Cancel() { |
342 | 356 | rx.subjects.PublishSubject<Integer> ps = rx.subjects.PublishSubject.create(); |
343 | | - io.reactivex.observers.TestObserver<Integer> ts = toV2Maybe(ps.toSingle()).test(); |
| 357 | + io.reactivex.observers.TestObserver<Integer> to = toV2Maybe(ps.toSingle()).test(); |
344 | 358 |
|
345 | 359 | assertTrue("1.x PublishSubject has no observers!", ps.hasObservers()); |
346 | 360 |
|
347 | | - ts.cancel(); |
| 361 | + to.dispose(); |
348 | 362 |
|
349 | 363 | assertFalse("1.x PublishSubject has observers!", ps.hasObservers()); |
350 | 364 |
|
351 | 365 | } |
352 | 366 |
|
353 | 367 | @Test |
354 | 368 | public void s1m2Error() { |
355 | | - toV2Maybe(rx.Single.error(new RuntimeException("Forced failure"))).test() |
356 | | - .assertFailureAndMessage(RuntimeException.class, "Forced failure"); |
| 369 | + assertFailureAndMessage(toV2Maybe(rx.Single.error(new RuntimeException("Forced failure"))).test() |
| 370 | + , RuntimeException.class, "Forced failure"); |
357 | 371 | } |
358 | 372 |
|
359 | 373 | @Test |
@@ -401,19 +415,19 @@ public void c1c2Normal() { |
401 | 415 | @Test |
402 | 416 | public void c1c2Cancel() { |
403 | 417 | rx.subjects.PublishSubject<Integer> ps = rx.subjects.PublishSubject.create(); |
404 | | - io.reactivex.observers.TestObserver<Void> ts = toV2Completable(ps.toCompletable()).test(); |
| 418 | + io.reactivex.observers.TestObserver<Void> to = toV2Completable(ps.toCompletable()).test(); |
405 | 419 |
|
406 | 420 | assertTrue("1.x PublishSubject has no observers!", ps.hasObservers()); |
407 | 421 |
|
408 | | - ts.cancel(); |
| 422 | + to.dispose(); |
409 | 423 |
|
410 | 424 | assertFalse("1.x PublishSubject has observers!", ps.hasObservers()); |
411 | 425 | } |
412 | 426 |
|
413 | 427 | @Test |
414 | 428 | public void c1c2Error() { |
415 | | - toV2Completable(rx.Completable.error(new RuntimeException("Forced failure"))).test() |
416 | | - .assertFailureAndMessage(RuntimeException.class, "Forced failure"); |
| 429 | + assertFailureAndMessage(toV2Completable(rx.Completable.error(new RuntimeException("Forced failure"))).test() |
| 430 | + , RuntimeException.class, "Forced failure"); |
417 | 431 | } |
418 | 432 |
|
419 | 433 | @Test |
@@ -454,15 +468,15 @@ public void c1m2Cancel() { |
454 | 468 |
|
455 | 469 | assertTrue("1.x PublishSubject has no observers!", ps.hasObservers()); |
456 | 470 |
|
457 | | - ts.cancel(); |
| 471 | + ts.dispose(); |
458 | 472 |
|
459 | 473 | assertFalse("1.x PublishSubject has observers!", ps.hasObservers()); |
460 | 474 | } |
461 | 475 |
|
462 | 476 | @Test |
463 | 477 | public void c1m2Error() { |
464 | | - toV2Maybe(rx.Completable.error(new RuntimeException("Forced failure"))).test() |
465 | | - .assertFailureAndMessage(RuntimeException.class, "Forced failure"); |
| 478 | + assertFailureAndMessage(toV2Maybe(rx.Completable.error(new RuntimeException("Forced failure"))).test() |
| 479 | + , RuntimeException.class, "Forced failure"); |
466 | 480 | } |
467 | 481 |
|
468 | 482 |
|
|
0 commit comments