Search in sources :

Example 21 with CountingRunnable

use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method disposedWorkerReturnsDisposedDisposables.

@Test
public void disposedWorkerReturnsDisposedDisposables() {
    Worker worker = scheduler.createWorker();
    worker.dispose();
    Disposable disposable = worker.schedule(new CountingRunnable());
    assertTrue(disposable.isDisposed());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Test(org.junit.Test)

Example 22 with CountingRunnable

use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerSchedulePeriodicallyThrowingDoesNotReschedule.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyThrowingDoesNotReschedule() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable() {

        @Override
        public void run() {
            super.run();
            if (get() == 2) {
                throw new RuntimeException("Broken!");
            }
        }
    };
    worker.schedulePeriodically(counter, 1, 1, MINUTES);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    // Exception will have happened here during the last run() execution.
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with CountingRunnable

use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directScheduleOncePostsImmediately.

@Test
public void directScheduleOncePostsImmediately() {
    CountingRunnable counter = new CountingRunnable();
    scheduler.scheduleDirect(counter);
    runUiThreadTasks();
    assertEquals(1, counter.get());
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Test(org.junit.Test)

Example 24 with CountingRunnable

use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directScheduleOnceInputValidation.

@Test
public void directScheduleOnceInputValidation() {
    try {
        scheduler.scheduleDirect(null);
        fail();
    } catch (NullPointerException e) {
        assertEquals("run == null", e.getMessage());
    }
    try {
        scheduler.scheduleDirect(null, 1, MINUTES);
        fail();
    } catch (NullPointerException e) {
        assertEquals("run == null", e.getMessage());
    }
    try {
        scheduler.scheduleDirect(new CountingRunnable(), 1, null);
        fail();
    } catch (NullPointerException e) {
        assertEquals("unit == null", e.getMessage());
    }
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Test(org.junit.Test)

Example 25 with CountingRunnable

use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directScheduleOnceWithDelayPostsWithDelay.

@Test
public void directScheduleOnceWithDelayPostsWithDelay() {
    CountingRunnable counter = new CountingRunnable();
    scheduler.scheduleDirect(counter, 1, MINUTES);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Test(org.junit.Test)

Aggregations

CountingRunnable (io.reactivex.android.testutil.CountingRunnable)33 Test (org.junit.Test)33 Worker (io.reactivex.Scheduler.Worker)19 Ignore (org.junit.Ignore)12 Disposable (io.reactivex.disposables.Disposable)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9