use of io.reactivex.functions.Action in project RxJava by ReactiveX.
the class CompletableTimerTest method timer.
@Test
public void timer() {
final TestScheduler testScheduler = new TestScheduler();
final AtomicLong atomicLong = new AtomicLong();
Completable.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Action() {
@Override
public void run() throws Exception {
atomicLong.incrementAndGet();
}
});
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(1, atomicLong.get());
}
use of io.reactivex.functions.Action in project RxJava by ReactiveX.
the class CompletableDisposeOnTest method error.
@Test
public void error() {
TestScheduler scheduler = new TestScheduler();
final int[] call = { 0 };
Completable.error(new TestException()).doOnDispose(new Action() {
@Override
public void run() throws Exception {
call[0]++;
}
}).unsubscribeOn(scheduler).test().assertFailure(TestException.class);
scheduler.triggerActions();
assertEquals(0, call[0]);
}
use of io.reactivex.functions.Action in project RxJava by ReactiveX.
the class CompletableDisposeOnTest method normal.
@Test
public void normal() {
TestScheduler scheduler = new TestScheduler();
final int[] call = { 0 };
Completable.complete().doOnDispose(new Action() {
@Override
public void run() throws Exception {
call[0]++;
}
}).unsubscribeOn(scheduler).test().assertResult();
scheduler.triggerActions();
assertEquals(0, call[0]);
}
use of io.reactivex.functions.Action in project RxJava by ReactiveX.
the class CompletableFromActionTest method fromActionTwice.
@Test
public void fromActionTwice() {
final AtomicInteger atomicInteger = new AtomicInteger();
Action run = new Action() {
@Override
public void run() throws Exception {
atomicInteger.incrementAndGet();
}
};
Completable.fromAction(run).test().assertResult();
assertEquals(1, atomicInteger.get());
Completable.fromAction(run).test().assertResult();
assertEquals(2, atomicInteger.get());
}
use of io.reactivex.functions.Action in project RxJava by ReactiveX.
the class FlowableDoAfterTerminateTest method ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce.
@Test
public void ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce() throws Exception {
Action finallyAction = Mockito.mock(Action.class);
doThrow(new IllegalStateException()).when(finallyAction).run();
TestSubscriber<String> testSubscriber = new TestSubscriber<String>();
Flowable.just("value").doAfterTerminate(finallyAction).subscribe(testSubscriber);
testSubscriber.assertValue("value");
verify(finallyAction).run();
// Actual result:
// Not only IllegalStateException was swallowed
// But finallyAction was called twice!
}
Aggregations