@Test public void untilSingleMainSuccess() { SingleSubject<Integer> main = SingleSubject.create(); SingleSubject<Integer> other = SingleSubject.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 untilSingleOtherSuccess() { SingleSubject<Integer> main = SingleSubject.create(); SingleSubject<Integer> other = SingleSubject.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); other.onSuccess(1); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertFailure(CancellationException.class); }
@Test public void untilSingleOtherError() { SingleSubject<Integer> main = SingleSubject.create(); SingleSubject<Integer> other = SingleSubject.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 cancelOther() { SingleSubject<Object> other = SingleSubject.create(); TestObserver<Object> to = Observable.empty() .concatWith(other) .test(); assertTrue(other.hasObservers()); to.cancel(); assertFalse(other.hasObservers()); }
@Test public void cancelOther() { SingleSubject<Object> other = SingleSubject.create(); TestSubscriber<Object> ts = Flowable.empty() .concatWith(other) .test(); assertTrue(other.hasObservers()); ts.cancel(); assertFalse(other.hasObservers()); }
@Test public void cancel() { final PublishProcessor<Integer> pp = PublishProcessor.create(); final SingleSubject<Integer> cs = SingleSubject.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 scalarSource() { SingleSubject<Integer> ss = SingleSubject.create(); TestObserver<Integer> to = Observable.just(1) .switchMapSingle(Functions.justFunction(ss)) .test(); assertTrue(ss.hasObservers()); to.assertEmpty(); ss.onSuccess(2); to.assertResult(2); } }
@Test public void untilPublisherOtherOnNext() { SingleSubject<Integer> main = SingleSubject.create(); PublishProcessor<Integer> other = PublishProcessor.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasSubscribers()); other.onNext(1); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasSubscribers()); to.assertFailure(CancellationException.class); }
@Test public void untilPublisherDispose() { SingleSubject<Integer> main = SingleSubject.create(); PublishProcessor<Integer> other = PublishProcessor.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasSubscribers()); to.dispose(); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasSubscribers()); to.assertEmpty(); }
@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 untilPublisherMainSuccess() { SingleSubject<Integer> main = SingleSubject.create(); PublishProcessor<Integer> other = PublishProcessor.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasSubscribers()); main.onSuccess(1); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasSubscribers()); to.assertResult(1); }
@Test public void cancelMain() { SingleSubject<Integer> ss = SingleSubject.create(); PublishSubject<Integer> ps = PublishSubject.create(); TestObserver<Integer> to = ss.flatMapObservable(Functions.justFunction(ps)) .test(); assertTrue(ss.hasObservers()); assertFalse(ps.hasObservers()); to.cancel(); assertFalse(ss.hasObservers()); assertFalse(ps.hasObservers()); }
@Test public void untilPublisherOtherOnComplete() { SingleSubject<Integer> main = SingleSubject.create(); PublishProcessor<Integer> other = PublishProcessor.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasSubscribers()); other.onComplete(); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasSubscribers()); to.assertFailure(CancellationException.class); }
@Test public void untilPublisherMainError() { SingleSubject<Integer> main = SingleSubject.create(); PublishProcessor<Integer> other = PublishProcessor.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasSubscribers()); main.onError(new TestException()); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasSubscribers()); to.assertFailure(TestException.class); }
@Test public void untilPublisherOtherError() { SingleSubject<Integer> main = SingleSubject.create(); PublishProcessor<Integer> other = PublishProcessor.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasSubscribers()); other.onError(new TestException()); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasSubscribers()); 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 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 scalarEmptySource() { SingleSubject<Integer> ss = SingleSubject.create(); Observable.empty() .switchMapSingle(Functions.justFunction(ss)) .test() .assertResult(); assertFalse(ss.hasObservers()); }
@Test public void scalarEmptySource() { SingleSubject<Integer> ss = SingleSubject.create(); Observable.empty() .concatMapSingle(Functions.justFunction(ss)) .test() .assertResult(); assertFalse(ss.hasObservers()); }
@Test public void disposeWhenFallback() { TestScheduler sch = new TestScheduler(); SingleSubject<Integer> subj = SingleSubject.create(); subj.timeout(1, TimeUnit.SECONDS, sch, Single.just(1)) .test(true) .assertEmpty(); assertFalse(subj.hasObservers()); }