@Test public void bufferWithBOEmptyLastViaBoundary() { PublishSubject<Integer> source = PublishSubject.create(); PublishSubject<Integer> boundary = PublishSubject.create(); Observer<Object> o = TestHelper.mockObserver(); InOrder inOrder = Mockito.inOrder(o); source.buffer(boundary).subscribe(o); boundary.onComplete(); inOrder.verify(o, times(1)).onNext(Arrays.asList()); inOrder.verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); }
@Test public void disposed() { TestHelper.checkDisposed(PublishSubject.<Integer>create().flatMapMaybe(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.<Integer>empty(); } })); }
@Before public void setUp() { observer = TestHelper.mockObserver(); testScheduler = new TestScheduler(); subject = PublishSubject.create(); observable = subject.timeInterval(testScheduler); }
@Test public void methodTestNoCancel() { PublishSubject<Integer> ps = PublishSubject.create(); ps.test(false); assertTrue(ps.hasObservers()); }
@Test public void disposed() { TestHelper.checkDisposed(PublishSubject.create().singleElement().doFinally(this)); } }
@Test public void dispose() { TestHelper.checkDisposed(PublishSubject.<Integer>create().join(Observable.just(1), Functions.justFunction(Observable.never()), Functions.justFunction(Observable.never()), new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) throws Exception { return a + b; } })); }
@Test public void checkDisposed() { PublishSubject<Integer> ps = PublishSubject.create(); SingleSubject<Integer> ms = SingleSubject.create(); TestHelper.checkDisposed(ps.switchMapSingle(Functions.justFunction(ms))); }
@Test public void methodTestNoCancel() { PublishSubject<Integer> ps = PublishSubject.create(); ps.ignoreElements().test(false); assertTrue(ps.hasObservers()); } }
@Test public void disposeOnArrival2() { Observable<Integer> o = PublishSubject.<Integer>create().cache(); o.test(); o.test(true) .assertEmpty(); }
@Test public void innerSuccessCompletesAfterMain() { PublishSubject<Integer> ps = PublishSubject.create(); TestObserver<Integer> to = Observable.just(1).flatMapSingle(Functions.justFunction(ps.singleOrError())) .test(); ps.onNext(2); ps.onComplete(); to .assertResult(2); }
@Test public void untilPublisherDispose() { PublishSubject<Integer> main = PublishSubject.create(); PublishSubject<Integer> other = PublishSubject.create(); TestObserver<Integer> to = main.takeUntil(other).test(); assertTrue("Main no observers?", main.hasObservers()); assertTrue("Other no observers?", other.hasObservers()); to.dispose(); assertFalse("Main has observers?", main.hasObservers()); assertFalse("Other has observers?", other.hasObservers()); to.assertEmpty(); }
@Test public void untilPublisherOtherError() { PublishSubject<Integer> main = PublishSubject.create(); PublishSubject<Integer> other = PublishSubject.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 periodicWindowCompletionBounded() { TestScheduler scheduler = new TestScheduler(); Subject<Integer> ps = PublishSubject.<Integer>create(); TestObserver<Observable<Integer>> to = ps.window(5, TimeUnit.MILLISECONDS, scheduler, 5, false) .test(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); to.assertValueCount(21) .assertNoErrors() .assertNotComplete(); }
@SuppressWarnings("unchecked") @Test public void bufferTimedExactBoundedError() { TestScheduler scheduler = new TestScheduler(); PublishSubject<Integer> ps = PublishSubject.create(); TestObserver<List<Integer>> to = ps .buffer(1, TimeUnit.MILLISECONDS, scheduler, 1, Functions.<Integer>createArrayList(16), true) .test(); ps.onError(new TestException()); to .assertFailure(TestException.class); }
@Test public void delayed() { PublishSubject<Integer> ps = PublishSubject.create(); Single<Integer> cache = ps.single(-99).cache(); TestObserver<Integer> to1 = cache.test(); TestObserver<Integer> to2 = cache.test(); ps.onNext(1); ps.onComplete(); to1.assertResult(1); to2.assertResult(1); }
@Test public void selectorTake() { PublishSubject<Integer> ps = PublishSubject.create(); TestObserver<Integer> to = ps .timeout(Functions.justFunction(Observable.never())) .take(1) .test(); assertTrue(ps.hasObservers()); ps.onNext(1); assertFalse(ps.hasObservers()); to.assertResult(1); }
@Test public void cancel() { final PublishSubject<Integer> ps = PublishSubject.create(); final SingleSubject<Integer> cs = SingleSubject.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 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 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 cancelMain() { MaybeSubject<Integer> ms = MaybeSubject.create(); PublishSubject<Integer> ps = PublishSubject.create(); TestObserver<Integer> to = ms.flatMapObservable(Functions.justFunction(ps)) .test(); assertTrue(ms.hasObservers()); assertFalse(ps.hasObservers()); to.cancel(); assertFalse(ms.hasObservers()); assertFalse(ps.hasObservers()); }