@Test(expected = NullPointerException.class) public void fromActionNull() { Completable.fromAction(null); }
@Test(expected = NullPointerException.class) public void fromActionNull() { Completable.fromAction(null); }
@Test(timeout = 5000) public void fromActionNormal() { final AtomicInteger calls = new AtomicInteger(); Completable c = Completable.fromAction(new Action() { @Override public void run() { calls.getAndIncrement(); } }); c.blockingAwait(); Assert.assertEquals(1, calls.get()); }
@Test(timeout = 5000, expected = TestException.class) public void fromActionThrows() { Completable c = Completable.fromAction(new Action() { @Override public void run() { throw new TestException(); } }); c.blockingAwait(); }
@Test(timeout = 5000) public void retryTimes5Normal() { final AtomicInteger calls = new AtomicInteger(5); Completable c = Completable.fromAction(new Action() { @Override public void run() { if (calls.decrementAndGet() != 0) { throw new TestException(); } } }).retry(5); c.blockingAwait(); }
@Test(timeout = 5000) public void retry5Times() { final AtomicInteger calls = new AtomicInteger(5); Completable c = Completable.fromAction(new Action() { @Override public void run() { if (calls.decrementAndGet() != 0) { throw new TestException(); } } }).retry(); c.blockingAwait(); }
@Test public void fromAction() { final AtomicInteger atomicInteger = new AtomicInteger(); Completable.fromAction(new Action() { @Override public void run() throws Exception { atomicInteger.incrementAndGet(); } }) .test() .assertResult(); assertEquals(1, atomicInteger.get()); }
@Test public void fromActionDisposed() { final AtomicInteger calls = new AtomicInteger(); Completable.fromAction(new Action() { @Override public void run() throws Exception { calls.incrementAndGet(); } }) .test(true) .assertEmpty(); assertEquals(1, calls.get()); }
@Test public void fromActionErrorsDisposed() { final AtomicInteger calls = new AtomicInteger(); Completable.fromAction(new Action() { @Override public void run() throws Exception { calls.incrementAndGet(); throw new TestException(); } }) .test(true) .assertEmpty(); assertEquals(1, calls.get()); } }
@Test public void fromActionThrows() { Completable.fromAction(new Action() { @Override public void run() throws Exception { throw new UnsupportedOperationException(); } }) .test() .assertFailure(UnsupportedOperationException.class); }
@Test public void normal() { final TestObserver<Integer> to = new TestObserver<Integer>(); Observable.range(1, 5) .concatWith(Completable.fromAction(new Action() { @Override public void run() throws Exception { to.onNext(100); } })) .subscribe(to); to.assertResult(1, 2, 3, 4, 5, 100); }
@Test public void normal() { final TestObserver<Integer> to = new TestObserver<Integer>(); Observable.range(1, 5).mergeWith( Completable.fromAction(new Action() { @Override public void run() throws Exception { to.onNext(100); } }) ) .subscribe(to); to.assertResult(1, 2, 3, 4, 5, 100); }
@Test public void simple2() { final AtomicInteger counter = new AtomicInteger(); Observable.range(1, 5) .concatMapCompletable(Functions.justFunction(Completable.fromAction(new Action() { @Override public void run() throws Exception { counter.incrementAndGet(); } }))) .test() .assertResult(); assertEquals(5, counter.get()); }
@Test public void simple2() { final AtomicInteger counter = new AtomicInteger(); Flowable.range(1, 5) .concatMapCompletable(Functions.justFunction(Completable.fromAction(new Action() { @Override public void run() throws Exception { counter.incrementAndGet(); } }))) .test() .assertResult(); assertEquals(5, counter.get()); }
@Test public void mainError() { final TestObserver<Integer> to = new TestObserver<Integer>(); Observable.<Integer>error(new TestException()) .concatWith(Completable.fromAction(new Action() { @Override public void run() throws Exception { to.onNext(100); } })) .subscribe(to); to.assertFailure(TestException.class); }
@Test public void takeMain() { final TestObserver<Integer> to = new TestObserver<Integer>(); Observable.range(1, 5) .concatWith(Completable.fromAction(new Action() { @Override public void run() throws Exception { to.onNext(100); } })) .take(3) .subscribe(to); to.assertResult(1, 2, 3); }
@Test public void normal() { final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Flowable.range(1, 5) .concatWith(Completable.fromAction(new Action() { @Override public void run() throws Exception { ts.onNext(100); } })) .subscribe(ts); ts.assertResult(1, 2, 3, 4, 5, 100); }
@Test public void normal() { final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Flowable.range(1, 5).mergeWith( Completable.fromAction(new Action() { @Override public void run() throws Exception { ts.onNext(100); } }) ) .subscribe(ts); ts.assertResult(1, 2, 3, 4, 5, 100); }
@Test public void mainError() { final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Flowable.<Integer>error(new TestException()) .concatWith(Completable.fromAction(new Action() { @Override public void run() throws Exception { ts.onNext(100); } })) .subscribe(ts); ts.assertFailure(TestException.class); }
@Test public void takeMain() { final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Flowable.range(1, 5) .concatWith(Completable.fromAction(new Action() { @Override public void run() throws Exception { ts.onNext(100); } })) .take(3) .subscribe(ts); ts.assertResult(1, 2, 3); }