Search in sources :

Example 16 with CountingRunnable

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

the class HandlerSchedulerTest method workerScheduleOnceDisposedDoesNotRun.

@Test
public void workerScheduleOnceDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter);
    disposable.dispose();
    runUiThreadTasks();
    assertEquals(0, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Test(org.junit.Test)

Example 17 with CountingRunnable

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

the class HandlerSchedulerTest method directSchedulePeriodicallyDisposedDuringRunDoesNotReschedule.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyDisposedDuringRunDoesNotReschedule() {
    final AtomicReference<Disposable> disposableRef = new AtomicReference<>();
    CountingRunnable counter = new CountingRunnable() {

        @Override
        public void run() {
            super.run();
            if (get() == 2) {
                disposableRef.get().dispose();
            }
        }
    };
    Disposable disposable = scheduler.schedulePeriodicallyDirect(counter, 1, 1, MINUTES);
    disposableRef.set(disposable);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    // Dispose will have happened here during the last run() execution.
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with CountingRunnable

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

the class HandlerSchedulerTest method workerScheduleOnceInputValidation.

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

Example 19 with CountingRunnable

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

the class HandlerSchedulerTest method workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule() {
    Worker worker = scheduler.createWorker();
    final AtomicReference<Disposable> disposableRef = new AtomicReference<>();
    CountingRunnable counter = new CountingRunnable() {

        @Override
        public void run() {
            super.run();
            if (get() == 2) {
                disposableRef.get().dispose();
            }
        }
    };
    Disposable disposable = worker.schedulePeriodically(counter, 1, 1, MINUTES);
    disposableRef.set(disposable);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    // Dispose will have happened here during the last run() execution.
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) AtomicReference(java.util.concurrent.atomic.AtomicReference) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with CountingRunnable

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

the class HandlerSchedulerTest method directScheduleOnceDisposedDoesNotRun.

@Test
public void directScheduleOnceDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.scheduleDirect(counter);
    disposable.dispose();
    runUiThreadTasks();
    assertEquals(0, counter.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable) 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