@Test public void disposed() { TestHelper.checkDisposed(CompletableSubject.create().doOnComplete(Functions.EMPTY_ACTION)); } }
@Test public void cancelOnArrival() { CompletableSubject.create() .test(true) .assertEmpty(); }
@Test public void checkDisposed() { PublishSubject<Integer> ps = PublishSubject.create(); CompletableSubject cs = CompletableSubject.create(); TestHelper.checkDisposed(ps.switchMapCompletable(Functions.justFunction(cs))); }
@Test public void nullThrowable() { CompletableSubject cs = CompletableSubject.create(); try { cs.onError(null); fail("No NullPointerException thrown"); } catch (NullPointerException ex) { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } cs.test().assertEmpty().cancel();; }
@Test public void checkDisposed() { PublishProcessor<Integer> pp = PublishProcessor.create(); CompletableSubject cs = CompletableSubject.create(); TestHelper.checkDisposed(pp.switchMapCompletable(Functions.justFunction(cs))); }
@Test public void emptyScalarSource() { final CompletableSubject cs = CompletableSubject.create(); Observable.empty() .concatMapCompletable(Functions.justFunction(cs)) .test() .assertResult(); }
@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() { 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 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 scalarEmptySource() { CompletableSubject cs = CompletableSubject.create(); Observable.empty() .switchMapCompletable(Functions.justFunction(cs)) .test() .assertResult(); assertFalse(cs.hasObservers()); }
@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 onSubscribeDispose() { CompletableSubject cs = CompletableSubject.create(); Disposable d = Disposables.empty(); cs.onSubscribe(d); assertFalse(d.isDisposed()); cs.onComplete(); d = Disposables.empty(); cs.onSubscribe(d); assertTrue(d.isDisposed()); }
@Test public void mainCompletesinnerErrorDelayed() { final PublishProcessor<Integer> pp = PublishProcessor.create(); final CompletableSubject cs = CompletableSubject.create(); TestObserver<Void> to = pp.switchMapCompletableDelayError(Functions.justFunction(cs)).test(); pp.onNext(1); pp.onComplete(); to.assertEmpty(); cs.onError(new TestException()); to.assertFailure(TestException.class); }
@Test public void innerErrorDelayed() { final PublishSubject<Integer> ps = PublishSubject.create(); final CompletableSubject cs = CompletableSubject.create(); TestObserver<Void> to = ps.switchMapCompletableDelayError(Functions.justFunction(cs)).test(); ps.onNext(1); cs.onError(new TestException()); to.assertEmpty(); assertTrue(ps.hasObservers()); ps.onComplete(); to.assertFailure(TestException.class); }
@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 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 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); }