From 82339727bd30125562a0e6c633548e75f858c093 Mon Sep 17 00:00:00 2001 From: soshial Date: Fri, 12 Oct 2018 16:21:36 +0300 Subject: [PATCH] add tests to delayCompletable() --- .../completable/CompletableDelayTest.java | 91 ++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java index 174a520e0f..20ab49e0c7 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java @@ -14,17 +14,24 @@ package io.reactivex.internal.operators.completable; import static org.junit.Assert.assertNotEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; import org.junit.Test; -import io.reactivex.*; +import io.reactivex.CompletableSource; +import io.reactivex.Observer; +import io.reactivex.TestHelper; +import io.reactivex.Completable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.observers.TestObserver; -import io.reactivex.schedulers.*; +import io.reactivex.schedulers.Schedulers; +import io.reactivex.schedulers.TestScheduler; public class CompletableDelayTest { @@ -120,4 +127,84 @@ public void errorDelayed() { to.assertFailure(TestException.class); } + + @Test + public void errorDelayedSubscription() { + TestScheduler scheduler = new TestScheduler(); + + TestObserver to = Completable.error(new TestException()) + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler) + .test(); + + to.assertEmpty(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + + to.assertEmpty(); + + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + + to.assertFailure(TestException.class); + } + + @Test + public void errorDelayedSubscriptionDisposeBeforeTime() { + TestScheduler scheduler = new TestScheduler(); + + Completable result = Completable.complete() + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + Observer o = TestHelper.mockObserver(); + TestObserver to = new TestObserver(o); + + result.subscribe(to); + to.assertEmpty(); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + to.dispose(); + + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + + to.assertEmpty(); + verify(o, never()).onComplete(); + verify(o, never()).onError(any(Throwable.class)); + } + + @Test + public void testDelaySubscriptionDisposeBeforeTime() { + TestScheduler scheduler = new TestScheduler(); + Completable result = Completable.complete() + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + + Observer o = TestHelper.mockObserver(); + TestObserver to = new TestObserver(o); + + result.subscribe(to); + + to.assertEmpty(); + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + to.dispose(); + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + + verify(o, never()).onComplete(); + verify(o, never()).onError(any(Throwable.class)); + } + + @Test + public void testDelaySubscription() { + TestScheduler scheduler = new TestScheduler(); + Completable result = Completable.complete() + .delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + + Observer o = TestHelper.mockObserver(); + TestObserver to = new TestObserver(o); + + result.subscribe(to); + + scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS); + to.assertEmpty(); + scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); + to.assertComplete(); + + verify(o, never()).onError(any(Throwable.class)); + } }