@Test public void untilCompletableOtherOnComplete() { CompletableSubject main = CompletableSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Void> to = main.ambWith(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); other.onComplete(); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertResult(); }
@Test public void untilCompletableMainComplete() { CompletableSubject main = CompletableSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Void> to = main.ambWith(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); main.onComplete(); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertResult(); }
@Test public void consumerDisposes() { CompletableSubject cs1 = CompletableSubject.create(); CompletableSubject cs2 = CompletableSubject.create(); TestObserver<Void> to = cs1.takeUntil(cs2).test(); to.assertEmpty(); assertTrue(cs1.hasObservers()); assertTrue(cs2.hasObservers()); to.dispose(); assertFalse(cs1.hasObservers()); assertFalse(cs2.hasObservers()); }
@Test public void untilCompletableOtherError() { CompletableSubject main = CompletableSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Void> to = main.ambWith(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); other.onError(new TestException()); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertFailure(TestException.class); }
@Test public void untilCompletableMainError() { CompletableSubject main = CompletableSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Void> to = main.ambWith(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); main.onError(new TestException()); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertFailure(TestException.class); }
@Test public void cancelOther() { CompletableSubject other = CompletableSubject.create(); TestObserver<Object> to = Observable.empty() .concatWith(other) .test(); assertTrue(other.hasObservers()); to.cancel(); assertFalse(other.hasObservers()); }
@Test public void cancelOther() { CompletableSubject other = CompletableSubject.create(); TestSubscriber<Object> ts = Flowable.empty() .concatWith(other) .test(); assertTrue(other.hasObservers()); ts.cancel(); assertFalse(other.hasObservers()); }
@Test public void cancelMain() { CompletableSubject cs = CompletableSubject.create(); PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = cs.andThen(pp) .test(); assertTrue(cs.hasObservers()); assertFalse(pp.hasSubscribers()); ts.cancel(); assertFalse(cs.hasObservers()); assertFalse(pp.hasSubscribers()); }
@Test public void cancel() { final PublishProcessor<Integer> pp = PublishProcessor.create(); final CompletableSubject cs = CompletableSubject.create(); TestSubscriber<Integer> ts = pp.mergeWith(cs).test(); assertTrue(pp.hasSubscribers()); assertTrue(cs.hasObservers()); ts.cancel(); assertFalse(pp.hasSubscribers()); assertFalse(cs.hasObservers()); }
@Test public void cancelMain() { CompletableSubject cs = CompletableSubject.create(); PublishSubject<Integer> ps = PublishSubject.create(); TestObserver<Integer> to = cs.andThen(ps) .test(); assertTrue(cs.hasObservers()); assertFalse(ps.hasObservers()); to.cancel(); assertFalse(cs.hasObservers()); assertFalse(ps.hasObservers()); }
@Test public void cancel() { final PublishSubject<Integer> ps = PublishSubject.create(); final CompletableSubject cs = CompletableSubject.create(); TestObserver<Integer> to = ps.mergeWith(cs).test(); assertTrue(ps.hasObservers()); assertTrue(cs.hasObservers()); to.cancel(); assertFalse(ps.hasObservers()); assertFalse(cs.hasObservers()); }
@Test public void scalarSource() { CompletableSubject cs = CompletableSubject.create(); TestObserver<Void> to = Observable.just(1) .switchMapCompletable(Functions.justFunction(cs)) .test(); assertTrue(cs.hasObservers()); to.assertEmpty(); cs.onComplete(); to.assertResult(); } }
@Test public void justScalarSource() { final CompletableSubject cs = CompletableSubject.create(); TestObserver<Void> to = Observable.just(1) .concatMapCompletable(Functions.justFunction(cs)) .test(); to.assertEmpty(); assertTrue(cs.hasObservers()); cs.onComplete(); to.assertResult(); } }
@Test public void untilCompletableOtherOnComplete() { SingleSubject<Integer> main = SingleSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); other.onComplete(); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertFailure(CancellationException.class); }
@Test public void untilCompletableMainSuccess() { SingleSubject<Integer> main = SingleSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); main.onSuccess(1); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertResult(1); }
@Test public void untilCompletableMainError() { SingleSubject<Integer> main = SingleSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); main.onError(new TestException()); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertFailure(TestException.class); }
@Test public void untilCompletableOtherError() { SingleSubject<Integer> main = SingleSubject.create(); CompletableSubject other = CompletableSubject.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); other.onError(new TestException()); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertFailure(TestException.class); }
@Test public void dispose() { PublishSubject<Integer> ps = PublishSubject.create(); CompletableSubject cs = CompletableSubject.create(); TestObserver<Void> to = ps.switchMapCompletable(Functions.justFunction(cs)) .test(); ps.onNext(1); assertTrue(ps.hasObservers()); assertTrue(cs.hasObservers()); to.dispose(); assertFalse(ps.hasObservers()); assertFalse(cs.hasObservers()); }
@Test public void scalarEmptySource() { CompletableSubject cs = CompletableSubject.create(); Observable.empty() .switchMapCompletable(Functions.justFunction(cs)) .test() .assertResult(); assertFalse(cs.hasObservers()); }
@Test public void mainErrorDelayed() { final PublishSubject<Integer> ps = PublishSubject.create(); final CompletableSubject cs = CompletableSubject.create(); TestObserver<Void> to = ps.switchMapCompletableDelayError(Functions.justFunction(cs)).test(); ps.onNext(1); ps.onError(new TestException()); to.assertEmpty(); assertTrue(cs.hasObservers()); cs.onComplete(); to.assertFailure(TestException.class); }