|
20 | 20 | import org.reactivestreams.*;
|
21 | 21 |
|
22 | 22 | import io.reactivex.*;
|
| 23 | +import io.reactivex.exceptions.TestException; |
23 | 24 | import io.reactivex.functions.Function;
|
24 | 25 | import io.reactivex.processors.PublishProcessor;
|
25 | 26 | import io.reactivex.subscribers.TestSubscriber;
|
@@ -293,4 +294,133 @@ public Flowable<Integer> apply(Flowable<Integer> c) throws Exception {
|
293 | 294 | }
|
294 | 295 | });
|
295 | 296 | }
|
| 297 | + |
| 298 | + @Test |
| 299 | + public void untilPublisherMainSuccess() { |
| 300 | + PublishProcessor<Integer> main = PublishProcessor.create(); |
| 301 | + PublishProcessor<Integer> other = PublishProcessor.create(); |
| 302 | + |
| 303 | + TestSubscriber<Integer> ts = main.takeUntil(other).test(); |
| 304 | + |
| 305 | + assertTrue("Main no subscribers?", main.hasSubscribers()); |
| 306 | + assertTrue("Other no subscribers?", other.hasSubscribers()); |
| 307 | + |
| 308 | + main.onNext(1); |
| 309 | + main.onNext(2); |
| 310 | + main.onComplete(); |
| 311 | + |
| 312 | + assertFalse("Main has subscribers?", main.hasSubscribers()); |
| 313 | + assertFalse("Other has subscribers?", other.hasSubscribers()); |
| 314 | + |
| 315 | + ts.assertResult(1, 2); |
| 316 | + } |
| 317 | + |
| 318 | + @Test |
| 319 | + public void untilPublisherMainComplete() { |
| 320 | + PublishProcessor<Integer> main = PublishProcessor.create(); |
| 321 | + PublishProcessor<Integer> other = PublishProcessor.create(); |
| 322 | + |
| 323 | + TestSubscriber<Integer> ts = main.takeUntil(other).test(); |
| 324 | + |
| 325 | + assertTrue("Main no subscribers?", main.hasSubscribers()); |
| 326 | + assertTrue("Other no subscribers?", other.hasSubscribers()); |
| 327 | + |
| 328 | + main.onComplete(); |
| 329 | + |
| 330 | + assertFalse("Main has subscribers?", main.hasSubscribers()); |
| 331 | + assertFalse("Other has subscribers?", other.hasSubscribers()); |
| 332 | + |
| 333 | + ts.assertResult(); |
| 334 | + } |
| 335 | + |
| 336 | + @Test |
| 337 | + public void untilPublisherMainError() { |
| 338 | + PublishProcessor<Integer> main = PublishProcessor.create(); |
| 339 | + PublishProcessor<Integer> other = PublishProcessor.create(); |
| 340 | + |
| 341 | + TestSubscriber<Integer> ts = main.takeUntil(other).test(); |
| 342 | + |
| 343 | + assertTrue("Main no subscribers?", main.hasSubscribers()); |
| 344 | + assertTrue("Other no subscribers?", other.hasSubscribers()); |
| 345 | + |
| 346 | + main.onError(new TestException()); |
| 347 | + |
| 348 | + assertFalse("Main has subscribers?", main.hasSubscribers()); |
| 349 | + assertFalse("Other has subscribers?", other.hasSubscribers()); |
| 350 | + |
| 351 | + ts.assertFailure(TestException.class); |
| 352 | + } |
| 353 | + |
| 354 | + @Test |
| 355 | + public void untilPublisherOtherOnNext() { |
| 356 | + PublishProcessor<Integer> main = PublishProcessor.create(); |
| 357 | + PublishProcessor<Integer> other = PublishProcessor.create(); |
| 358 | + |
| 359 | + TestSubscriber<Integer> ts = main.takeUntil(other).test(); |
| 360 | + |
| 361 | + assertTrue("Main no subscribers?", main.hasSubscribers()); |
| 362 | + assertTrue("Other no subscribers?", other.hasSubscribers()); |
| 363 | + |
| 364 | + other.onNext(1); |
| 365 | + |
| 366 | + assertFalse("Main has subscribers?", main.hasSubscribers()); |
| 367 | + assertFalse("Other has subscribers?", other.hasSubscribers()); |
| 368 | + |
| 369 | + ts.assertResult(); |
| 370 | + } |
| 371 | + |
| 372 | + @Test |
| 373 | + public void untilPublisherOtherOnComplete() { |
| 374 | + PublishProcessor<Integer> main = PublishProcessor.create(); |
| 375 | + PublishProcessor<Integer> other = PublishProcessor.create(); |
| 376 | + |
| 377 | + TestSubscriber<Integer> ts = main.takeUntil(other).test(); |
| 378 | + |
| 379 | + assertTrue("Main no subscribers?", main.hasSubscribers()); |
| 380 | + assertTrue("Other no subscribers?", other.hasSubscribers()); |
| 381 | + |
| 382 | + other.onComplete(); |
| 383 | + |
| 384 | + assertFalse("Main has subscribers?", main.hasSubscribers()); |
| 385 | + assertFalse("Other has subscribers?", other.hasSubscribers()); |
| 386 | + |
| 387 | + ts.assertResult(); |
| 388 | + } |
| 389 | + |
| 390 | + @Test |
| 391 | + public void untilPublisherOtherError() { |
| 392 | + PublishProcessor<Integer> main = PublishProcessor.create(); |
| 393 | + PublishProcessor<Integer> other = PublishProcessor.create(); |
| 394 | + |
| 395 | + TestSubscriber<Integer> ts = main.takeUntil(other).test(); |
| 396 | + |
| 397 | + assertTrue("Main no subscribers?", main.hasSubscribers()); |
| 398 | + assertTrue("Other no subscribers?", other.hasSubscribers()); |
| 399 | + |
| 400 | + other.onError(new TestException()); |
| 401 | + |
| 402 | + assertFalse("Main has subscribers?", main.hasSubscribers()); |
| 403 | + assertFalse("Other has subscribers?", other.hasSubscribers()); |
| 404 | + |
| 405 | + ts.assertFailure(TestException.class); |
| 406 | + } |
| 407 | + |
| 408 | + @Test |
| 409 | + public void untilPublisherDispose() { |
| 410 | + PublishProcessor<Integer> main = PublishProcessor.create(); |
| 411 | + PublishProcessor<Integer> other = PublishProcessor.create(); |
| 412 | + |
| 413 | + TestSubscriber<Integer> ts = main.takeUntil(other).test(); |
| 414 | + |
| 415 | + assertTrue("Main no subscribers?", main.hasSubscribers()); |
| 416 | + assertTrue("Other no subscribers?", other.hasSubscribers()); |
| 417 | + |
| 418 | + ts.dispose(); |
| 419 | + |
| 420 | + assertFalse("Main has subscribers?", main.hasSubscribers()); |
| 421 | + assertFalse("Other has subscribers?", other.hasSubscribers()); |
| 422 | + |
| 423 | + ts.assertEmpty(); |
| 424 | + } |
| 425 | + |
296 | 426 | }
|
0 commit comments