diff --git a/language-adaptors/rxjava-groovy/src/main/java/rx/lang/groovy/GroovyCreateWrapper.java b/language-adaptors/rxjava-groovy/src/main/java/rx/lang/groovy/GroovyCreateWrapper.java index 07d3af44a2..c94b0aaf57 100644 --- a/language-adaptors/rxjava-groovy/src/main/java/rx/lang/groovy/GroovyCreateWrapper.java +++ b/language-adaptors/rxjava-groovy/src/main/java/rx/lang/groovy/GroovyCreateWrapper.java @@ -17,7 +17,7 @@ import groovy.lang.Closure; import rx.Observable.OnSubscribe; -import rx.Observer; +import rx.Subscriber; import rx.Subscription; public class GroovyCreateWrapper implements OnSubscribe { @@ -29,7 +29,7 @@ public GroovyCreateWrapper(Closure closure) { } @Override - public void call(Observer op) { + public void call(Subscriber op) { Object o = closure.call(op); /* * If the new signature is being used, we will get NULL back. diff --git a/language-adaptors/rxjava-groovy/src/test/groovy/rx/lang/groovy/ObservableTests.groovy b/language-adaptors/rxjava-groovy/src/test/groovy/rx/lang/groovy/ObservableTests.groovy index 34d90f160c..9a093e98cf 100644 --- a/language-adaptors/rxjava-groovy/src/test/groovy/rx/lang/groovy/ObservableTests.groovy +++ b/language-adaptors/rxjava-groovy/src/test/groovy/rx/lang/groovy/ObservableTests.groovy @@ -15,28 +15,21 @@ */ package rx.lang.groovy -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import rx.Notification; -import rx.Observable; -import rx.Observable.OnSubscribeFunc; -import rx.Observer; -import rx.Subscription; -import rx.observables.GroupedObservable; -import rx.subscriptions.Subscriptions; -import rx.util.functions.Func1; +import static org.junit.Assert.* +import static org.mockito.Matchers.* +import static org.mockito.Mockito.* + +import org.junit.Before +import org.junit.Test +import org.mockito.Mock +import org.mockito.MockitoAnnotations + +import rx.Notification +import rx.Observable +import rx.Observer +import rx.Subscription +import rx.Observable.OnSubscribeFunc +import rx.subscriptions.Subscriptions def class ObservableTests { diff --git a/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyActionWrapper.java b/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyActionWrapper.java index 6beb4f1d59..5916490070 100644 --- a/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyActionWrapper.java +++ b/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyActionWrapper.java @@ -15,11 +15,11 @@ */ package rx.lang.jruby; -import org.jruby.RubyProc; import org.jruby.Ruby; +import org.jruby.RubyProc; +import org.jruby.javasupport.JavaUtil; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.javasupport.JavaUtil; import rx.util.functions.Action; import rx.util.functions.Action0; diff --git a/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyFunctionWrapper.java b/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyFunctionWrapper.java index f049827d8e..38e6a193b1 100644 --- a/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyFunctionWrapper.java +++ b/language-adaptors/rxjava-jruby/src/main/java/rx/lang/jruby/JRubyFunctionWrapper.java @@ -15,11 +15,11 @@ */ package rx.lang.jruby; -import org.jruby.RubyProc; import org.jruby.Ruby; +import org.jruby.RubyProc; +import org.jruby.javasupport.JavaUtil; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.javasupport.JavaUtil; import rx.util.functions.Func0; import rx.util.functions.Func1; diff --git a/language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Subject.scala b/language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Subject.scala index 9469b74210..eb9efa02ac 100644 --- a/language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Subject.scala +++ b/language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Subject.scala @@ -21,7 +21,7 @@ package rx.lang.scala trait Subject[T] extends Observable[T] with Observer[T] { private [scala] val asJavaSubject: rx.subjects.Subject[_ >: T, _<: T] - val asJavaObservable: rx.Observable[_ <: T] = asJavaSubject.toObservable() + val asJavaObservable: rx.Observable[_ <: T] = asJavaSubject override val asJavaObserver: rx.Observer[_ >: T] = asJavaSubject override def onNext(value: T): Unit = { asJavaObserver.onNext(value)} diff --git a/rxjava-contrib/rxjava-android/src/main/java/rx/android/observables/AndroidObservable.java b/rxjava-contrib/rxjava-android/src/main/java/rx/android/observables/AndroidObservable.java index be471b6291..a6af28b555 100644 --- a/rxjava-contrib/rxjava-android/src/main/java/rx/android/observables/AndroidObservable.java +++ b/rxjava-contrib/rxjava-android/src/main/java/rx/android/observables/AndroidObservable.java @@ -16,13 +16,10 @@ package rx.android.observables; import rx.Observable; -import rx.Observer; import rx.operators.OperationObserveFromAndroidComponent; - import android.app.Activity; import android.app.Fragment; import android.os.Build; -import android.support.v4.app.FragmentActivity; public final class AndroidObservable { diff --git a/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/AndroidSchedulers.java b/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/AndroidSchedulers.java index 5120c8e848..d43f0d2db2 100644 --- a/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/AndroidSchedulers.java +++ b/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/AndroidSchedulers.java @@ -15,9 +15,9 @@ */ package rx.android.schedulers; +import rx.Scheduler; import android.os.Handler; import android.os.Looper; -import rx.Scheduler; /** * Schedulers that have Android specific functionality diff --git a/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/HandlerThreadScheduler.java b/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/HandlerThreadScheduler.java index 5ce5856d86..a1b6b39055 100644 --- a/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/HandlerThreadScheduler.java +++ b/rxjava-contrib/rxjava-android/src/main/java/rx/android/schedulers/HandlerThreadScheduler.java @@ -15,14 +15,13 @@ */ package rx.android.schedulers; -import android.os.Handler; +import java.util.concurrent.TimeUnit; import rx.Scheduler; import rx.Subscription; import rx.operators.SafeObservableSubscription; import rx.util.functions.Func2; - -import java.util.concurrent.TimeUnit; +import android.os.Handler; /** * Schedules actions to run on an Android Handler thread. diff --git a/rxjava-contrib/rxjava-android/src/main/java/rx/operators/OperationObserveFromAndroidComponent.java b/rxjava-contrib/rxjava-android/src/main/java/rx/operators/OperationObserveFromAndroidComponent.java index 4ebf6b117a..5fa5584927 100644 --- a/rxjava-contrib/rxjava-android/src/main/java/rx/operators/OperationObserveFromAndroidComponent.java +++ b/rxjava-contrib/rxjava-android/src/main/java/rx/operators/OperationObserveFromAndroidComponent.java @@ -19,17 +19,10 @@ import rx.Observer; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; -import rx.subjects.PublishSubject; import android.app.Activity; -import android.app.Fragment; import android.os.Looper; import android.util.Log; -import java.util.concurrent.Callable; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - public class OperationObserveFromAndroidComponent { public static Observable observeFromAndroidComponent(Observable source, android.app.Fragment fragment) { diff --git a/rxjava-contrib/rxjava-android/src/test/java/rx/android/observables/AndroidObservableTest.java b/rxjava-contrib/rxjava-android/src/test/java/rx/android/observables/AndroidObservableTest.java index c7e6ca5f26..a5006bdf91 100644 --- a/rxjava-contrib/rxjava-android/src/test/java/rx/android/observables/AndroidObservableTest.java +++ b/rxjava-contrib/rxjava-android/src/test/java/rx/android/observables/AndroidObservableTest.java @@ -15,7 +15,7 @@ */ package rx.android.observables; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; import org.junit.Before; import org.junit.Test; @@ -29,12 +29,9 @@ import rx.Observable; import rx.Observer; import rx.observers.TestObserver; -import rx.operators.OperationObserveFromAndroidComponent; import android.app.Activity; import android.app.Fragment; -import android.os.Build; import android.support.v4.app.FragmentActivity; -import rx.android.observables.AndroidObservable; @RunWith(RobolectricTestRunner.class) diff --git a/rxjava-contrib/rxjava-android/src/test/java/rx/android/operators/OperationObserveFromAndroidComponentTest.java b/rxjava-contrib/rxjava-android/src/test/java/rx/android/operators/OperationObserveFromAndroidComponentTest.java index 70ea56d424..0304ef3edd 100644 --- a/rxjava-contrib/rxjava-android/src/test/java/rx/android/operators/OperationObserveFromAndroidComponentTest.java +++ b/rxjava-contrib/rxjava-android/src/test/java/rx/android/operators/OperationObserveFromAndroidComponentTest.java @@ -43,6 +43,7 @@ import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.observers.TestObserver; +import rx.observers.TestSubscriber; import rx.operators.OperationObserveFromAndroidComponent; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; @@ -149,8 +150,8 @@ public void itForwardsOnErrorToTargetObserver() { public void itDropsOnNextOnCompletedSequenceIfTargetComponentIsGone() throws Throwable { PublishSubject source = PublishSubject.create(); - final Observable.OnSubscribeFunc operator = newOnSubscribeFragmentInstance(source.toObservable(), mockFragment); - operator.onSubscribe(mockObserver); + final Observable.OnSubscribeFunc operator = newOnSubscribeFragmentInstance(source, mockFragment); + operator.onSubscribe(new TestSubscriber(mockObserver)); source.onNext(1); releaseComponentRef(operator); @@ -167,8 +168,8 @@ public void itDropsOnNextOnCompletedSequenceIfTargetComponentIsGone() throws Thr public void itDropsOnErrorIfTargetComponentIsGone() throws Throwable { PublishSubject source = PublishSubject.create(); - final Observable.OnSubscribeFunc operator = newOnSubscribeFragmentInstance(source.toObservable(), mockFragment); - operator.onSubscribe(mockObserver); + final Observable.OnSubscribeFunc operator = newOnSubscribeFragmentInstance(source, mockFragment); + operator.onSubscribe(new TestSubscriber(mockObserver)); source.onNext(1); releaseComponentRef(operator); @@ -203,7 +204,7 @@ private void releaseComponentRef(Observable.OnSubscribeFunc operator) t @Test public void itDoesNotForwardOnNextOnCompletedSequenceIfFragmentIsDetached() { PublishSubject source = PublishSubject.create(); - OperationObserveFromAndroidComponent.observeFromAndroidComponent(source.toObservable(), mockFragment).subscribe(new TestObserver(mockObserver)); + OperationObserveFromAndroidComponent.observeFromAndroidComponent(source, mockFragment).subscribe(new TestObserver(mockObserver)); source.onNext(1); @@ -219,7 +220,7 @@ public void itDoesNotForwardOnNextOnCompletedSequenceIfFragmentIsDetached() { @Test public void itDoesNotForwardOnErrorIfFragmentIsDetached() { PublishSubject source = PublishSubject.create(); - OperationObserveFromAndroidComponent.observeFromAndroidComponent(source.toObservable(), mockFragment).subscribe(new TestObserver(mockObserver)); + OperationObserveFromAndroidComponent.observeFromAndroidComponent(source, mockFragment).subscribe(new TestObserver(mockObserver)); source.onNext(1); diff --git a/rxjava-contrib/rxjava-apache-http/src/main/java/rx/apache/http/consumers/ResponseConsumerEventStream.java b/rxjava-contrib/rxjava-apache-http/src/main/java/rx/apache/http/consumers/ResponseConsumerEventStream.java index 3b386dcbd6..be8407aecf 100644 --- a/rxjava-contrib/rxjava-apache-http/src/main/java/rx/apache/http/consumers/ResponseConsumerEventStream.java +++ b/rxjava-contrib/rxjava-apache-http/src/main/java/rx/apache/http/consumers/ResponseConsumerEventStream.java @@ -85,7 +85,7 @@ protected void onResponseReceived(HttpResponse response) throws HttpException, I @Override public Subscription onSubscribe(Observer observer) { - parentSubscription.add(contentSubject.toObservable().subscribe(observer)); + parentSubscription.add(contentSubject.subscribe(observer)); return parentSubscription; } }); diff --git a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java index b735de2263..4ac9874e96 100644 --- a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java +++ b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/Async.java @@ -18,6 +18,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; + import rx.Observable; import rx.Scheduler; import rx.schedulers.Schedulers; @@ -605,7 +606,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -662,7 +663,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -721,7 +722,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -782,7 +783,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -845,7 +846,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -910,7 +911,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -977,7 +978,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -1046,7 +1047,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -1117,7 +1118,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -1190,7 +1191,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } @@ -1243,7 +1244,7 @@ public void call() { subject.onCompleted(); } }); - return subject.toObservable(); + return subject; } }; } diff --git a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/LatchedObserver.java b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/LatchedObserver.java index 994c9bd692..e76a391d87 100644 --- a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/LatchedObserver.java +++ b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/LatchedObserver.java @@ -18,6 +18,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; + import rx.Observer; import rx.util.functions.Action0; import rx.util.functions.Action1; @@ -28,7 +29,7 @@ * a terminal state has been reached. * @param the observed value type */ -abstract class LatchedObserver extends Observer { +abstract class LatchedObserver implements Observer { /** The CountDownLatch to count-down on a terminal state. */ protected final CountDownLatch latch; /** Contains the error. */ diff --git a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationDeferFuture.java b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationDeferFuture.java index fab5f2766f..8c55816fd7 100644 --- a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationDeferFuture.java +++ b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationDeferFuture.java @@ -16,10 +16,10 @@ package rx.util.async.operators; import java.util.concurrent.Future; + import rx.Observable; import rx.Scheduler; import rx.util.functions.Func0; -import rx.util.functions.Func1; /** * Defer the execution of a factory method which produces an observable sequence. diff --git a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationForEachFuture.java b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationForEachFuture.java index 74a060b345..bd689e204e 100644 --- a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationForEachFuture.java +++ b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationForEachFuture.java @@ -17,6 +17,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; + import rx.Observable; import rx.Subscription; import rx.util.Exceptions; diff --git a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationFromFunctionals.java b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationFromFunctionals.java index 24af4e0939..dd74f89bfd 100644 --- a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationFromFunctionals.java +++ b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationFromFunctionals.java @@ -16,6 +16,7 @@ package rx.util.async.operators; import java.util.concurrent.Callable; + import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Subscription; diff --git a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationStartFuture.java b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationStartFuture.java index b84badd815..4f1c4005e7 100644 --- a/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationStartFuture.java +++ b/rxjava-contrib/rxjava-async-util/src/main/java/rx/util/async/operators/OperationStartFuture.java @@ -31,9 +31,8 @@ package rx.util.async.operators; import java.util.concurrent.Future; + import rx.Observable; -import rx.Observable.OnSubscribeFunc; -import rx.Observer; import rx.Scheduler; import rx.util.functions.Func0; diff --git a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationDeferFutureTest.java b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationDeferFutureTest.java index f07d9b5e04..298ffa7e02 100644 --- a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationDeferFutureTest.java +++ b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationDeferFutureTest.java @@ -15,20 +15,20 @@ */ package rx.util.async.operators; +import static org.junit.Assert.*; +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; + import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.fail; + import org.junit.Test; import org.mockito.InOrder; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; + import rx.Observable; import rx.Observer; import rx.schedulers.Schedulers; diff --git a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationForEachFutureTest.java b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationForEachFutureTest.java index e7784262c3..954380cd7e 100644 --- a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationForEachFutureTest.java +++ b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationForEachFutureTest.java @@ -30,6 +30,8 @@ */ package rx.util.async.operators; +import static org.junit.Assert.*; + import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -37,9 +39,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; + import org.junit.Test; + import rx.Observable; import rx.schedulers.Schedulers; import rx.util.async.Async; diff --git a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationFromFunctionalsTest.java b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationFromFunctionalsTest.java index 7b3b8d16eb..09c3b353d4 100644 --- a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationFromFunctionalsTest.java +++ b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationFromFunctionalsTest.java @@ -16,6 +16,9 @@ package rx.util.async.operators; +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; + import java.io.IOException; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -27,7 +30,6 @@ import org.junit.Test; import org.mockito.InOrder; -import static org.mockito.Mockito.*; import rx.Observable; import rx.Observer; import rx.observers.TestObserver; diff --git a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationStartFutureTest.java b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationStartFutureTest.java index 2d7886e980..7086f5002e 100644 --- a/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationStartFutureTest.java +++ b/rxjava-contrib/rxjava-async-util/src/test/java/rx/util/async/operators/OperationStartFutureTest.java @@ -15,16 +15,20 @@ */ package rx.util.async.operators; +import static org.junit.Assert.*; +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; + import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.fail; + import org.junit.Test; import org.mockito.InOrder; -import static org.mockito.Mockito.*; + import rx.Observable; import rx.Observer; import rx.schedulers.Schedulers; @@ -39,7 +43,7 @@ static class CustomException extends RuntimeException {} * on terminal conditions. * @param */ - static class MockHelper extends Observer { + static class MockHelper implements Observer { final Observer observer; final CountDownLatch latch; diff --git a/rxjava-contrib/rxjava-computation-expressions/src/main/java/rx/operators/OperationConditionals.java b/rxjava-contrib/rxjava-computation-expressions/src/main/java/rx/operators/OperationConditionals.java index 45f4b0423e..e7336b3ce5 100644 --- a/rxjava-contrib/rxjava-computation-expressions/src/main/java/rx/operators/OperationConditionals.java +++ b/rxjava-contrib/rxjava-computation-expressions/src/main/java/rx/operators/OperationConditionals.java @@ -22,7 +22,6 @@ import rx.Observer; import rx.Subscription; import rx.subscriptions.MultipleAssignmentSubscription; -import rx.subscriptions.SerialSubscription; import rx.subscriptions.Subscriptions; import rx.util.functions.Func0; @@ -244,7 +243,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observe the source. */ - final class SourceObserver extends Observer { + final class SourceObserver implements Observer { final MultipleAssignmentSubscription cancel; final Observer observer; diff --git a/rxjava-contrib/rxjava-computation-expressions/src/test/java/rx/operators/OperationConditionalsTest.java b/rxjava-contrib/rxjava-computation-expressions/src/test/java/rx/operators/OperationConditionalsTest.java index 9fe6a617d4..35d40e7999 100644 --- a/rxjava-contrib/rxjava-computation-expressions/src/test/java/rx/operators/OperationConditionalsTest.java +++ b/rxjava-contrib/rxjava-computation-expressions/src/test/java/rx/operators/OperationConditionalsTest.java @@ -15,7 +15,6 @@ */ package rx.operators; -import static org.junit.Assert.*; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -37,7 +36,6 @@ import rx.observers.TestObserver; import rx.schedulers.Schedulers; import rx.schedulers.TestScheduler; -import rx.util.functions.Action1; import rx.util.functions.Func0; public class OperationConditionalsTest { diff --git a/rxjava-contrib/rxjava-string/src/main/java/rx/observables/StringObservable.java b/rxjava-contrib/rxjava-string/src/main/java/rx/observables/StringObservable.java index 8a22ef8cb7..1c7e1e2b1a 100644 --- a/rxjava-contrib/rxjava-string/src/main/java/rx/observables/StringObservable.java +++ b/rxjava-contrib/rxjava-string/src/main/java/rx/observables/StringObservable.java @@ -27,9 +27,9 @@ import java.util.regex.Pattern; import rx.Observable; +import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Subscription; -import rx.Observable.OnSubscribeFunc; import rx.util.functions.Func1; import rx.util.functions.Func2; diff --git a/rxjava-contrib/rxjava-string/src/test/java/rx/observables/StringObservableTest.java b/rxjava-contrib/rxjava-string/src/test/java/rx/observables/StringObservableTest.java index dde9b12a88..8b45a44f9e 100644 --- a/rxjava-contrib/rxjava-string/src/test/java/rx/observables/StringObservableTest.java +++ b/rxjava-contrib/rxjava-string/src/test/java/rx/observables/StringObservableTest.java @@ -16,6 +16,8 @@ package rx.observables; import static org.junit.Assert.*; +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; import java.io.IOException; import java.nio.charset.Charset; @@ -24,7 +26,6 @@ import org.junit.Test; -import static org.mockito.Mockito.*; import rx.Observable; import rx.Observer; import rx.observers.TestObserver; diff --git a/rxjava-core/src/main/java/rx/Observable.java b/rxjava-core/src/main/java/rx/Observable.java index 642a783d88..03bf817fc2 100644 --- a/rxjava-core/src/main/java/rx/Observable.java +++ b/rxjava-core/src/main/java/rx/Observable.java @@ -32,7 +32,7 @@ import rx.observables.BlockingObservable; import rx.observables.ConnectableObservable; import rx.observables.GroupedObservable; -import rx.observers.SafeObserver; +import rx.observers.SafeSubscriber; import rx.operators.OperationAll; import rx.operators.OperationAmb; import rx.operators.OperationAny; @@ -49,7 +49,7 @@ import rx.operators.OperationDematerialize; import rx.operators.OperationDistinct; import rx.operators.OperationDistinctUntilChanged; -import rx.operators.OperationDoOnEach; +import rx.operators.OperatorDoOnEach; import rx.operators.OperationElementAt; import rx.operators.OperationFilter; import rx.operators.OperationFinally; @@ -85,6 +85,7 @@ import rx.operators.OperationSwitch; import rx.operators.OperationSynchronize; import rx.operators.OperationTakeLast; +import rx.operators.OperationTakeTimed; import rx.operators.OperationTakeUntil; import rx.operators.OperationTakeWhile; import rx.operators.OperationThrottleFirst; @@ -104,11 +105,9 @@ import rx.operators.OperatorMerge; import rx.operators.OperatorParallel; import rx.operators.OperatorTake; -import rx.operators.OperationTakeTimed; import rx.operators.OperatorTimestamp; import rx.operators.OperatorToObservableList; import rx.operators.OperatorToObservableSortedList; -import rx.operators.SafeObservableSubscription; import rx.plugins.RxJavaObservableExecutionHook; import rx.plugins.RxJavaPlugins; import rx.schedulers.Schedulers; @@ -167,7 +166,7 @@ public class Observable { * constructor, unless you specifically have a need for inheritance. * * @param onSubscribe - * {@link OnSubscribeFunc} to be executed when {@link #subscribe(Observer)} is called + * {@link OnSubscribeFunc} to be executed when {@link #subscribe(Subscriber)} is called */ protected Observable(OnSubscribe f) { this.f = f; @@ -176,12 +175,12 @@ protected Observable(OnSubscribe f) { private final static RxJavaObservableExecutionHook hook = RxJavaPlugins.getInstance().getObservableExecutionHook(); /** - * Returns an Observable that will execute the specified function when an {@link Observer} subscribes to it. + * Returns an Observable that will execute the specified function when an {@link Subscriber} subscribes to it. *

* *

* Write the function you pass to {@code create} so that it behaves as an Observable: It should - * invoke the Observer's {@link Observer#onNext onNext}, {@link Observer#onError onError}, and {@link Observer#onCompleted onCompleted} methods appropriately. + * invoke the Observer's {@link Subscriber#onNext onNext}, {@link Subscriber#onError onError}, and {@link Subscriber#onCompleted onCompleted} methods appropriately. *

* A well-formed Observable must invoke either the Observer's {@code onCompleted} method * exactly once or its {@code onError} method exactly once. @@ -194,7 +193,7 @@ protected Observable(OnSubscribe f) { * @param func * a function that accepts an {@code Observer}, invokes its {@code onNext}, {@code onError}, and {@code onCompleted} methods as appropriate, and returns a {@link Subscription} that * allows the Observer to cancel the subscription - * @return an Observable that, when an {@link Observer} subscribes to it, will execute the + * @return an Observable that, when an {@link Subscriber} subscribes to it, will execute the * specified function * @see RxJava Wiki: create() * @see MSDN: Observable.Create @@ -203,7 +202,7 @@ public final static Observable create(OnSubscribe f) { return new Observable(f); } - public static interface OnSubscribe extends Action1> { + public static interface OnSubscribe extends Action1> { } @@ -211,7 +210,7 @@ public final static Observable create(final OnSubscribeFunc f) { return new Observable(new OnSubscribe() { @Override - public void call(Observer observer) { + public void call(Subscriber observer) { Subscription s = f.onSubscribe(observer); if (s != null && s != observer) { observer.add(s); @@ -238,11 +237,11 @@ public static interface OnSubscribeFunc extends Function { * @param bind * @return an Observable that emits values that are the result of applying the bind function to the values of the current Observable */ - public Observable lift(final Func1, Observer> bind) { + public Observable lift(final Func1, Subscriber> bind) { return new Observable(new OnSubscribe() { @Override - public void call(Observer o) { + public void call(Subscriber o) { subscribe(bind.call(o)); } }); @@ -4246,7 +4245,7 @@ public final void onNext(T args) { }; - return create(OperationDoOnEach.doOnEach(this, observer)); + return lift(new OperatorDoOnEach(observer)); } /** @@ -4279,7 +4278,7 @@ public final void onNext(T v) { }; - return create(OperationDoOnEach.doOnEach(this, observer)); + return lift(new OperatorDoOnEach(observer)); } /** @@ -4294,7 +4293,7 @@ public final void onNext(T v) { * @see MSDN: Observable.Do */ public final Observable doOnEach(Observer observer) { - return create(OperationDoOnEach.doOnEach(this, observer)); + return lift(new OperatorDoOnEach(observer)); } /** @@ -4325,7 +4324,7 @@ public final void onNext(T args) { }; - return create(OperationDoOnEach.doOnEach(this, observer)); + return lift(new OperatorDoOnEach(observer)); } /** @@ -4356,7 +4355,7 @@ public final void onNext(T args) { }; - return create(OperationDoOnEach.doOnEach(this, observer)); + return lift(new OperatorDoOnEach(observer)); } /** @@ -5323,8 +5322,8 @@ public final Observable parallel(final Func1, Observable * See https://github.com/Netflix/RxJava/issues/216 for a discussion on "Guideline 6.4: Protect * calls to user code from within an Observer" */ - private Subscription protectivelyWrapAndSubscribe(Observer o) { - return subscribe(new SafeObserver(o)); + private Subscription protectivelyWrapAndSubscribe(Subscriber o) { + return subscribe(new SafeSubscriber(o)); } /** @@ -6631,7 +6630,7 @@ public final Observable startWith(T[] values, Scheduler scheduler) { * items before the Observable has finished sending them */ public final Subscription subscribe() { - return protectivelyWrapAndSubscribe(new Observer() { + return protectivelyWrapAndSubscribe(new Subscriber() { @Override public final void onCompleted() { @@ -6671,7 +6670,7 @@ public final Subscription subscribe(final Action1 onNext) { * * See https://github.com/Netflix/RxJava/issues/216 for discussion on "Guideline 6.4: Protect calls to user code from within an Observer" */ - return protectivelyWrapAndSubscribe(new Observer() { + return protectivelyWrapAndSubscribe(new Subscriber() { @Override public final void onCompleted() { @@ -6717,7 +6716,7 @@ public final Subscription subscribe(final Action1 onNext, final Actio * See https://github.com/Netflix/RxJava/issues/216 for discussion on * "Guideline 6.4: Protect calls to user code from within an Observer" */ - return protectivelyWrapAndSubscribe(new Observer() { + return protectivelyWrapAndSubscribe(new Subscriber() { @Override public final void onCompleted() { @@ -6767,7 +6766,7 @@ public final Subscription subscribe(final Action1 onNext, final Actio * * See https://github.com/Netflix/RxJava/issues/216 for discussion on "Guideline 6.4: Protect calls to user code from within an Observer" */ - return protectivelyWrapAndSubscribe(new Observer() { + return protectivelyWrapAndSubscribe(new Subscriber() { @Override public final void onCompleted() { @@ -6841,6 +6840,31 @@ public final Subscription subscribe(final Action1 onNext, Scheduler s return subscribeOn(scheduler).subscribe(onNext); } + public final Subscription subscribe(final Observer observer, Scheduler scheduler) { + return subscribeOn(scheduler).subscribe(observer); + } + + public final Subscription subscribe(final Observer observer) { + return subscribe(new Subscriber() { + + @Override + public void onCompleted() { + observer.onCompleted(); + } + + @Override + public void onError(Throwable e) { + observer.onError(e); + } + + @Override + public void onNext(T t) { + observer.onNext(t); + } + + }); + } + /** * An {@link Observer} must call an Observable's {@code subscribe} method in order to receive * items and notifications from the Observable. @@ -6866,7 +6890,7 @@ public final Subscription subscribe(final Action1 onNext, Scheduler s * @throws IllegalArgumentException * if the {@link Observer} provided as the argument to {@code subscribe()} is {@code null} */ - public final Subscription subscribe(Observer observer) { + public final Subscription subscribe(Subscriber observer) { // allow the hook to intercept and/or decorate OnSubscribe onSubscribeFunction = hook.onSubscribeStart(this, f); // validate and proceed @@ -6884,7 +6908,7 @@ public final Subscription subscribe(Observer observer) { if (isInternalImplementation(observer)) { onSubscribeFunction.call(observer); } else { - onSubscribeFunction.call(new SafeObserver(observer)); + onSubscribeFunction.call(new SafeSubscriber(observer)); } return hook.onSubscribeReturn(this, observer); } catch (OnErrorNotImplementedException e) { @@ -6935,7 +6959,7 @@ public final Subscription subscribe(Observer observer) { * @throws IllegalArgumentException * if an argument to {@code subscribe()} is {@code null} */ - public final Subscription subscribe(Observer observer, Scheduler scheduler) { + public final Subscription subscribe(Subscriber observer, Scheduler scheduler) { return subscribeOn(scheduler).subscribe(observer); } @@ -8398,7 +8422,7 @@ public NeverObservable() { super(new OnSubscribe() { @Override - public void call(Observer observer) { + public void call(Subscriber observer) { // do nothing } @@ -8425,7 +8449,7 @@ public ThrowObservable(final Throwable exception) { * @return a reference to the subscription */ @Override - public void call(Observer observer) { + public void call(Subscriber observer) { observer.onError(exception); } @@ -8454,7 +8478,7 @@ private boolean isInternalImplementation(Object o) { return true; } // prevent double-wrapping (yeah it happens) - if (o instanceof SafeObserver) { + if (o instanceof SafeSubscriber) { return true; } diff --git a/rxjava-core/src/main/java/rx/Observer.java b/rxjava-core/src/main/java/rx/Observer.java index 580bb62c94..a2de94be24 100644 --- a/rxjava-core/src/main/java/rx/Observer.java +++ b/rxjava-core/src/main/java/rx/Observer.java @@ -15,37 +15,18 @@ */ package rx; -import rx.subscriptions.CompositeSubscription; - /** * Provides a mechanism for receiving push-based notifications. *

- * After an Observer calls an {@link Observable}'s Observable.subscribe method, the {@link Observable} calls the - * Observer's onNext method to provide notifications. A well-behaved {@link Observable} will call an Observer's + * After an Observer calls an {@link Observable}'s Observable.subscribe method, the {@link Observable} calls the + * Observer's onNext method to provide notifications. A well-behaved {@link Observable} will call an Observer's * onCompleted closure exactly once or the Observer's onError closure exactly once. *

* For more information see the RxJava Wiki * * @param */ -public abstract class Observer implements Subscription { - - private final CompositeSubscription cs; - - protected Observer(CompositeSubscription cs) { - if (cs == null) { - throw new IllegalArgumentException("The CompositeSubscription can not be null"); - } - this.cs = cs; - } - - protected Observer() { - this(new CompositeSubscription()); - } - - protected Observer(Observer op) { - this(op.cs); - } +public interface Observer { /** * Notifies the Observer that the {@link Observable} has finished sending push-based notifications. @@ -74,19 +55,4 @@ protected Observer(Observer op) { */ public abstract void onNext(T t); - /** - * Used to register an unsubscribe callback. - */ - public final void add(Subscription s) { - cs.add(s); - } - - @Override - public final void unsubscribe() { - cs.unsubscribe(); - } - - public final boolean isUnsubscribed() { - return cs.isUnsubscribed(); - } } diff --git a/rxjava-core/src/main/java/rx/Subscriber.java b/rxjava-core/src/main/java/rx/Subscriber.java new file mode 100644 index 0000000000..cfce1c60c5 --- /dev/null +++ b/rxjava-core/src/main/java/rx/Subscriber.java @@ -0,0 +1,86 @@ +/** + * Copyright 2014 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rx; + +import rx.subscriptions.CompositeSubscription; + +/** + * Provides a mechanism for receiving push-based notifications. + *

+ * After an Observer calls an {@link Observable}'s Observable.subscribe method, the {@link Observable} calls the + * Observer's onNext method to provide notifications. A well-behaved {@link Observable} will call an Observer's + * onCompleted closure exactly once or the Observer's onError closure exactly once. + *

+ * For more information see the RxJava Wiki + * + * @param + */ +public abstract class Subscriber implements Observer, Subscription { + + private final CompositeSubscription cs; + + protected Subscriber(CompositeSubscription cs) { + if (cs == null) { + throw new IllegalArgumentException("The CompositeSubscription can not be null"); + } + this.cs = cs; + } + + protected Subscriber() { + this(new CompositeSubscription()); + } + + protected Subscriber(Subscriber op) { + this(op.cs); + } + + public static Subscriber from(final Observer o) { + return new Subscriber() { + + @Override + public void onCompleted() { + o.onCompleted(); + } + + @Override + public void onError(Throwable e) { + o.onError(e); + } + + @Override + public void onNext(T t) { + o.onNext(t); + } + + }; + } + + /** + * Used to register an unsubscribe callback. + */ + public final void add(Subscription s) { + cs.add(s); + } + + @Override + public final void unsubscribe() { + cs.unsubscribe(); + } + + public final boolean isUnsubscribed() { + return cs.isUnsubscribed(); + } +} diff --git a/rxjava-core/src/main/java/rx/Subscription.java b/rxjava-core/src/main/java/rx/Subscription.java index 0248fd603f..690e5b93c3 100644 --- a/rxjava-core/src/main/java/rx/Subscription.java +++ b/rxjava-core/src/main/java/rx/Subscription.java @@ -18,7 +18,7 @@ import rx.subscriptions.Subscriptions; /** - * Subscription returns from {@link Observable#subscribe(Observer)} to allow unsubscribing. + * Subscription returns from {@link Observable#subscribe(Subscriber)} to allow unsubscribing. *

* See utilities in {@link Subscriptions} and implementations in the {@code rx.subscriptions} package. *

@@ -27,9 +27,9 @@ public interface Subscription { /** - * Stop receiving notifications on the {@link Observer} that was registered when this Subscription was received. + * Stop receiving notifications on the {@link Subscriber} that was registered when this Subscription was received. *

- * This allows unregistering an {@link Observer} before it has finished receiving all events (ie. before onCompleted is called). + * This allows unregistering an {@link Subscriber} before it has finished receiving all events (ie. before onCompleted is called). */ public void unsubscribe(); diff --git a/rxjava-core/src/main/java/rx/joins/JoinObserver1.java b/rxjava-core/src/main/java/rx/joins/JoinObserver1.java index 2aa7193c8c..9c3e1de1b8 100644 --- a/rxjava-core/src/main/java/rx/joins/JoinObserver1.java +++ b/rxjava-core/src/main/java/rx/joins/JoinObserver1.java @@ -23,29 +23,29 @@ import rx.Notification; import rx.Observable; -import rx.Observer; -import rx.observers.SafeObserver; +import rx.Subscriber; +import rx.observers.SafeSubscriber; import rx.operators.SafeObservableSubscription; import rx.util.functions.Action1; /** * Default implementation of a join observer. */ -public final class JoinObserver1 extends Observer> implements JoinObserver { +public final class JoinObserver1 extends Subscriber> implements JoinObserver { private Object gate; private final Observable source; private final Action1 onError; private final List activePlans; private final Queue> queue; private final AtomicBoolean subscribed = new AtomicBoolean(false); - private final SafeObserver> safeObserver; + private final SafeSubscriber> safeObserver; public JoinObserver1(Observable source, Action1 onError) { this.source = source; this.onError = onError; queue = new LinkedList>(); activePlans = new ArrayList(); - safeObserver = new SafeObserver>(new InnerObserver()); + safeObserver = new SafeSubscriber>(new InnerObserver()); // add this subscription so it gets unsubscribed when the parent does add(safeObserver); } @@ -97,7 +97,7 @@ void removeActivePlan(ActivePlan0 activePlan) { } - private final class InnerObserver extends Observer> { + private final class InnerObserver extends Subscriber> { @Override public void onNext(Notification args) { diff --git a/rxjava-core/src/main/java/rx/observables/BlockingObservable.java b/rxjava-core/src/main/java/rx/observables/BlockingObservable.java index 25e20de0d5..ccd4be7b71 100644 --- a/rxjava-core/src/main/java/rx/observables/BlockingObservable.java +++ b/rxjava-core/src/main/java/rx/observables/BlockingObservable.java @@ -21,9 +21,9 @@ import java.util.concurrent.atomic.AtomicReference; import rx.Observable; -import rx.Observer; +import rx.Subscriber; import rx.Subscription; -import rx.observers.SafeObserver; +import rx.observers.SafeSubscriber; import rx.operators.OperationLatest; import rx.operators.OperationMostRecent; import rx.operators.OperationNext; @@ -66,14 +66,14 @@ public static BlockingObservable from(final Observable o) { } /** - * Used for protecting against errors being thrown from {@link Observer} implementations and ensuring onNext/onError/onCompleted contract + * Used for protecting against errors being thrown from {@link Subscriber} implementations and ensuring onNext/onError/onCompleted contract * compliance. *

* See https://github.com/Netflix/RxJava/issues/216 for discussion on * "Guideline 6.4: Protect calls to user code from within an operator" */ - private Subscription protectivelyWrapAndSubscribe(Observer observer) { - return o.subscribe(new SafeObserver(observer)); + private Subscription protectivelyWrapAndSubscribe(Subscriber observer) { + return o.subscribe(new SafeSubscriber(observer)); } /** @@ -82,8 +82,8 @@ private Subscription protectivelyWrapAndSubscribe(Observer observer) *

* NOTE: This will block even if the Observable is asynchronous. *

- * This is similar to {@link Observable#subscribe(Observer)}, but it blocks. - * Because it blocks it does not need the {@link Observer#onCompleted()} or {@link Observer#onError(Throwable)} methods. + * This is similar to {@link Observable#subscribe(Subscriber)}, but it blocks. + * Because it blocks it does not need the {@link Subscriber#onCompleted()} or {@link Subscriber#onError(Throwable)} methods. *

* * @@ -103,7 +103,7 @@ public void forEach(final Action1 onNext) { * See https://github.com/Netflix/RxJava/issues/216 for discussion on * "Guideline 6.4: Protect calls to user code from within an operator" */ - protectivelyWrapAndSubscribe(new Observer() { + protectivelyWrapAndSubscribe(new Subscriber() { @Override public void onCompleted() { latch.countDown(); diff --git a/rxjava-core/src/main/java/rx/observables/ConnectableObservable.java b/rxjava-core/src/main/java/rx/observables/ConnectableObservable.java index d224873b16..b71ad4d81e 100644 --- a/rxjava-core/src/main/java/rx/observables/ConnectableObservable.java +++ b/rxjava-core/src/main/java/rx/observables/ConnectableObservable.java @@ -16,14 +16,14 @@ package rx.observables; import rx.Observable; -import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.operators.OperationRefCount; /** * A ConnectableObservable resembles an ordinary {@link Observable}, except that it does not begin * emitting items when it is subscribed to, but only when its {@link #connect} method is called. In - * this way you can wait for all intended {@link Observer}s to {@link Observable#subscribe} to the + * this way you can wait for all intended {@link Subscriber}s to {@link Observable#subscribe} to the * Observable before the Observable begins emitting items. *

* @@ -43,7 +43,7 @@ protected ConnectableObservable(OnSubscribe onSubscribe) { /** * Call a ConnectableObservable's connect() method to instruct it to begin emitting the - * items from its underlying {@link Observable} to its {@link Observer}s. + * items from its underlying {@link Observable} to its {@link Subscriber}s. */ public abstract Subscription connect(); diff --git a/rxjava-core/src/main/java/rx/observers/EmptyObserver.java b/rxjava-core/src/main/java/rx/observers/EmptyObserver.java index 1e0a5834ac..99ba2f5d04 100644 --- a/rxjava-core/src/main/java/rx/observers/EmptyObserver.java +++ b/rxjava-core/src/main/java/rx/observers/EmptyObserver.java @@ -2,10 +2,11 @@ import rx.Observer; + /** * Observer that does nothing... including swallowing errors. */ -public class EmptyObserver extends Observer { +public class EmptyObserver implements Observer { @Override public void onCompleted() { diff --git a/rxjava-core/src/main/java/rx/observers/SafeSubscriber.java b/rxjava-core/src/main/java/rx/observers/SafeSubscriber.java new file mode 100644 index 0000000000..a7ce075ef5 --- /dev/null +++ b/rxjava-core/src/main/java/rx/observers/SafeSubscriber.java @@ -0,0 +1,160 @@ +/** + * Copyright 2014 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rx.observers; + +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicBoolean; + +import rx.Subscriber; +import rx.Subscription; +import rx.operators.SafeObservableSubscription; +import rx.plugins.RxJavaPlugins; +import rx.subscriptions.Subscriptions; +import rx.util.CompositeException; +import rx.util.OnErrorNotImplementedException; + +/** + * Wrapper around Observer to ensure compliance with Rx contract. + *

+ * The following is taken from the Rx Design Guidelines document: http://go.microsoft.com/fwlink/?LinkID=205219 + *

+ * Messages sent to instances of the IObserver interface follow the following grammar:
+ * 
+ * OnNext* (OnCompleted | OnError)?
+ * 
+ * This grammar allows observable sequences to send any amount (0 or more) of OnNext messages to the subscribed
+ * observer instance, optionally followed by a single success (OnCompleted) or failure (OnError) message.
+ * 
+ * The single message indicating that an observable sequence has finished ensures that consumers of the observable
+ * sequence can deterministically establish that it is safe to perform cleanup operations.
+ * 
+ * A single failure further ensures that abort semantics can be maintained for operators that work on
+ * multiple observable sequences (see paragraph 6.6).
+ * 
+ * + *

+ * This wrapper will do the following: + *

    + *
  • Allow only single execution of either onError or onCompleted.
  • + *
  • Once an onComplete or onError are performed, no further calls can be executed
  • + *
  • If unsubscribe is called, this means we call completed() and don't allow any further onNext calls.
  • + *
  • When onError or onComplete occur it will unsubscribe from the Observable (if executing asynchronously).
  • + *
+ *

+ * It will not synchronize onNext execution. Use the {@link SynchronizedObserver} to do that. + * + * @param + */ +public class SafeSubscriber extends Subscriber { + + private final Subscriber actual; + private final AtomicBoolean isFinished = new AtomicBoolean(false); + + public SafeSubscriber(Subscriber actual) { + super(actual); + this.actual = actual; + } + + @Override + public void onCompleted() { + if (isFinished.compareAndSet(false, true)) { + try { + actual.onCompleted(); + } catch (Throwable e) { + // handle errors if the onCompleted implementation fails, not just if the Observable fails + _onError(e); + } finally { + // auto-unsubscribe + unsubscribe(); + } + } + } + + @Override + public void onError(Throwable e) { + if (isFinished.compareAndSet(false, true)) { + _onError(e); + } + } + + @Override + public void onNext(T args) { + try { + if (!isFinished.get()) { + actual.onNext(args); + } + } catch (Throwable e) { + // handle errors if the onNext implementation fails, not just if the Observable fails + onError(e); + } + } + + /* + * The logic for `onError` without the `isFinished` check so it can be called from within `onCompleted`. + * + * See https://github.com/Netflix/RxJava/issues/630 for the report of this bug. + */ + protected void _onError(Throwable e) { + try { + RxJavaPlugins.getInstance().getErrorHandler().handleError(e); + actual.onError(e); + } catch (Throwable e2) { + if (e2 instanceof OnErrorNotImplementedException) { + /* + * onError isn't implemented so throw + * + * https://github.com/Netflix/RxJava/issues/198 + * + * Rx Design Guidelines 5.2 + * + * "when calling the Subscribe method that only has an onNext argument, the OnError behavior will be + * to rethrow the exception on the thread that the message comes out from the observable sequence. + * The OnCompleted behavior in this case is to do nothing." + */ + try { + unsubscribe(); + } catch (Throwable unsubscribeException) { + RxJavaPlugins.getInstance().getErrorHandler().handleError(unsubscribeException); + throw new RuntimeException("Observer.onError not implemented and error while unsubscribing.", new CompositeException(Arrays.asList(e, unsubscribeException))); + } + throw (OnErrorNotImplementedException) e2; + } else { + /* + * throw since the Rx contract is broken if onError failed + * + * https://github.com/Netflix/RxJava/issues/198 + */ + RxJavaPlugins.getInstance().getErrorHandler().handleError(e2); + try { + unsubscribe(); + } catch (Throwable unsubscribeException) { + RxJavaPlugins.getInstance().getErrorHandler().handleError(unsubscribeException); + throw new RuntimeException("Error occurred when trying to propagate error to Observer.onError and during unsubscription.", new CompositeException(Arrays.asList(e, e2, unsubscribeException))); + } + + throw new RuntimeException("Error occurred when trying to propagate error to Observer.onError", new CompositeException(Arrays.asList(e, e2))); + } + } + // if we did not throw above we will unsubscribe here, if onError failed then unsubscribe happens in the catch + try { + unsubscribe(); + } catch (RuntimeException unsubscribeException) { + RxJavaPlugins.getInstance().getErrorHandler().handleError(unsubscribeException); + throw unsubscribeException; + } + } + +} diff --git a/rxjava-core/src/main/java/rx/observers/SynchronizedObserver.java b/rxjava-core/src/main/java/rx/observers/SynchronizedObserver.java index 70bd34abda..ad18e6a2eb 100644 --- a/rxjava-core/src/main/java/rx/observers/SynchronizedObserver.java +++ b/rxjava-core/src/main/java/rx/observers/SynchronizedObserver.java @@ -16,6 +16,7 @@ package rx.observers; import rx.Observer; +import rx.Subscriber; import rx.operators.SafeObservableSubscription; /** @@ -30,7 +31,7 @@ * * @param */ -public final class SynchronizedObserver extends Observer { +public final class SynchronizedObserver implements Observer { /** * Intrinsic synchronized locking with double-check short-circuiting was chosen after testing several other implementations. @@ -52,14 +53,14 @@ public final class SynchronizedObserver extends Observer { private volatile boolean finished = false; private volatile Object lock; - public SynchronizedObserver(Observer Observer, SafeObservableSubscription subscription) { - this.observer = Observer; + public SynchronizedObserver(Observer subscriber, SafeObservableSubscription subscription) { + this.observer = subscriber; this.subscription = subscription; this.lock = this; } - public SynchronizedObserver(Observer Observer, SafeObservableSubscription subscription, Object lock) { - this.observer = Observer; + public SynchronizedObserver(Observer subscriber, SafeObservableSubscription subscription, Object lock) { + this.observer = subscriber; this.subscription = subscription; this.lock = lock; } @@ -69,8 +70,8 @@ public SynchronizedObserver(Observer Observer, SafeObservableSubscrip * * @param Observer */ - public SynchronizedObserver(Observer Observer) { - this(Observer, new SafeObservableSubscription()); + public SynchronizedObserver(Observer subscriber) { + this(subscriber, new SafeObservableSubscription()); } public void onNext(T arg) { diff --git a/rxjava-core/src/main/java/rx/observers/SynchronizedSubscriber.java b/rxjava-core/src/main/java/rx/observers/SynchronizedSubscriber.java new file mode 100644 index 0000000000..54eef0f8cc --- /dev/null +++ b/rxjava-core/src/main/java/rx/observers/SynchronizedSubscriber.java @@ -0,0 +1,69 @@ +/** + * Copyright 2014 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rx.observers; + +import rx.Observer; +import rx.Subscriber; +import rx.operators.SafeObservableSubscription; + +/** + * A thread-safe Observer for transitioning states in operators. + *

+ * Execution rules are: + *

    + *
  • Allow only single-threaded, synchronous, ordered execution of onNext, onCompleted, onError
  • + *
  • Once an onComplete or onError are performed, no further calls can be executed
  • + *
  • If unsubscribe is called, this means we call completed() and don't allow any further onNext calls.
  • + *
+ * + * @param + */ +public final class SynchronizedSubscriber extends Subscriber { + + private final Observer observer; + + public SynchronizedSubscriber(Subscriber subscriber, Object lock) { + super(subscriber); + SafeObservableSubscription s = new SafeObservableSubscription(); + subscriber.add(s); + this.observer = new SynchronizedObserver(subscriber, s, lock); + } + + /** + * Used when synchronizing an Subscriber without access to the subscription. + * + * @param Observer + */ + public SynchronizedSubscriber(Subscriber subscriber) { + this(subscriber, new Object()); + } + + @Override + public void onCompleted() { + observer.onCompleted(); + } + + @Override + public void onError(Throwable e) { + observer.onError(e); + } + + @Override + public void onNext(T t) { + observer.onNext(t); + } + +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/rx/observers/TestObserver.java b/rxjava-core/src/main/java/rx/observers/TestObserver.java index 87342a7f4a..bbc667a546 100644 --- a/rxjava-core/src/main/java/rx/observers/TestObserver.java +++ b/rxjava-core/src/main/java/rx/observers/TestObserver.java @@ -25,7 +25,7 @@ /** * Observer usable for unit testing to perform assertions, inspect received events or wrap a mocked Observer. */ -public class TestObserver extends Observer { +public class TestObserver implements Observer { private final Observer EMPTY = new EmptyObserver(); diff --git a/rxjava-core/src/main/java/rx/observers/TestSubscriber.java b/rxjava-core/src/main/java/rx/observers/TestSubscriber.java new file mode 100644 index 0000000000..677c9dcb94 --- /dev/null +++ b/rxjava-core/src/main/java/rx/observers/TestSubscriber.java @@ -0,0 +1,84 @@ +/** + * Copyright 2014 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rx.observers; + +import java.util.List; + +import rx.Notification; +import rx.Observer; +import rx.Subscriber; + +/** + * Observer usable for unit testing to perform assertions, inspect received events or wrap a mocked Observer. + */ +public class TestSubscriber extends Subscriber { + + private final Subscriber EMPTY = Subscriber.from(new EmptyObserver()); + + private final TestObserver testObserver; + + public TestSubscriber(Subscriber delegate) { + this.testObserver = new TestObserver(delegate); + } + + public TestSubscriber(Observer delegate) { + this.testObserver = new TestObserver(delegate); + } + + @SuppressWarnings("unchecked") + public TestSubscriber() { + this.testObserver = new TestObserver((Subscriber) EMPTY); + } + + @Override + public void onCompleted() { + testObserver.onCompleted(); + } + + public List> getOnCompletedEvents() { + return testObserver.getOnCompletedEvents(); + } + + @Override + public void onError(Throwable e) { + testObserver.onError(e); + } + + public List getOnErrorEvents() { + return testObserver.getOnErrorEvents(); + } + + @Override + public void onNext(T t) { + testObserver.onNext(t); + } + + public List getOnNextEvents() { + return testObserver.getOnNextEvents(); + } + + public void assertReceivedOnNext(List items) { + testObserver.assertReceivedOnNext(items); + } + + /** + * Assert that a single terminal event occurred, either onCompleted or onError. + */ + public void assertTerminalEvent() { + testObserver.assertTerminalEvent(); + } + +} diff --git a/rxjava-core/src/main/java/rx/operators/ChunkedOperation.java b/rxjava-core/src/main/java/rx/operators/ChunkedOperation.java index 1f89a7ccc8..6fa8879777 100644 --- a/rxjava-core/src/main/java/rx/operators/ChunkedOperation.java +++ b/rxjava-core/src/main/java/rx/operators/ChunkedOperation.java @@ -394,7 +394,7 @@ public void pushValue(T value) { * The type of object all internal {@link rx.operators.ChunkedOperation.Chunk} objects record. * The type of object being tracked by the {@link Chunk} */ - protected static class ChunkObserver extends Observer { + protected static class ChunkObserver implements Observer { private final Chunks chunks; private final Observer observer; diff --git a/rxjava-core/src/main/java/rx/operators/OperationAll.java b/rxjava-core/src/main/java/rx/operators/OperationAll.java index 0387d194a7..2a68c0bd71 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationAll.java +++ b/rxjava-core/src/main/java/rx/operators/OperationAll.java @@ -52,7 +52,7 @@ public Subscription onSubscribe(final Observer observer) { } - private class AllObserver extends Observer { + private class AllObserver implements Observer { private final Observer underlying; private final AtomicBoolean status = new AtomicBoolean(true); diff --git a/rxjava-core/src/main/java/rx/operators/OperationAmb.java b/rxjava-core/src/main/java/rx/operators/OperationAmb.java index 5f4c3bfd48..16a6c307dd 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationAmb.java +++ b/rxjava-core/src/main/java/rx/operators/OperationAmb.java @@ -136,7 +136,7 @@ public Subscription onSubscribe(final Observer observer) { }; } - private static class AmbObserver extends Observer { + private static class AmbObserver implements Observer { private static final int NONE = -1; diff --git a/rxjava-core/src/main/java/rx/operators/OperationAny.java b/rxjava-core/src/main/java/rx/operators/OperationAny.java index 0de9f4d502..cb650a2bee 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationAny.java +++ b/rxjava-core/src/main/java/rx/operators/OperationAny.java @@ -80,7 +80,8 @@ private Any(Observable source, Func1 predicate, @Override public Subscription onSubscribe(final Observer observer) { - return source.subscribe(new Observer(observer) { + final SafeObservableSubscription subscription = new SafeObservableSubscription(); + return subscription.wrap(source.subscribe(new Observer() { private final AtomicBoolean hasEmitted = new AtomicBoolean(false); @@ -92,12 +93,16 @@ public void onNext(T value) { && hasEmitted.getAndSet(true) == false) { observer.onNext(!returnOnEmpty); observer.onCompleted(); - unsubscribe(); + // this will work if the sequence is asynchronous, it + // will have no effect on a synchronous observable + subscription.unsubscribe(); } } } catch (Throwable ex) { observer.onError(ex); - unsubscribe(); + // this will work if the sequence is asynchronous, it + // will have no effect on a synchronous observable + subscription.unsubscribe(); } } @@ -114,7 +119,7 @@ public void onCompleted() { observer.onCompleted(); } } - }); + })); } } diff --git a/rxjava-core/src/main/java/rx/operators/OperationAverage.java b/rxjava-core/src/main/java/rx/operators/OperationAverage.java index 38e54c7bf5..01a7ad0765 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationAverage.java +++ b/rxjava-core/src/main/java/rx/operators/OperationAverage.java @@ -128,7 +128,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class AverageObserver extends Observer { + private final class AverageObserver implements Observer { final Observer observer; int sum; int count; @@ -188,7 +188,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class AverageObserver extends Observer { + private final class AverageObserver implements Observer { final Observer observer; long sum; int count; @@ -248,7 +248,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class AverageObserver extends Observer { + private final class AverageObserver implements Observer { final Observer observer; float sum; int count; @@ -308,7 +308,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class AverageObserver extends Observer { + private final class AverageObserver implements Observer { final Observer observer; double sum; int count; diff --git a/rxjava-core/src/main/java/rx/operators/OperationBuffer.java b/rxjava-core/src/main/java/rx/operators/OperationBuffer.java index ba596f3f97..b0946f0351 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationBuffer.java +++ b/rxjava-core/src/main/java/rx/operators/OperationBuffer.java @@ -444,7 +444,7 @@ public Subscription onSubscribe(Observer> t1) { /** * Observes the source. */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer> observer; /** The buffer, if null, that indicates a terminal state. */ List buffer; @@ -514,7 +514,7 @@ void emitAndComplete() { /** * Observes the boundary. */ - private static final class BoundaryObserver extends Observer { + private static final class BoundaryObserver implements Observer { final SourceObserver so; public BoundaryObserver(SourceObserver so) { diff --git a/rxjava-core/src/main/java/rx/operators/OperationCache.java b/rxjava-core/src/main/java/rx/operators/OperationCache.java index 56c6f74460..eb10bc9ab6 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationCache.java +++ b/rxjava-core/src/main/java/rx/operators/OperationCache.java @@ -56,7 +56,7 @@ public Subscription onSubscribe(Observer observer) { */ } - return cache.toObservable().subscribe(observer); + return cache.subscribe(observer); } }; diff --git a/rxjava-core/src/main/java/rx/operators/OperationCombineLatest.java b/rxjava-core/src/main/java/rx/operators/OperationCombineLatest.java index cd7dd1014e..9e05b1c7c4 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationCombineLatest.java +++ b/rxjava-core/src/main/java/rx/operators/OperationCombineLatest.java @@ -275,7 +275,7 @@ public void completed(int index) { /** * Observes a specific source and communicates with the collector. */ - final class SourceObserver extends Observer { + final class SourceObserver implements Observer { final SafeObservableSubscription self; final Collector collector; final int index; diff --git a/rxjava-core/src/main/java/rx/operators/OperationDebounce.java b/rxjava-core/src/main/java/rx/operators/OperationDebounce.java index 08e6d0a0a6..9cad959c80 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationDebounce.java +++ b/rxjava-core/src/main/java/rx/operators/OperationDebounce.java @@ -98,7 +98,7 @@ public Subscription onSubscribe(Observer observer) { } } - private static class DebounceObserver extends Observer { + private static class DebounceObserver implements Observer { private final Observer observer; private final long timeout; @@ -186,7 +186,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observe the source. */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer observer; final Func1> debounceSelector; final CompositeSubscription cancel; @@ -274,7 +274,7 @@ public void onCompleted() { /** * The debounce observer. */ - private static final class DebounceObserver extends Observer { + private static final class DebounceObserver implements Observer { final SourceObserver parent; final Subscription cancel; final T value; diff --git a/rxjava-core/src/main/java/rx/operators/OperationDefaultIfEmpty.java b/rxjava-core/src/main/java/rx/operators/OperationDefaultIfEmpty.java index 58bbc0bcc0..924a508500 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationDefaultIfEmpty.java +++ b/rxjava-core/src/main/java/rx/operators/OperationDefaultIfEmpty.java @@ -55,7 +55,8 @@ private DefaultIfEmpty(Observable source, T defaultValue) { @Override public Subscription onSubscribe(final Observer observer) { - return source.subscribe(new Observer(observer) { + final SafeObservableSubscription subscription = new SafeObservableSubscription(); + return subscription.wrap(source.subscribe(new Observer() { private volatile boolean hasEmitted = false; @@ -66,7 +67,9 @@ public void onNext(T value) { observer.onNext(value); } catch (Throwable ex) { observer.onError(ex); - unsubscribe(); + // this will work if the sequence is asynchronous, it + // will have no effect on a synchronous observable + subscription.unsubscribe(); } } @@ -84,7 +87,7 @@ public void onCompleted() { observer.onCompleted(); } } - }); + })); } } } diff --git a/rxjava-core/src/main/java/rx/operators/OperationDelay.java b/rxjava-core/src/main/java/rx/operators/OperationDelay.java index dea9f32313..5bd391758e 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationDelay.java +++ b/rxjava-core/src/main/java/rx/operators/OperationDelay.java @@ -146,7 +146,7 @@ public Subscription onSubscribe(Observer t1) { } /** Subscribe delay observer. */ - private static final class SubscribeDelay extends Observer { + private static final class SubscribeDelay implements Observer { final Observable source; final SourceObserver so; final CompositeSubscription csub; @@ -186,7 +186,7 @@ public void onCompleted() { } /** The source observer. */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer observer; final Func1> itemDelay; final CompositeSubscription csub; @@ -274,7 +274,7 @@ boolean checkDone() { /** * Delay observer. */ - private static final class DelayObserver extends Observer { + private static final class DelayObserver implements Observer { final T value; final SourceObserver parent; final Subscription token; diff --git a/rxjava-core/src/main/java/rx/operators/OperationDematerialize.java b/rxjava-core/src/main/java/rx/operators/OperationDematerialize.java index 493376c9b7..9bfd901f7e 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationDematerialize.java +++ b/rxjava-core/src/main/java/rx/operators/OperationDematerialize.java @@ -54,7 +54,7 @@ public DematerializeObservable(Observable> s @Override public Subscription onSubscribe(final Observer observer) { - return sequence.subscribe(new Observer>(observer) { + return sequence.subscribe(new Observer>() { @Override public void onCompleted() { } diff --git a/rxjava-core/src/main/java/rx/operators/OperationDistinct.java b/rxjava-core/src/main/java/rx/operators/OperationDistinct.java index bbf7530017..9fc8f94ffe 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationDistinct.java +++ b/rxjava-core/src/main/java/rx/operators/OperationDistinct.java @@ -97,7 +97,7 @@ private Distinct(Observable source, Func1 k @Override public Subscription onSubscribe(final Observer observer) { - return source.subscribe(new Observer(observer) { + final Subscription sourceSub = source.subscribe(new Observer() { private final Set emittedKeys = new HashSet(); @Override @@ -119,6 +119,13 @@ public void onNext(T next) { } } }); + + return Subscriptions.create(new Action0() { + @Override + public void call() { + sourceSub.unsubscribe(); + } + }); } } @@ -135,7 +142,7 @@ private DistinctWithComparator(Observable source, Func1 observer) { - return source.subscribe(new Observer(observer) { + final Subscription sourceSub = source.subscribe(new Observer() { // due to the totally arbitrary equality comparator, we can't use anything more efficient than lists here private final List emittedKeys = new ArrayList(); @@ -168,6 +175,13 @@ private boolean alreadyEmitted(U newKey) { return false; } }); + + return Subscriptions.create(new Action0() { + @Override + public void call() { + sourceSub.unsubscribe(); + } + }); } } } diff --git a/rxjava-core/src/main/java/rx/operators/OperationDistinctUntilChanged.java b/rxjava-core/src/main/java/rx/operators/OperationDistinctUntilChanged.java index 259001c6ba..b78da98f96 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationDistinctUntilChanged.java +++ b/rxjava-core/src/main/java/rx/operators/OperationDistinctUntilChanged.java @@ -108,7 +108,7 @@ private DistinctUntilChanged(Observable source, Func1 observer) { - return source.subscribe(new Observer(observer) { + final Subscription sourceSub = source.subscribe(new Observer() { private U lastEmittedKey; private boolean hasEmitted; @@ -135,6 +135,13 @@ public void onNext(T next) { } } }); + + return Subscriptions.create(new Action0() { + @Override + public void call() { + sourceSub.unsubscribe(); + } + }); } } } diff --git a/rxjava-core/src/main/java/rx/operators/OperationDoOnEach.java b/rxjava-core/src/main/java/rx/operators/OperationDoOnEach.java deleted file mode 100644 index 510e4a53d1..0000000000 --- a/rxjava-core/src/main/java/rx/operators/OperationDoOnEach.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright 2014 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observable.OnSubscribeFunc; -import rx.Observer; -import rx.Subscription; - -/** - * Converts the elements of an observable sequence to the specified type. - */ -public class OperationDoOnEach { - public static OnSubscribeFunc doOnEach(Observable sequence, Observer observer) { - return new DoOnEachObservable(sequence, observer); - } - - private static class DoOnEachObservable implements OnSubscribeFunc { - - private final Observable sequence; - private final Observer doOnEachObserver; - - public DoOnEachObservable(Observable sequence, Observer doOnEachObserver) { - this.sequence = sequence; - this.doOnEachObserver = doOnEachObserver; - } - - @Override - public Subscription onSubscribe(final Observer observer) { - return sequence.subscribe(new Observer(observer) { - @Override - public void onCompleted() { - try { - doOnEachObserver.onCompleted(); - } catch (Throwable e) { - onError(e); - return; - } - observer.onCompleted(); - } - - @Override - public void onError(Throwable e) { - try { - doOnEachObserver.onError(e); - } catch (Throwable e2) { - observer.onError(e2); - return; - } - observer.onError(e); - } - - @Override - public void onNext(T value) { - try { - doOnEachObserver.onNext(value); - } catch (Throwable e) { - onError(e); - return; - } - observer.onNext(value); - } - }); - } - - } -} \ No newline at end of file diff --git a/rxjava-core/src/main/java/rx/operators/OperationFilter.java b/rxjava-core/src/main/java/rx/operators/OperationFilter.java index 1dd338223c..ada9aa9a29 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationFilter.java +++ b/rxjava-core/src/main/java/rx/operators/OperationFilter.java @@ -43,7 +43,8 @@ public Filter(Observable that, Func1 predicate) } public Subscription onSubscribe(final Observer observer) { - return that.subscribe(new Observer(observer) { + final SafeObservableSubscription subscription = new SafeObservableSubscription(); + return subscription.wrap(that.subscribe(new Observer() { public void onNext(T value) { try { if (predicate.call(value)) { @@ -51,7 +52,8 @@ public void onNext(T value) { } } catch (Throwable ex) { observer.onError(ex); - unsubscribe(); + // this will work if the sequence is asynchronous, it will have no effect on a synchronous observable + subscription.unsubscribe(); } } @@ -62,7 +64,7 @@ public void onError(Throwable ex) { public void onCompleted() { observer.onCompleted(); } - }); + })); } } diff --git a/rxjava-core/src/main/java/rx/operators/OperationFinally.java b/rxjava-core/src/main/java/rx/operators/OperationFinally.java index 62e08d1787..0d0667f1f8 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationFinally.java +++ b/rxjava-core/src/main/java/rx/operators/OperationFinally.java @@ -71,7 +71,7 @@ public Subscription onSubscribe(Observer observer) { return sequence.subscribe(new FinallyObserver(observer)); } - private class FinallyObserver extends Observer { + private class FinallyObserver implements Observer { private final Observer observer; FinallyObserver(Observer observer) { diff --git a/rxjava-core/src/main/java/rx/operators/OperationFlatMap.java b/rxjava-core/src/main/java/rx/operators/OperationFlatMap.java index acc4f7cbb8..8e9c6202b4 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationFlatMap.java +++ b/rxjava-core/src/main/java/rx/operators/OperationFlatMap.java @@ -108,7 +108,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observes the source, starts the collections and projects the result. */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer observer; final Func1> collectionSelector; final Func2 resultSelector; @@ -193,7 +193,7 @@ void emit(T t, U u) { } /** Observe a collection and call emit with the pair of the key and the value. */ - private static final class CollectionObserver extends Observer { + private static final class CollectionObserver implements Observer { final SourceObserver so; final Subscription cancel; final T value; @@ -271,7 +271,7 @@ public Subscription onSubscribe(Observer t1) { * @param * the result value type */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer observer; final Func1> onNext; final Func1> onError; @@ -359,7 +359,7 @@ void finish() { } /** Observes the collections. */ - private static final class CollectionObserver extends Observer { + private static final class CollectionObserver implements Observer { final SourceObserver parent; final Subscription cancel; diff --git a/rxjava-core/src/main/java/rx/operators/OperationGroupByUntil.java b/rxjava-core/src/main/java/rx/operators/OperationGroupByUntil.java index 7c686fff3e..ab93b52015 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationGroupByUntil.java +++ b/rxjava-core/src/main/java/rx/operators/OperationGroupByUntil.java @@ -24,6 +24,7 @@ import rx.Observable.OnSubscribe; import rx.Observable.OnSubscribeFunc; import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.observables.GroupedObservable; import rx.subjects.PublishSubject; @@ -63,7 +64,7 @@ public Subscription onSubscribe(Observer { + class ResultSink implements Observer { /** Guarded by gate. */ protected final Observer> observer; protected final Subscription cancel; @@ -180,7 +181,7 @@ public void expire(TKey key, Subscription handle) { } /** Observe the completion of a group. */ - class DurationObserver extends Observer { + class DurationObserver implements Observer { final TKey key; final Subscription handle; @@ -208,7 +209,7 @@ public void onCompleted() { } /** A grouped observable with subject-like behavior. */ - public static class GroupSubject extends Observer { + public static class GroupSubject implements Observer { protected final Subject publish; private final K key; @@ -220,8 +221,8 @@ public GroupSubject(K key, final Subject publish) { public GroupedObservable toObservable() { return new GroupedObservable(key, new OnSubscribe() { @Override - public void call(Observer o) { - publish.toObservable().subscribe(o); + public void call(Subscriber o) { + publish.subscribe(o); } }); } diff --git a/rxjava-core/src/main/java/rx/operators/OperationGroupJoin.java b/rxjava-core/src/main/java/rx/operators/OperationGroupJoin.java index 7045fd276b..8ec39d7d67 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationGroupJoin.java +++ b/rxjava-core/src/main/java/rx/operators/OperationGroupJoin.java @@ -90,8 +90,8 @@ public void init() { group.add(s1); group.add(s2); - s1.set(left.subscribe(new LeftObserver(s1))); - s2.set(right.subscribe(new RightObserver(s2))); + s1.setSubscription(left.subscribe(new LeftObserver(s1))); + s2.setSubscription(right.subscribe(new RightObserver(s2))); } @@ -110,7 +110,7 @@ void groupsOnCompleted() { } /** Observe the left source. */ - class LeftObserver extends Observer { + class LeftObserver implements Observer { final Subscription tosource; public LeftObserver(Subscription tosource) { @@ -127,13 +127,13 @@ public void onNext(T1 args) { leftMap.put(id, subj); } - Observable window = Observable.create(new WindowObservableFunc(subj.toObservable(), cancel)); + Observable window = Observable.create(new WindowObservableFunc(subj, cancel)); Observable duration = leftDuration.call(args); SerialSubscription sduration = new SerialSubscription(); group.add(sduration); - sduration.set(duration.subscribe(new LeftDurationObserver(id, sduration, subj))); + sduration.setSubscription(duration.subscribe(new LeftDurationObserver(id, sduration, subj))); R result = resultSelector.call(args, window); @@ -175,7 +175,7 @@ public void onError(Throwable e) { } /** Observe the right source. */ - class RightObserver extends Observer { + class RightObserver implements Observer { final Subscription tosource; public RightObserver(Subscription tosource) { @@ -233,7 +233,7 @@ public void onError(Throwable e) { } /** Observe left duration and apply termination. */ - class LeftDurationObserver extends Observer { + class LeftDurationObserver implements Observer { final int id; final Subscription sduration; final Observer gr; @@ -269,7 +269,7 @@ public void onNext(D1 args) { } /** Observe right duration and apply termination. */ - class RightDurationObserver extends Observer { + class RightDurationObserver implements Observer { final int id; final Subscription sduration; @@ -318,14 +318,14 @@ public WindowObservableFunc(Observable underlying, RefCountSubscription refCo @Override public Subscription onSubscribe(Observer t1) { CompositeSubscription cs = new CompositeSubscription(); - cs.add(refCount.get()); + cs.add(refCount.getSubscription()); WindowObserver wo = new WindowObserver(t1, cs); cs.add(underlying.subscribe(wo)); return cs; } /** Observe activities on the window. */ - class WindowObserver extends Observer { + class WindowObserver implements Observer { final Observer observer; final Subscription self; diff --git a/rxjava-core/src/main/java/rx/operators/OperationJoin.java b/rxjava-core/src/main/java/rx/operators/OperationJoin.java index 163c328096..057aefc45b 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationJoin.java +++ b/rxjava-core/src/main/java/rx/operators/OperationJoin.java @@ -90,7 +90,7 @@ public Subscription run() { } /** Observes the left values. */ - class LeftObserver extends Observer { + class LeftObserver implements Observer { final Subscription self; public LeftObserver(Subscription self) { @@ -165,7 +165,7 @@ public void onCompleted() { } /** Observes the left duration. */ - class LeftDurationObserver extends Observer { + class LeftDurationObserver implements Observer { final int id; final Subscription handle; @@ -193,7 +193,7 @@ public void onCompleted() { } /** Observes the right values. */ - class RightObserver extends Observer { + class RightObserver implements Observer { final Subscription self; public RightObserver(Subscription self) { @@ -268,7 +268,7 @@ public void onCompleted() { } /** Observe the right duration. */ - class RightDurationObserver extends Observer { + class RightDurationObserver implements Observer { final int id; final Subscription handle; diff --git a/rxjava-core/src/main/java/rx/operators/OperationLatest.java b/rxjava-core/src/main/java/rx/operators/OperationLatest.java index 78a1444c4a..6cc213c37d 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationLatest.java +++ b/rxjava-core/src/main/java/rx/operators/OperationLatest.java @@ -48,7 +48,7 @@ public Iterator iterator() { } /** Observer of source, iterator for output. */ - static final class LatestObserverIterator extends Observer> implements Iterator { + static final class LatestObserverIterator implements Observer>, Iterator { final Semaphore notify = new Semaphore(0); // observer's notification final AtomicReference> reference = new AtomicReference>(); diff --git a/rxjava-core/src/main/java/rx/operators/OperationMaterialize.java b/rxjava-core/src/main/java/rx/operators/OperationMaterialize.java index 49507f365c..66356e1db0 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationMaterialize.java +++ b/rxjava-core/src/main/java/rx/operators/OperationMaterialize.java @@ -54,23 +54,23 @@ public MaterializeObservable(Observable sequence) { @Override public Subscription onSubscribe(final Observer> observer) { - return sequence.subscribe(new Observer(observer) { + return sequence.subscribe(new Observer() { @Override public void onCompleted() { - observer.onNext(Notification.createOnCompleted()); + observer.onNext(new Notification()); observer.onCompleted(); } @Override public void onError(Throwable e) { - observer.onNext(Notification.createOnError(e)); + observer.onNext(new Notification(e)); observer.onCompleted(); } @Override public void onNext(T value) { - observer.onNext(Notification.createOnNext(value)); + observer.onNext(new Notification(value)); } }); diff --git a/rxjava-core/src/main/java/rx/operators/OperationMergeDelayError.java b/rxjava-core/src/main/java/rx/operators/OperationMergeDelayError.java index c241fde8c0..dd1882e53c 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationMergeDelayError.java +++ b/rxjava-core/src/main/java/rx/operators/OperationMergeDelayError.java @@ -208,7 +208,7 @@ public boolean stop() { * * @param */ - private class ParentObserver extends Observer> { + private class ParentObserver implements Observer> { private final Observer actualObserver; public ParentObserver(Observer actualObserver) { @@ -274,7 +274,7 @@ public void onNext(Observable childObservable) { * Subscribe to each child Observable and forward their sequence of data to the actualObserver * */ - private class ChildObserver extends Observer { + private class ChildObserver implements Observer { private final Observer actualObserver; private volatile boolean finished = false; diff --git a/rxjava-core/src/main/java/rx/operators/OperationMostRecent.java b/rxjava-core/src/main/java/rx/operators/OperationMostRecent.java index 6cd17e5d9c..7af2f3fb1a 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationMostRecent.java +++ b/rxjava-core/src/main/java/rx/operators/OperationMostRecent.java @@ -74,7 +74,7 @@ public void remove() { } } - private static class MostRecentObserver extends Observer { + private static class MostRecentObserver implements Observer { private final AtomicBoolean completed = new AtomicBoolean(false); private final AtomicReference value; private final AtomicReference exception = new AtomicReference(); diff --git a/rxjava-core/src/main/java/rx/operators/OperationMulticast.java b/rxjava-core/src/main/java/rx/operators/OperationMulticast.java index e0f17d23b3..fc46b43fa0 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationMulticast.java +++ b/rxjava-core/src/main/java/rx/operators/OperationMulticast.java @@ -18,9 +18,9 @@ import rx.Observable; import rx.Observable.OnSubscribeFunc; import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.observables.ConnectableObservable; -import rx.observers.SafeObserver; import rx.subjects.Subject; import rx.subscriptions.CompositeSubscription; import rx.subscriptions.Subscriptions; @@ -43,8 +43,8 @@ private static class MulticastConnectableObservable extends ConnectableObs public MulticastConnectableObservable(Observable source, final Subject subject) { super(new OnSubscribe() { @Override - public void call(Observer observer) { - subject.toObservable().subscribe(observer); + public void call(Subscriber observer) { + subject.subscribe(observer); } }); this.source = source; @@ -137,7 +137,8 @@ public Subscription onSubscribe(Observer t1) { CompositeSubscription csub = new CompositeSubscription(); - csub.add(observable.subscribe(t1)); + csub.add(observable.subscribe(new SafeObserver( + new SafeObservableSubscription(csub), t1))); csub.add(connectable.connect()); return csub; diff --git a/rxjava-core/src/main/java/rx/operators/OperationNext.java b/rxjava-core/src/main/java/rx/operators/OperationNext.java index dff80fc14f..45d1fff72b 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationNext.java +++ b/rxjava-core/src/main/java/rx/operators/OperationNext.java @@ -126,7 +126,7 @@ public void remove() { } } - private static class NextObserver extends Observer> { + private static class NextObserver implements Observer> { private final BlockingQueue> buf = new ArrayBlockingQueue>(1); private final AtomicBoolean waiting = new AtomicBoolean(false); diff --git a/rxjava-core/src/main/java/rx/operators/OperationRepeat.java b/rxjava-core/src/main/java/rx/operators/OperationRepeat.java index 5b99fd5424..ade09aecce 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationRepeat.java +++ b/rxjava-core/src/main/java/rx/operators/OperationRepeat.java @@ -47,7 +47,7 @@ public Subscription onSubscribe(final Observer observer) { compositeSubscription.add(scheduler.schedule(new Action1() { @Override public void call(final Action0 self) { - innerSubscription.set(source.subscribe(new Observer(observer) { + innerSubscription.set(source.subscribe(new Observer() { @Override public void onCompleted() { diff --git a/rxjava-core/src/main/java/rx/operators/OperationReplay.java b/rxjava-core/src/main/java/rx/operators/OperationReplay.java index 05c852f755..b59b929980 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationReplay.java +++ b/rxjava-core/src/main/java/rx/operators/OperationReplay.java @@ -30,6 +30,7 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Scheduler; +import rx.Subscriber; import rx.Subscription; import rx.subjects.Subject; import rx.subscriptions.Subscriptions; @@ -62,11 +63,11 @@ public static Subject replayBuffered(int bufferSize) { * propagated through the given wrapped subject. */ public static Subject createScheduledSubject(Subject subject, Scheduler scheduler) { - final Observable observedOn = subject.toObservable().observeOn(scheduler); + final Observable observedOn = subject.observeOn(scheduler); SubjectWrapper s = new SubjectWrapper(new OnSubscribe() { @Override - public void call(Observer o) { + public void call(Subscriber o) { // TODO HACK between OnSubscribeFunc and Action1 subscriberOf(observedOn).onSubscribe(o); } @@ -198,18 +199,12 @@ public Subscription onSubscribe(Observer t1) { public static final class SubjectWrapper extends Subject { /** The wrapped subject. */ final Subject subject; - private final OnSubscribe func; public SubjectWrapper(OnSubscribe func, Subject subject) { - this.func = func; + super(func); this.subject = subject; } - @Override - public Observable toObservable() { - return Observable.create(func); - } - @Override public void onNext(T args) { subject.onNext(args); @@ -727,13 +722,19 @@ public static CustomReplaySubject create(int maxSize) { protected final ReplayState state; /** The result selector. */ protected final Func1 intermediateSelector; - private final OnSubscribeFunc onSubscribe; private CustomReplaySubject( final OnSubscribeFunc onSubscribe, ReplayState state, Func1 intermediateSelector) { - this.onSubscribe = onSubscribe; + super(new OnSubscribe() { + + @Override + public void call(Subscriber sub) { + onSubscribe.onSubscribe(sub); + } + + }); this.state = state; this.intermediateSelector = intermediateSelector; } @@ -793,11 +794,6 @@ protected void replayValues() { rp.replayTill(s); } } - - @Override - public Observable toObservable() { - return Observable.create(onSubscribe); - } } /** diff --git a/rxjava-core/src/main/java/rx/operators/OperationRetry.java b/rxjava-core/src/main/java/rx/operators/OperationRetry.java index 65fccff94f..3e55077849 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationRetry.java +++ b/rxjava-core/src/main/java/rx/operators/OperationRetry.java @@ -93,7 +93,7 @@ public void onError(Throwable e) { if ((retryCount == INFINITE_RETRY || attempts.get() <= retryCount) && !subscription.isUnsubscribed()) { // retry again // add the new subscription and schedule a retry recursively - rescursiveSubscription.set(scheduler.schedule(rescursiveSubscription, attemptSubscription(observer))); + rescursiveSubscription.setSubscription(scheduler.schedule(rescursiveSubscription, attemptSubscription(observer))); } else { // give up and pass the failure observer.onError(e); diff --git a/rxjava-core/src/main/java/rx/operators/OperationSample.java b/rxjava-core/src/main/java/rx/operators/OperationSample.java index 20c8248d11..57ceb97d22 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSample.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSample.java @@ -107,15 +107,13 @@ public void onNext(T value) { } }); - observer.add(Subscriptions.create(new Action0() { + return Subscriptions.create(new Action0() { @Override public void call() { clockSubscription.unsubscribe(); sourceSubscription.unsubscribe(); } - })); - - return observer; + }); } } @@ -139,7 +137,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observe source values. */ - class ResultManager extends Observer { + class ResultManager implements Observer { final Observer observer; final CompositeSubscription cancel; T value; @@ -191,7 +189,7 @@ public void onCompleted() { } /** Take the latest value, but only once. */ - class Sampler extends Observer { + class Sampler implements Observer { @Override public void onNext(U args) { synchronized (guard) { diff --git a/rxjava-core/src/main/java/rx/operators/OperationScan.java b/rxjava-core/src/main/java/rx/operators/OperationScan.java index 89ac8b23bb..3c58e053c5 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationScan.java +++ b/rxjava-core/src/main/java/rx/operators/OperationScan.java @@ -81,7 +81,7 @@ private AccuWithoutInitialValue(Observable sequence, Func2 @Override public Subscription onSubscribe(final Observer observer) { - return sequence.subscribe(new Observer(observer) { + return sequence.subscribe(new Observer() { // has to be synchronized so that the initial value is always sent only once. @Override @@ -125,14 +125,13 @@ public Subscription onSubscribe(final Observer observer) { } } - private static class AccumulatingObserver extends Observer { + private static class AccumulatingObserver implements Observer { private final Observer observer; private final Func2 accumulatorFunction; private R acc; private AccumulatingObserver(Observer observer, R initialValue, Func2 accumulator) { - super(observer); this.observer = observer; this.accumulatorFunction = accumulator; diff --git a/rxjava-core/src/main/java/rx/operators/OperationSingle.java b/rxjava-core/src/main/java/rx/operators/OperationSingle.java index e004bdd41f..871d565092 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSingle.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSingle.java @@ -44,7 +44,8 @@ private static OnSubscribeFunc single( @Override public Subscription onSubscribe(final Observer observer) { - return source.subscribe(new Observer(observer) { + final SafeObservableSubscription subscription = new SafeObservableSubscription(); + subscription.wrap(source.subscribe(new Observer() { private T value; private boolean isEmpty = true; @@ -84,10 +85,11 @@ public void onNext(T value) { hasTooManyElemenets = true; observer.onError(new IllegalArgumentException( "Sequence contains too many elements")); - unsubscribe(); + subscription.unsubscribe(); } } - }); + })); + return subscription; } }; } diff --git a/rxjava-core/src/main/java/rx/operators/OperationSkip.java b/rxjava-core/src/main/java/rx/operators/OperationSkip.java index 99d780262f..706ae08c80 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSkip.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSkip.java @@ -82,7 +82,7 @@ public Subscription onSubscribe(Observer observer) { /** * Used to subscribe to the 'items' Observable sequence and forward to the actualObserver up to 'num' count. */ - private class ItemObserver extends Observer { + private class ItemObserver implements Observer { private AtomicInteger counter = new AtomicInteger(); private final Observer observer; @@ -155,7 +155,7 @@ public Subscription onSubscribe(Observer t1) { * @param * the observed value type */ - private static final class SourceObserver extends Observer implements Action0 { + private static final class SourceObserver implements Observer, Action0 { final AtomicBoolean gate; final Observer observer; final Subscription cancel; diff --git a/rxjava-core/src/main/java/rx/operators/OperationSkipLast.java b/rxjava-core/src/main/java/rx/operators/OperationSkipLast.java index 4007c06efe..c20da050a1 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSkipLast.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSkipLast.java @@ -74,7 +74,8 @@ public Subscription onSubscribe(final Observer observer) { throw new IndexOutOfBoundsException( "count could not be negative"); } - return source.subscribe(new Observer(observer) { + final SafeObservableSubscription subscription = new SafeObservableSubscription(); + return subscription.wrap(source.subscribe(new Observer() { private final ReentrantLock lock = new ReentrantLock(); @@ -103,7 +104,7 @@ public void onNext(T value) { observer.onNext(value); } catch (Throwable ex) { observer.onError(ex); - unsubscribe(); + subscription.unsubscribe(); } return; } @@ -119,13 +120,13 @@ public void onNext(T value) { } } catch (Throwable ex) { observer.onError(ex); - unsubscribe(); + subscription.unsubscribe(); } finally { lock.unlock(); } } - }); + })); } } @@ -152,7 +153,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observes the source. */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer observer; final long timeInMillis; final Scheduler scheduler; diff --git a/rxjava-core/src/main/java/rx/operators/OperationSkipUntil.java b/rxjava-core/src/main/java/rx/operators/OperationSkipUntil.java index 0d106458bd..4f6cd185e7 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSkipUntil.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSkipUntil.java @@ -21,6 +21,7 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Subscription; +import rx.subscriptions.CompositeSubscription; import rx.subscriptions.SerialSubscription; /** @@ -44,13 +45,15 @@ public Subscription onSubscribe(Observer t1) { } /** Manage the source and other observers. */ - private class ResultManager extends Observer { + private class ResultManager implements Subscription, Observer { final Observer observer; + final CompositeSubscription cancel; final Object guard = new Object(); final AtomicBoolean running = new AtomicBoolean(); public ResultManager(Observer observer) { this.observer = observer; + this.cancel = new CompositeSubscription(); } public ResultManager init() { @@ -58,15 +61,20 @@ public ResultManager init() { SerialSubscription toSource = new SerialSubscription(); SerialSubscription toOther = new SerialSubscription(); - add(toSource); - add(toOther); + cancel.add(toSource); + cancel.add(toOther); - toSource.set(source.subscribe(this)); - toOther.set(other.subscribe(new OtherObserver(toOther))); + toSource.setSubscription(source.subscribe(this)); + toOther.setSubscription(other.subscribe(new OtherObserver(toOther))); return this; } + @Override + public void unsubscribe() { + cancel.unsubscribe(); + } + @Override public void onNext(T args) { if (running.get()) { @@ -91,7 +99,7 @@ public void onCompleted() { } /** Observe the other stream. */ - private class OtherObserver extends Observer { + private class OtherObserver implements Observer { final Subscription self; public OtherObserver(Subscription self) { diff --git a/rxjava-core/src/main/java/rx/operators/OperationSkipWhile.java b/rxjava-core/src/main/java/rx/operators/OperationSkipWhile.java index 23ec2af174..54476adb69 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSkipWhile.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSkipWhile.java @@ -58,7 +58,7 @@ public Subscription onSubscribe(Observer observer) { return source.subscribe(new SkipWhileObserver(observer)); } - private class SkipWhileObserver extends Observer { + private class SkipWhileObserver implements Observer { private final Observer observer; public SkipWhileObserver(Observer observer) { diff --git a/rxjava-core/src/main/java/rx/operators/OperationSum.java b/rxjava-core/src/main/java/rx/operators/OperationSum.java index f4b99d4544..4a12335e42 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSum.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSum.java @@ -85,7 +85,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class SumObserver extends Observer { + private final class SumObserver implements Observer { final Observer observer; int sum; boolean hasValue; @@ -145,7 +145,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class SumObserver extends Observer { + private final class SumObserver implements Observer { final Observer observer; long sum; boolean hasValue; @@ -205,7 +205,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class SumObserver extends Observer { + private final class SumObserver implements Observer { final Observer observer; float sum; boolean hasValue; @@ -265,7 +265,7 @@ public Subscription onSubscribe(Observer t1) { } /** Computes the average. */ - private final class SumObserver extends Observer { + private final class SumObserver implements Observer { final Observer observer; double sum; boolean hasValue; diff --git a/rxjava-core/src/main/java/rx/operators/OperationSwitch.java b/rxjava-core/src/main/java/rx/operators/OperationSwitch.java index 17563787ea..c6fc01d5af 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationSwitch.java +++ b/rxjava-core/src/main/java/rx/operators/OperationSwitch.java @@ -70,7 +70,7 @@ public Subscription onSubscribe(Observer observer) { } } - private static class SwitchObserver extends Observer> { + private static class SwitchObserver implements Observer> { private final Object gate; private final Observer observer; diff --git a/rxjava-core/src/main/java/rx/operators/OperationTakeLast.java b/rxjava-core/src/main/java/rx/operators/OperationTakeLast.java index 4c10e232b0..b4e64cf2ec 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationTakeLast.java +++ b/rxjava-core/src/main/java/rx/operators/OperationTakeLast.java @@ -64,7 +64,7 @@ public Subscription onSubscribe(Observer observer) { return subscription.wrap(items.subscribe(new ItemObserver(observer))); } - private class ItemObserver extends Observer { + private class ItemObserver implements Observer { /** * Store the last count elements until now. @@ -162,7 +162,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observes source values and keeps the most recent items. */ - static final class TakeLastTimedObserver extends Observer { + static final class TakeLastTimedObserver implements Observer { final Observer observer; final Subscription cancel; final long ageMillis; diff --git a/rxjava-core/src/main/java/rx/operators/OperationTakeTimed.java b/rxjava-core/src/main/java/rx/operators/OperationTakeTimed.java index 9d11cecaf5..2894edabbf 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationTakeTimed.java +++ b/rxjava-core/src/main/java/rx/operators/OperationTakeTimed.java @@ -109,7 +109,7 @@ public void onNext(T args) return subscription.wrap(items.subscribe(new ItemObserver(observer))); } - private class ItemObserver extends Observer { + private class ItemObserver implements Observer { private final Observer observer; private final AtomicInteger counter = new AtomicInteger(); @@ -210,7 +210,7 @@ public Subscription onSubscribe(Observer t1) { * @param * the observed value type */ - private static final class SourceObserver extends Observer implements Action0 { + private static final class SourceObserver implements Observer, Action0 { final Observer observer; final Subscription cancel; final AtomicInteger state = new AtomicInteger(); diff --git a/rxjava-core/src/main/java/rx/operators/OperationTakeUntil.java b/rxjava-core/src/main/java/rx/operators/OperationTakeUntil.java index b9ecc2c742..e06381afab 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationTakeUntil.java +++ b/rxjava-core/src/main/java/rx/operators/OperationTakeUntil.java @@ -120,7 +120,7 @@ public Subscription onSubscribe(final Observer> notifica return sequence.subscribe(new Observer() { @Override public void onCompleted() { - // Ignore + notificationObserver.onNext(Notification. halt()); } @Override diff --git a/rxjava-core/src/main/java/rx/operators/OperationTakeWhile.java b/rxjava-core/src/main/java/rx/operators/OperationTakeWhile.java index ff03b0bc68..219295d626 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationTakeWhile.java +++ b/rxjava-core/src/main/java/rx/operators/OperationTakeWhile.java @@ -21,7 +21,6 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Subscription; -import rx.observers.SafeObserver; import rx.util.functions.Func1; import rx.util.functions.Func2; @@ -88,6 +87,7 @@ public Boolean call(T input, Integer index) { private static class TakeWhile implements OnSubscribeFunc { private final Observable items; private final Func2 predicate; + private final SafeObservableSubscription subscription = new SafeObservableSubscription(); private TakeWhile(Observable items, Func2 predicate) { this.items = items; @@ -96,20 +96,19 @@ private TakeWhile(Observable items, Func2 observer) { - return items.subscribe(new ItemObserver(observer)); + return subscription.wrap(items.subscribe(new ItemObserver(observer))); } - private class ItemObserver extends Observer { + private class ItemObserver implements Observer { private final Observer observer; private final AtomicInteger counter = new AtomicInteger(); public ItemObserver(Observer observer) { - super(observer); // Using AtomicObserver because the unsubscribe, onCompleted, onError and error handling behavior // needs "isFinished" logic to not send duplicated events // The 'testTakeWhile1' and 'testTakeWhile2' tests fail without this. - this.observer = new SafeObserver(observer); + this.observer = new SafeObserver(subscription, observer); } @Override @@ -135,7 +134,8 @@ public void onNext(T args) { observer.onNext(args); } else { observer.onCompleted(); - unsubscribe(); + // this will work if the sequence is asynchronous, it will have no effect on a synchronous observable + subscription.unsubscribe(); } } diff --git a/rxjava-core/src/main/java/rx/operators/OperationTimeInterval.java b/rxjava-core/src/main/java/rx/operators/OperationTimeInterval.java index 3e2a297bc9..b2c67b4851 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationTimeInterval.java +++ b/rxjava-core/src/main/java/rx/operators/OperationTimeInterval.java @@ -45,7 +45,7 @@ public Subscription onSubscribe( }; } - private static class TimeIntervalObserver extends Observer { + private static class TimeIntervalObserver implements Observer { private final Observer> observer; /** diff --git a/rxjava-core/src/main/java/rx/operators/OperationTimeout.java b/rxjava-core/src/main/java/rx/operators/OperationTimeout.java index 80cf600e1d..cf838a6061 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationTimeout.java +++ b/rxjava-core/src/main/java/rx/operators/OperationTimeout.java @@ -197,7 +197,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observe the source. */ - private static final class SourceObserver extends Observer implements TimeoutCallback { + private static final class SourceObserver implements Observer, TimeoutCallback { final Observer observer; final Func1> valueTimeout; final Observable other; @@ -292,7 +292,7 @@ private interface TimeoutCallback { } /** Observe the timeout. */ - private static final class TimeoutObserver extends Observer { + private static final class TimeoutObserver implements Observer { final TimeoutCallback parent; public TimeoutObserver(TimeoutCallback parent) { diff --git a/rxjava-core/src/main/java/rx/operators/OperationToMap.java b/rxjava-core/src/main/java/rx/operators/OperationToMap.java index 1189157e86..e15c180aec 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationToMap.java +++ b/rxjava-core/src/main/java/rx/operators/OperationToMap.java @@ -124,7 +124,7 @@ public Subscription onSubscribe(Observer> t1) { * Observer that collects the source values of T into * a map. */ - public static class ToMapObserver extends Observer { + public static class ToMapObserver implements Observer { /** The map. */ Map map; /** Key extractor. */ diff --git a/rxjava-core/src/main/java/rx/operators/OperationToMultimap.java b/rxjava-core/src/main/java/rx/operators/OperationToMultimap.java index 1a4d0390c4..a04c3545cb 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationToMultimap.java +++ b/rxjava-core/src/main/java/rx/operators/OperationToMultimap.java @@ -163,7 +163,7 @@ public Subscription onSubscribe(Observer>> t1) { /** * Observer that collects the source values of Ts into a multimap. */ - public static class ToMultimapObserver extends Observer { + public static class ToMultimapObserver implements Observer { private final Func1 keySelector; private final Func1 valueSelector; private final Func1> collectionFactory; diff --git a/rxjava-core/src/main/java/rx/operators/OperationUsing.java b/rxjava-core/src/main/java/rx/operators/OperationUsing.java index 446400de4b..6476c03745 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationUsing.java +++ b/rxjava-core/src/main/java/rx/operators/OperationUsing.java @@ -19,7 +19,6 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Subscription; -import rx.observers.SafeObserver; import rx.subscriptions.CompositeSubscription; import rx.subscriptions.Subscriptions; import rx.util.functions.Func0; @@ -43,8 +42,13 @@ public Subscription onSubscribe(Observer observer) { resourceSubscription = resource; } Observable observable = observableFactory.call(resource); - // Use SafeObserver to guarantee resourceSubscription will be unsubscribed. - return new CompositeSubscription(observable.subscribe(new SafeObserver(observer)), resourceSubscription); + SafeObservableSubscription subscription = new SafeObservableSubscription(); + // Use SafeObserver to guarantee resourceSubscription will + // be unsubscribed. + return subscription.wrap(new CompositeSubscription( + observable.subscribe(new SafeObserver( + subscription, observer)), + resourceSubscription)); } catch (Throwable e) { resourceSubscription.unsubscribe(); return Observable. error(e).subscribe(observer); diff --git a/rxjava-core/src/main/java/rx/operators/OperationWindow.java b/rxjava-core/src/main/java/rx/operators/OperationWindow.java index 3156108c26..eae1f059ef 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationWindow.java +++ b/rxjava-core/src/main/java/rx/operators/OperationWindow.java @@ -386,7 +386,7 @@ public Subscription onSubscribe(Observer> t1) { final SourceObserver so = new SourceObserver(t1, csub); try { - t1.onNext(so.subject.toObservable()); + t1.onNext(so.subject); } catch (Throwable t) { t1.onError(t); return Subscriptions.empty(); @@ -403,7 +403,7 @@ public Subscription onSubscribe(Observer> t1) { /** * Observe the source and emit the values into the current window. */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer> observer; final Subscription cancel; final Object guard; @@ -470,7 +470,7 @@ public void replace() { s.onCompleted(); subject = create(); - observer.onNext(subject.toObservable()); + observer.onNext(subject); } } catch (Throwable t) { onError(t); @@ -481,7 +481,7 @@ public void replace() { /** * Observe the boundary and replace the window on each item. */ - private static final class BoundaryObserver extends Observer { + private static final class BoundaryObserver implements Observer { final SourceObserver so; public BoundaryObserver(SourceObserver so) { diff --git a/rxjava-core/src/main/java/rx/operators/OperationZip.java b/rxjava-core/src/main/java/rx/operators/OperationZip.java index d9c42c2e33..5b05946913 100644 --- a/rxjava-core/src/main/java/rx/operators/OperationZip.java +++ b/rxjava-core/src/main/java/rx/operators/OperationZip.java @@ -150,7 +150,7 @@ public Subscription onSubscribe(final Observer observer) { final List> all = new ArrayList>(); - Observer> o2 = new Observer>(observer) { + Observer> o2 = new Observer>() { boolean done; @Override public void onCompleted() { @@ -198,7 +198,7 @@ public void onNext(List value) { * @param * the element type */ - private static final class ItemObserver extends Observer { + private static final class ItemObserver implements Observer, Subscription { /** Reader-writer lock. */ protected final ReadWriteLock rwLock; /** The queue. */ @@ -241,7 +241,6 @@ public ItemObserver( this.source = source; this.observer = observer; this.cancel = cancel; - add(toSource); } @Override @@ -291,6 +290,11 @@ public void connect() { toSource.set(source.subscribe(this)); } + @Override + public void unsubscribe() { + toSource.unsubscribe(); + } + private void runCollector() { if (rwLock.writeLock().tryLock()) { boolean cu = false; @@ -378,7 +382,7 @@ public Subscription onSubscribe(Observer t1) { } /** Observe the source. */ - private static final class SourceObserver extends Observer { + private static final class SourceObserver implements Observer { final Observer observer; final Iterator other; final Func2 zipFunction; diff --git a/rxjava-core/src/main/java/rx/operators/Operator.java b/rxjava-core/src/main/java/rx/operators/Operator.java index 32204821e0..6ba540e1a5 100644 --- a/rxjava-core/src/main/java/rx/operators/Operator.java +++ b/rxjava-core/src/main/java/rx/operators/Operator.java @@ -1,8 +1,8 @@ package rx.operators; -import rx.Observer; +import rx.Subscriber; import rx.util.functions.Func1; -public interface Operator extends Func1, Observer> { +public interface Operator extends Func1, Subscriber> { } diff --git a/rxjava-core/src/main/java/rx/operators/OperatorCast.java b/rxjava-core/src/main/java/rx/operators/OperatorCast.java index f0330a3b01..65678cdda6 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorCast.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorCast.java @@ -15,7 +15,7 @@ */ package rx.operators; -import rx.Observer; +import rx.Subscriber; /** @@ -30,8 +30,8 @@ public OperatorCast(Class castClass) { } @Override - public Observer call(final Observer o) { - return new Observer(o) { + public Subscriber call(final Subscriber o) { + return new Subscriber(o) { @Override public void onCompleted() { diff --git a/rxjava-core/src/main/java/rx/operators/OperatorDoOnEach.java b/rxjava-core/src/main/java/rx/operators/OperatorDoOnEach.java new file mode 100644 index 0000000000..7c0023ec6d --- /dev/null +++ b/rxjava-core/src/main/java/rx/operators/OperatorDoOnEach.java @@ -0,0 +1,68 @@ +/** + * Copyright 2014 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rx.operators; + +import rx.Observer; +import rx.Subscriber; + +/** + * Converts the elements of an observable sequence to the specified type. + */ +public class OperatorDoOnEach implements Operator { + private final Observer doOnEachObserver; + + public OperatorDoOnEach(Observer doOnEachObserver) { + this.doOnEachObserver = doOnEachObserver; + } + + @Override + public Subscriber call(final Subscriber observer) { + return new Subscriber(observer) { + @Override + public void onCompleted() { + try { + doOnEachObserver.onCompleted(); + } catch (Throwable e) { + onError(e); + return; + } + observer.onCompleted(); + } + + @Override + public void onError(Throwable e) { + try { + doOnEachObserver.onError(e); + } catch (Throwable e2) { + observer.onError(e2); + return; + } + observer.onError(e); + } + + @Override + public void onNext(T value) { + try { + doOnEachObserver.onNext(value); + } catch (Throwable e) { + onError(e); + return; + } + observer.onNext(value); + } + }; + } +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/rx/operators/OperatorFromIterable.java b/rxjava-core/src/main/java/rx/operators/OperatorFromIterable.java index 30bb7c7c93..750fa9ba24 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorFromIterable.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorFromIterable.java @@ -16,7 +16,7 @@ package rx.operators; import rx.Observable.OnSubscribe; -import rx.Observer; +import rx.Subscriber; /** * Converts an Iterable sequence into an Observable. @@ -35,7 +35,7 @@ public OperatorFromIterable(Iterable iterable) { } @Override - public void call(Observer o) { + public void call(Subscriber o) { for (T i : is) { if (o.isUnsubscribed()) { return; diff --git a/rxjava-core/src/main/java/rx/operators/OperatorGroupBy.java b/rxjava-core/src/main/java/rx/operators/OperatorGroupBy.java index 121d3bdd6d..6226461876 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorGroupBy.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorGroupBy.java @@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; import rx.Observable.OnSubscribe; -import rx.Observer; +import rx.Subscriber; import rx.observables.GroupedObservable; import rx.subjects.PublishSubject; import rx.subscriptions.CompositeSubscription; @@ -43,10 +43,10 @@ public OperatorGroupBy(final Func1 keySelector) { } @Override - public Observer call(final Observer> childObserver) { + public Subscriber call(final Subscriber> childObserver) { // a new CompositeSubscription to decouple the subscription as the inner subscriptions need a separate lifecycle // and will unsubscribe on this parent if they are all unsubscribed - return new Observer(new CompositeSubscription()) { + return new Subscriber(new CompositeSubscription()) { private final Map> groups = new HashMap>(); private final AtomicInteger completionCounter = new AtomicInteger(0); @@ -86,7 +86,7 @@ public void onNext(T t) { GroupedObservable go = new GroupedObservable(key, new OnSubscribe() { @Override - public void call(final Observer o) { + public void call(final Subscriber o) { // number of children we have running completionCounter.incrementAndGet(); o.add(Subscriptions.create(new Action0() { @@ -97,7 +97,7 @@ public void call() { } })); - _gps.toObservable().subscribe(new Observer(o) { + _gps.subscribe(new Subscriber(o) { @Override public void onCompleted() { diff --git a/rxjava-core/src/main/java/rx/operators/OperatorMap.java b/rxjava-core/src/main/java/rx/operators/OperatorMap.java index 889710393c..3c23124ff8 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorMap.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorMap.java @@ -15,7 +15,7 @@ */ package rx.operators; -import rx.Observer; +import rx.Subscriber; import rx.util.functions.Func1; /** @@ -33,8 +33,8 @@ public OperatorMap(Func1 transformer) { } @Override - public Observer call(final Observer o) { - return new Observer(o) { + public Subscriber call(final Subscriber o) { + return new Subscriber(o) { @Override public void onCompleted() { diff --git a/rxjava-core/src/main/java/rx/operators/OperatorMerge.java b/rxjava-core/src/main/java/rx/operators/OperatorMerge.java index 3a641b6b2a..0514fee7c6 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorMerge.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorMerge.java @@ -19,8 +19,8 @@ import java.util.concurrent.atomic.AtomicInteger; import rx.Observable; -import rx.Observer; -import rx.observers.SynchronizedObserver; +import rx.Subscriber; +import rx.observers.SynchronizedSubscriber; import rx.subscriptions.CompositeSubscription; /** @@ -46,15 +46,15 @@ public OperatorMerge(int maxConcurrent) { } @Override - public Observer> call(final Observer outerOperation) { + public Subscriber> call(final Subscriber outerOperation) { final AtomicInteger completionCounter = new AtomicInteger(1); final AtomicInteger concurrentCounter = new AtomicInteger(1); // Concurrent* since we'll be accessing them from the inner Observers which can be on other threads final ConcurrentLinkedQueue> pending = new ConcurrentLinkedQueue>(); - final Observer o = new SynchronizedObserver(outerOperation); - return new Observer>(outerOperation) { + final Subscriber o = new SynchronizedSubscriber(outerOperation); + return new Subscriber>(outerOperation) { @Override public void onCompleted() { @@ -106,7 +106,7 @@ private void complete() { } } - final class InnerObserver extends Observer { + final class InnerObserver extends Subscriber { public InnerObserver(CompositeSubscription cs) { super(cs); diff --git a/rxjava-core/src/main/java/rx/operators/OperatorParallel.java b/rxjava-core/src/main/java/rx/operators/OperatorParallel.java index 6375ee2f3d..9e1cf294d4 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorParallel.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorParallel.java @@ -16,8 +16,8 @@ package rx.operators; import rx.Observable; -import rx.Observer; import rx.Scheduler; +import rx.Subscriber; import rx.observables.GroupedObservable; import rx.util.functions.Func1; @@ -35,9 +35,9 @@ public OperatorParallel(Func1, Observable> f, Scheduler schedul } @Override - public Observer call(Observer op) { + public Subscriber call(Subscriber op) { - Func1>, Observer> groupBy = + Func1>, Subscriber> groupBy = new OperatorGroupBy(new Func1() { int i = 0; @@ -49,7 +49,7 @@ public Integer call(T t) { }); - Func1>, Observer>> map = + Func1>, Subscriber>> map = new OperatorMap, Observable>( new Func1, Observable>() { diff --git a/rxjava-core/src/main/java/rx/operators/OperatorTake.java b/rxjava-core/src/main/java/rx/operators/OperatorTake.java index 1a1c10aabb..c1463608cc 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorTake.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorTake.java @@ -15,7 +15,7 @@ */ package rx.operators; -import rx.Observer; +import rx.Subscriber; import rx.subscriptions.CompositeSubscription; /** @@ -38,7 +38,7 @@ public OperatorTake(int limit) { } @Override - public Observer call(final Observer o) { + public Subscriber call(final Subscriber o) { CompositeSubscription parent = new CompositeSubscription(); if (limit == 0) { o.onCompleted(); @@ -50,7 +50,7 @@ public Observer call(final Observer o) { * * Thus, we only unsubscribe UPWARDS to the parent and an onComplete DOWNSTREAM. */ - return new Observer(parent) { + return new Subscriber(parent) { int count = 0; boolean completed = false; diff --git a/rxjava-core/src/main/java/rx/operators/OperatorTimestamp.java b/rxjava-core/src/main/java/rx/operators/OperatorTimestamp.java index 1f46c295bf..12dfef137b 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorTimestamp.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorTimestamp.java @@ -15,8 +15,8 @@ */ package rx.operators; -import rx.Observer; import rx.Scheduler; +import rx.Subscriber; import rx.util.Timestamped; /** @@ -36,8 +36,8 @@ public OperatorTimestamp(Scheduler scheduler) { * @return a sequence of timestamped values created by adding timestamps to each item in the input sequence. */ @Override - public Observer call(final Observer> o) { - return new Observer(o) { + public Subscriber call(final Subscriber> o) { + return new Subscriber(o) { @Override public void onCompleted() { diff --git a/rxjava-core/src/main/java/rx/operators/OperatorToObservableList.java b/rxjava-core/src/main/java/rx/operators/OperatorToObservableList.java index 0d1442796a..3b45f72d8b 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorToObservableList.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorToObservableList.java @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.List; -import rx.Observer; +import rx.Subscriber; /** * Returns an Observable that emits a single item, a list composed of all the items emitted by the @@ -37,8 +37,8 @@ public final class OperatorToObservableList implements Operator, T> { @Override - public Observer call(final Observer> o) { - return new Observer(o) { + public Subscriber call(final Subscriber> o) { + return new Subscriber(o) { final List list = new ArrayList(); diff --git a/rxjava-core/src/main/java/rx/operators/OperatorToObservableSortedList.java b/rxjava-core/src/main/java/rx/operators/OperatorToObservableSortedList.java index 1b8732e844..90f3aa18e2 100644 --- a/rxjava-core/src/main/java/rx/operators/OperatorToObservableSortedList.java +++ b/rxjava-core/src/main/java/rx/operators/OperatorToObservableSortedList.java @@ -20,7 +20,7 @@ import java.util.Comparator; import java.util.List; -import rx.Observer; +import rx.Subscriber; import rx.util.functions.Func2; /** @@ -45,8 +45,8 @@ public OperatorToObservableSortedList(Func2 sortF } @Override - public Observer call(final Observer> o) { - return new Observer(o) { + public Subscriber call(final Subscriber> o) { + return new Subscriber(o) { final List list = new ArrayList(); diff --git a/rxjava-core/src/main/java/rx/observers/SafeObserver.java b/rxjava-core/src/main/java/rx/operators/SafeObserver.java similarity index 90% rename from rxjava-core/src/main/java/rx/observers/SafeObserver.java rename to rxjava-core/src/main/java/rx/operators/SafeObserver.java index 66798c688f..ae621d13ab 100644 --- a/rxjava-core/src/main/java/rx/observers/SafeObserver.java +++ b/rxjava-core/src/main/java/rx/operators/SafeObserver.java @@ -1,5 +1,5 @@ /** - * Copyright 2014 Netflix, Inc. + * Copyright 2013 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package rx.observers; +package rx.operators; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; import rx.Observer; import rx.Subscription; -import rx.operators.SafeObservableSubscription; import rx.plugins.RxJavaPlugins; import rx.subscriptions.Subscriptions; import rx.util.CompositeException; @@ -57,14 +56,22 @@ * It will not synchronize onNext execution. Use the {@link SynchronizedObserver} to do that. * * @param + * @Deprecated Replaced by SafeSubscriber */ -public class SafeObserver extends Observer { +@Deprecated +public class SafeObserver implements Observer { private final Observer actual; private final AtomicBoolean isFinished = new AtomicBoolean(false); + private final Subscription subscription; public SafeObserver(Observer actual) { - super(actual); + this.subscription = Subscriptions.empty(); + this.actual = actual; + } + + public SafeObserver(SafeObservableSubscription subscription, Observer actual) { + this.subscription = subscription; this.actual = actual; } @@ -78,7 +85,7 @@ public void onCompleted() { _onError(e); } finally { // auto-unsubscribe - unsubscribe(); + subscription.unsubscribe(); } } } @@ -125,7 +132,7 @@ protected void _onError(Throwable e) { * The OnCompleted behavior in this case is to do nothing." */ try { - unsubscribe(); + subscription.unsubscribe(); } catch (Throwable unsubscribeException) { RxJavaPlugins.getInstance().getErrorHandler().handleError(unsubscribeException); throw new RuntimeException("Observer.onError not implemented and error while unsubscribing.", new CompositeException(Arrays.asList(e, unsubscribeException))); @@ -139,7 +146,7 @@ protected void _onError(Throwable e) { */ RxJavaPlugins.getInstance().getErrorHandler().handleError(e2); try { - unsubscribe(); + subscription.unsubscribe(); } catch (Throwable unsubscribeException) { RxJavaPlugins.getInstance().getErrorHandler().handleError(unsubscribeException); throw new RuntimeException("Error occurred when trying to propagate error to Observer.onError and during unsubscription.", new CompositeException(Arrays.asList(e, e2, unsubscribeException))); @@ -148,9 +155,9 @@ protected void _onError(Throwable e) { throw new RuntimeException("Error occurred when trying to propagate error to Observer.onError", new CompositeException(Arrays.asList(e, e2))); } } - // if we did not throw above we will unsubscribe here, if onError failed then unsubscribe happens in the catch + // if we did not throw about we will unsubscribe here, if onError failed then unsubscribe happens in the catch try { - unsubscribe(); + subscription.unsubscribe(); } catch (RuntimeException unsubscribeException) { RxJavaPlugins.getInstance().getErrorHandler().handleError(unsubscribeException); throw unsubscribeException; diff --git a/rxjava-core/src/main/java/rx/package-info.java b/rxjava-core/src/main/java/rx/package-info.java index 944d93ec79..fb3dc1f459 100644 --- a/rxjava-core/src/main/java/rx/package-info.java +++ b/rxjava-core/src/main/java/rx/package-info.java @@ -38,7 +38,7 @@ *

Services which intend on exposing data asynchronously and wish * to allow reactive processing and composition can implement the {@link rx.Observable} interface which then allows Observers to subscribe to them * and receive events.

- *

Usage examples can be found on the {@link rx.Observable} and {@link rx.Observer} classes.

+ *

Usage examples can be found on the {@link rx.Observable} and {@link rx.Subscriber} classes.

*/ package rx; diff --git a/rxjava-core/src/main/java/rx/plugins/RxJavaErrorHandler.java b/rxjava-core/src/main/java/rx/plugins/RxJavaErrorHandler.java index 7ca897412b..9ccef7c46a 100644 --- a/rxjava-core/src/main/java/rx/plugins/RxJavaErrorHandler.java +++ b/rxjava-core/src/main/java/rx/plugins/RxJavaErrorHandler.java @@ -16,12 +16,12 @@ package rx.plugins; import rx.Observable; -import rx.Observer; +import rx.Subscriber; /** - * Abstract class for defining error handling logic in addition to the normal {@link Observer#onError(Throwable)} behavior. + * Abstract class for defining error handling logic in addition to the normal {@link Subscriber#onError(Throwable)} behavior. *

- * For example, all Exceptions can be logged using this handler even if {@link Observer#onError(Throwable)} is ignored or not provided when an {@link Observable} is subscribed to. + * For example, all Exceptions can be logged using this handler even if {@link Subscriber#onError(Throwable)} is ignored or not provided when an {@link Observable} is subscribed to. *

* See {@link RxJavaPlugins} or the RxJava GitHub Wiki for information on configuring plugins: https://github.com/Netflix/RxJava/wiki/Plugins. @@ -29,7 +29,7 @@ public abstract class RxJavaErrorHandler { /** - * Receives all Exceptions from an {@link Observable} passed to {@link Observer#onError(Throwable)}. + * Receives all Exceptions from an {@link Observable} passed to {@link Subscriber#onError(Throwable)}. *

* This should NEVER throw an Exception. Make sure to try/catch(Throwable) all code inside this method implementation. * diff --git a/rxjava-core/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java b/rxjava-core/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java index bf2b0f6e2f..c3aa2b44ad 100644 --- a/rxjava-core/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java +++ b/rxjava-core/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java @@ -18,7 +18,7 @@ import rx.Observable; import rx.Observable.OnSubscribe; import rx.Observable.OnSubscribeFunc; -import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.util.functions.Func1; @@ -39,15 +39,15 @@ public abstract class RxJavaObservableExecutionHook { /** - * Invoked before {@link Observable#subscribe(rx.Observer)} is about to be executed. + * Invoked before {@link Observable#subscribe(rx.Subscriber)} is about to be executed. *

* This can be used to decorate or replace the onSubscribe function or just perform extra logging, metrics and other such things and pass-thru the function. * * @param observableInstance * The executing {@link Observable} instance. * @param onSubscribe - * original {@link Func1}<{@link Observer}{@code }, {@link Subscription}> to be executed - * @return {@link Func1}<{@link Observer}{@code }, {@link Subscription}> function that can be modified, decorated, replaced or just returned as a pass-thru. + * original {@link Func1}<{@link Subscriber}{@code }, {@link Subscription}> to be executed + * @return {@link Func1}<{@link Subscriber}{@code }, {@link Subscription}> function that can be modified, decorated, replaced or just returned as a pass-thru. */ @Deprecated public OnSubscribeFunc onSubscribeStart(Observable observableInstance, OnSubscribeFunc onSubscribe) { @@ -61,7 +61,7 @@ public OnSubscribe onSubscribeStart(Observable observableIns } /** - * Invoked after successful execution of {@link Observable#subscribe(rx.Observer)} with returned {@link Subscription}. + * Invoked after successful execution of {@link Observable#subscribe(rx.Subscriber)} with returned {@link Subscription}. *

* This can be used to decorate or replace the {@link Subscription} instance or just perform extra logging, metrics and other such things and pass-thru the subscription. * @@ -77,15 +77,15 @@ public Subscription onSubscribeReturn(Observable observableInst } /** - * Invoked after failed execution of {@link Observable#subscribe(Observer)} with thrown Throwable. + * Invoked after failed execution of {@link Observable#subscribe(Subscriber)} with thrown Throwable. *

- * This is NOT errors emitted via {@link Observer#onError(Throwable)} but exceptions thrown when attempting - * to subscribe to a {@link Func1}<{@link Observer}{@code }, {@link Subscription}>. + * This is NOT errors emitted via {@link Subscriber#onError(Throwable)} but exceptions thrown when attempting + * to subscribe to a {@link Func1}<{@link Subscriber}{@code }, {@link Subscription}>. * * @param observableInstance * The executing {@link Observable} instance. * @param e - * Throwable thrown by {@link Observable#subscribe(Observer)} + * Throwable thrown by {@link Observable#subscribe(Subscriber)} * @return Throwable that can be decorated, replaced or just returned as a pass-thru. */ public Throwable onSubscribeError(Observable observableInstance, Throwable e) { diff --git a/rxjava-core/src/main/java/rx/subjects/AsyncSubject.java b/rxjava-core/src/main/java/rx/subjects/AsyncSubject.java index 78fd158d64..16eeeb0bc6 100644 --- a/rxjava-core/src/main/java/rx/subjects/AsyncSubject.java +++ b/rxjava-core/src/main/java/rx/subjects/AsyncSubject.java @@ -19,8 +19,6 @@ import java.util.concurrent.atomic.AtomicReference; import rx.Notification; -import rx.Observable; -import rx.Observable.OnSubscribe; import rx.Observer; import rx.subjects.SubjectSubscriptionManager.SubjectObserver; import rx.util.functions.Action1; @@ -98,17 +96,11 @@ protected static void emitValueToObserver(Notification n, Observer subscriptionManager; final AtomicReference> lastNotification; - private final Observable observable; protected AsyncSubject(OnSubscribe onSubscribe, SubjectSubscriptionManager subscriptionManager, AtomicReference> lastNotification) { + super(onSubscribe); this.subscriptionManager = subscriptionManager; this.lastNotification = lastNotification; - this.observable = Observable.create(onSubscribe); - } - - @Override - public Observable toObservable() { - return observable; } @Override @@ -130,7 +122,7 @@ public void onError(final Throwable e) { @Override public void call(Collection> observers) { - lastNotification.set(Notification.createOnError(e)); + lastNotification.set(new Notification(e)); for (Observer o : observers) { emitValueToObserver(lastNotification.get(), o); } @@ -141,7 +133,7 @@ public void call(Collection> observers) { @Override public void onNext(T v) { - lastNotification.set(Notification.createOnNext(v)); + lastNotification.set(new Notification(v)); } -} +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/rx/subjects/BehaviorSubject.java b/rxjava-core/src/main/java/rx/subjects/BehaviorSubject.java index 214c3f5940..3c1cdaa433 100644 --- a/rxjava-core/src/main/java/rx/subjects/BehaviorSubject.java +++ b/rxjava-core/src/main/java/rx/subjects/BehaviorSubject.java @@ -19,8 +19,6 @@ import java.util.concurrent.atomic.AtomicReference; import rx.Notification; -import rx.Observable; -import rx.Observable.OnSubscribe; import rx.Observer; import rx.subjects.SubjectSubscriptionManager.SubjectObserver; import rx.util.functions.Action1; @@ -68,6 +66,18 @@ */ public final class BehaviorSubject extends Subject { + /** + * Creates a {@link BehaviorSubject} which publishes the last and all subsequent events to each {@link Observer} that subscribes to it. + * + * @param defaultValue + * The value which will be published to any {@link Observer} as long as the {@link BehaviorSubject} has not yet received any events. + * @return the constructed {@link BehaviorSubject}. + * @deprecated Use {@link create()} instead. + */ + public static BehaviorSubject createWithDefaultValue(T defaultValue) { + return create(defaultValue); + } + /** * Creates a {@link BehaviorSubject} which publishes the last and all subsequent events to each {@link Observer} that subscribes to it. * @@ -121,17 +131,11 @@ public void call(SubjectObserver o) { private final SubjectSubscriptionManager subscriptionManager; final AtomicReference> lastNotification; - private final Observable observable; protected BehaviorSubject(OnSubscribe onSubscribe, SubjectSubscriptionManager subscriptionManager, AtomicReference> lastNotification) { + super(onSubscribe); this.subscriptionManager = subscriptionManager; this.lastNotification = lastNotification; - this.observable = Observable.create(onSubscribe); - } - - @Override - public Observable toObservable() { - return observable; } @Override @@ -140,7 +144,7 @@ public void onCompleted() { @Override public void call(Collection> observers) { - lastNotification.set(Notification.createOnCompleted()); + lastNotification.set(new Notification()); for (Observer o : observers) { o.onCompleted(); } @@ -154,7 +158,7 @@ public void onError(final Throwable e) { @Override public void call(Collection> observers) { - lastNotification.set(Notification.createOnError(e)); + lastNotification.set(new Notification(e)); for (Observer o : observers) { o.onError(e); } @@ -168,11 +172,11 @@ public void onNext(T v) { // do not overwrite a terminal notification // so new subscribers can get them if (lastNotification.get().isOnNext()) { - lastNotification.set(Notification.createOnNext(v)); + lastNotification.set(new Notification(v)); for (Observer o : subscriptionManager.rawSnapshot()) { o.onNext(v); } } } -} +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/rx/subjects/PublishSubject.java b/rxjava-core/src/main/java/rx/subjects/PublishSubject.java index 4d2850b73f..508e561e1d 100644 --- a/rxjava-core/src/main/java/rx/subjects/PublishSubject.java +++ b/rxjava-core/src/main/java/rx/subjects/PublishSubject.java @@ -19,9 +19,8 @@ import java.util.concurrent.atomic.AtomicReference; import rx.Notification; -import rx.Observable; -import rx.Observable.OnSubscribe; import rx.Observer; +import rx.Subscriber; import rx.subjects.SubjectSubscriptionManager.SubjectObserver; import rx.util.functions.Action1; @@ -88,17 +87,11 @@ public void call(SubjectObserver o) { private final SubjectSubscriptionManager subscriptionManager; final AtomicReference> lastNotification; - private final Observable observable; protected PublishSubject(OnSubscribe onSubscribe, SubjectSubscriptionManager subscriptionManager, AtomicReference> lastNotification) { + super(onSubscribe); this.subscriptionManager = subscriptionManager; this.lastNotification = lastNotification; - this.observable = Observable.create(onSubscribe); - } - - @Override - public Observable toObservable() { - return observable; } @Override @@ -107,7 +100,7 @@ public void onCompleted() { @Override public void call(Collection> observers) { - lastNotification.set(Notification.createOnCompleted()); + lastNotification.set(new Notification()); for (Observer o : observers) { o.onCompleted(); } @@ -121,7 +114,7 @@ public void onError(final Throwable e) { @Override public void call(Collection> observers) { - lastNotification.set(Notification.createOnError(e)); + lastNotification.set(new Notification(e)); for (Observer o : observers) { o.onError(e); } @@ -136,4 +129,4 @@ public void onNext(T v) { o.onNext(v); } } -} +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/rx/subjects/ReplaySubject.java b/rxjava-core/src/main/java/rx/subjects/ReplaySubject.java index c167ef17d1..ce5023963c 100644 --- a/rxjava-core/src/main/java/rx/subjects/ReplaySubject.java +++ b/rxjava-core/src/main/java/rx/subjects/ReplaySubject.java @@ -22,8 +22,6 @@ import java.util.concurrent.atomic.AtomicReference; import rx.Notification; -import rx.Observable; -import rx.Observable.OnSubscribe; import rx.Observer; import rx.subjects.SubjectSubscriptionManager.SubjectObserver; import rx.util.functions.Action1; @@ -108,17 +106,11 @@ public ReplayState(int initialCapacity) { private final SubjectSubscriptionManager subscriptionManager; private final ReplayState state; - private final Observable observable; protected ReplaySubject(OnSubscribe onSubscribe, SubjectSubscriptionManager subscriptionManager, ReplayState state) { + super(onSubscribe); this.subscriptionManager = subscriptionManager; this.state = state; - this.observable = Observable.create(onSubscribe); - } - - @Override - public Observable toObservable() { - return observable; } @Override @@ -127,7 +119,7 @@ public void onCompleted() { @Override public void call(Collection> observers) { - state.history.complete(Notification.createOnCompleted()); + state.history.complete(new Notification()); for (SubjectObserver o : observers) { if (caughtUp(o)) { o.onCompleted(); @@ -143,7 +135,7 @@ public void onError(final Throwable e) { @Override public void call(Collection> observers) { - state.history.complete(Notification.createOnError(e)); + state.history.complete(new Notification(e)); for (SubjectObserver o : observers) { if (caughtUp(o)) { o.onError(e); @@ -238,4 +230,4 @@ public void complete(Notification n) { } } -} +} \ No newline at end of file diff --git a/rxjava-core/src/main/java/rx/subjects/Subject.java b/rxjava-core/src/main/java/rx/subjects/Subject.java index 52340ae2ff..e914874a9d 100644 --- a/rxjava-core/src/main/java/rx/subjects/Subject.java +++ b/rxjava-core/src/main/java/rx/subjects/Subject.java @@ -18,8 +18,8 @@ import rx.Observable; import rx.Observer; -public abstract class Subject extends Observer { - - public abstract Observable toObservable(); - +public abstract class Subject extends Observable implements Observer { + protected Subject(OnSubscribe onSubscribe) { + super(onSubscribe); + } } diff --git a/rxjava-core/src/main/java/rx/subjects/SubjectSubscriptionManager.java b/rxjava-core/src/main/java/rx/subjects/SubjectSubscriptionManager.java index e1a6b67cf4..945eef700f 100644 --- a/rxjava-core/src/main/java/rx/subjects/SubjectSubscriptionManager.java +++ b/rxjava-core/src/main/java/rx/subjects/SubjectSubscriptionManager.java @@ -20,11 +20,11 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; -import rx.Observable.OnSubscribe; import rx.Observer; +import rx.Subscriber; import rx.Subscription; +import rx.Observable.OnSubscribe; import rx.operators.SafeObservableSubscription; -import rx.subscriptions.Subscriptions; import rx.util.functions.Action1; /* package */class SubjectSubscriptionManager { @@ -42,8 +42,8 @@ public OnSubscribe getOnSubscribeFunc(final Action1> onSubscribe, final Action1> onTerminated) { return new OnSubscribe() { @Override - public void call(Observer actualObserver) { - SubjectObserver observer = new SubjectObserver(actualObserver); + public void call(Subscriber actualOperator) { + SubjectObserver observer = new SubjectObserver(actualOperator); // invoke onSubscribe logic if (onSubscribe != null) { onSubscribe.call(observer); @@ -52,12 +52,10 @@ public void call(Observer actualObserver) { State current; State newState = null; boolean addedObserver = false; - Subscription s; do { current = state.get(); if (current.terminated) { // we are terminated so don't need to do anything - s = Subscriptions.empty(); addedObserver = false; // break out and don't try to modify state newState = current; @@ -70,8 +68,10 @@ public void call(Observer actualObserver) { } break; } else { + final SafeObservableSubscription subscription = new SafeObservableSubscription(); + actualOperator.add(subscription); // add to parent if the Subject itself is unsubscribed addedObserver = true; - s = new Subscription() { + subscription.wrap(new Subscription() { @Override public void unsubscribe() { State current; @@ -79,13 +79,13 @@ public void unsubscribe() { do { current = state.get(); // on unsubscribe remove it from the map of outbound observers to notify - newState = current.removeObserver(this); + newState = current.removeObserver(subscription); } while (!state.compareAndSet(current, newState)); } - }; + }); // on subscribe add it to the map of outbound observers to notify - newState = current.addObserver(s, observer); + newState = current.addObserver(subscription, observer); } } while (!state.compareAndSet(current, newState)); @@ -95,13 +95,12 @@ public void unsubscribe() { if (newState.terminated && !addedObserver) { onTerminated.call(observer); } - - actualObserver.add(s); } }; } + @SuppressWarnings({ "unchecked", "rawtypes" }) protected void terminate(Action1>> onTerminate) { State current; State newState = null; @@ -136,6 +135,7 @@ protected void terminate(Action1>> onTermi * * @return the array of current observers */ + @SuppressWarnings("unchecked") public SubjectObserver[] rawSnapshot() { return state.get().observers; } @@ -226,13 +226,12 @@ public State removeObserver(Subscription s) { } } - protected static class SubjectObserver extends Observer { + protected static class SubjectObserver implements Observer { private final Observer actual; protected volatile boolean caughtUp = false; SubjectObserver(Observer actual) { - super(actual); this.actual = actual; } diff --git a/rxjava-core/src/main/java/rx/util/OnErrorNotImplementedException.java b/rxjava-core/src/main/java/rx/util/OnErrorNotImplementedException.java index 260035aebe..b50ea97419 100644 --- a/rxjava-core/src/main/java/rx/util/OnErrorNotImplementedException.java +++ b/rxjava-core/src/main/java/rx/util/OnErrorNotImplementedException.java @@ -15,10 +15,10 @@ */ package rx.util; -import rx.Observer; +import rx.Subscriber; /** - * Used for re-throwing {@link Observer#onError(Throwable)} when an implementation doesn't exist. + * Used for re-throwing {@link Subscriber#onError(Throwable)} when an implementation doesn't exist. * * https://github.com/Netflix/RxJava/issues/198 * diff --git a/rxjava-core/src/main/java/rx/util/functions/Actions.java b/rxjava-core/src/main/java/rx/util/functions/Actions.java index 63304570a9..5d4d3656dc 100644 --- a/rxjava-core/src/main/java/rx/util/functions/Actions.java +++ b/rxjava-core/src/main/java/rx/util/functions/Actions.java @@ -16,6 +16,7 @@ package rx.util.functions; import rx.Observer; +import rx.Subscriber; /** * Utility class for the Action interfaces. diff --git a/rxjava-core/src/test/java/rx/ErrorHandlingTests.java b/rxjava-core/src/test/java/rx/ErrorHandlingTests.java index 1eb6a646c0..7e30305d0b 100644 --- a/rxjava-core/src/test/java/rx/ErrorHandlingTests.java +++ b/rxjava-core/src/test/java/rx/ErrorHandlingTests.java @@ -35,7 +35,7 @@ public void testOnNextError() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); Observable o = Observable.interval(50, TimeUnit.MILLISECONDS); - Observer observer = new Observer() { + Subscriber observer = new Subscriber() { @Override public void onCompleted() { @@ -70,7 +70,7 @@ public void testOnNextErrorAcrossThread() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); Observable o = Observable.interval(50, TimeUnit.MILLISECONDS); - Observer observer = new Observer() { + Subscriber observer = new Subscriber() { @Override public void onCompleted() { diff --git a/rxjava-core/src/test/java/rx/ObservableTests.java b/rxjava-core/src/test/java/rx/ObservableTests.java index 1e33b2bd72..1ada4f37cd 100644 --- a/rxjava-core/src/test/java/rx/ObservableTests.java +++ b/rxjava-core/src/test/java/rx/ObservableTests.java @@ -36,7 +36,6 @@ import rx.Observable.OnSubscribeFunc; import rx.observables.ConnectableObservable; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subscriptions.BooleanSubscription; import rx.subscriptions.Subscriptions; @@ -117,7 +116,7 @@ public Subscription onSubscribe(Observer Observer) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -128,7 +127,7 @@ public Subscription onSubscribe(Observer Observer) { @Test public void testCountAFewItems() { Observable observable = Observable.from("a", "b", "c", "d"); - observable.count().subscribe(new TestObserver(w)); + observable.count().subscribe(w); // we should be called only once verify(w, times(1)).onNext(anyInt()); verify(w).onNext(4); @@ -139,7 +138,7 @@ public void testCountAFewItems() { @Test public void testCountZeroItems() { Observable observable = Observable.empty(); - observable.count().subscribe(new TestObserver(w)); + observable.count().subscribe(w); // we should be called only once verify(w, times(1)).onNext(anyInt()); verify(w).onNext(0); @@ -156,7 +155,7 @@ public Subscription onSubscribe(Observer obsv) { return Subscriptions.empty(); } }); - o.count().subscribe(new TestObserver(w)); + o.count().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onCompleted(); verify(w, times(1)).onError(any(RuntimeException.class)); @@ -164,7 +163,7 @@ public Subscription onSubscribe(Observer obsv) { public void testTakeFirstWithPredicateOfSome() { Observable observable = Observable.from(1, 3, 5, 4, 6, 3); - observable.takeFirst(IS_EVEN).subscribe(new TestObserver(w)); + observable.takeFirst(IS_EVEN).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(4); verify(w, times(1)).onCompleted(); @@ -174,7 +173,7 @@ public void testTakeFirstWithPredicateOfSome() { @Test public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { Observable observable = Observable.from(1, 3, 5, 7, 9, 7, 5, 3, 1); - observable.takeFirst(IS_EVEN).subscribe(new TestObserver(w)); + observable.takeFirst(IS_EVEN).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onCompleted(); verify(w, never()).onError(any(Throwable.class)); @@ -183,7 +182,7 @@ public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { @Test public void testTakeFirstOfSome() { Observable observable = Observable.from(1, 2, 3); - observable.takeFirst().subscribe(new TestObserver(w)); + observable.takeFirst().subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(1); verify(w, times(1)).onCompleted(); @@ -193,7 +192,7 @@ public void testTakeFirstOfSome() { @Test public void testTakeFirstOfNone() { Observable observable = Observable.empty(); - observable.takeFirst().subscribe(new TestObserver(w)); + observable.takeFirst().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onCompleted(); verify(w, never()).onError(any(Throwable.class)); @@ -202,7 +201,7 @@ public void testTakeFirstOfNone() { @Test public void testFirstOfNone() { Observable observable = Observable.empty(); - observable.first().subscribe(new TestObserver(w)); + observable.first().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onCompleted(); verify(w, times(1)).onError(isA(IllegalArgumentException.class)); @@ -211,7 +210,7 @@ public void testFirstOfNone() { @Test public void testFirstWithPredicateOfNoneMatchingThePredicate() { Observable observable = Observable.from(1, 3, 5, 7, 9, 7, 5, 3, 1); - observable.first(IS_EVEN).subscribe(new TestObserver(w)); + observable.first(IS_EVEN).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onCompleted(); verify(w, times(1)).onError(isA(IllegalArgumentException.class)); @@ -227,7 +226,7 @@ public Integer call(Integer t1, Integer t2) { return t1 + t2; } - }).subscribe(new TestObserver(w)); + }).subscribe(w); // we should be called only once verify(w, times(1)).onNext(anyInt()); verify(w).onNext(10); @@ -287,7 +286,7 @@ public Integer call(Integer t1, Integer t2) { return t1 + t2; } - }).subscribe(new TestObserver(w)); + }).subscribe(w); // we should be called only once verify(w, times(1)).onNext(anyInt()); verify(w).onNext(60); @@ -306,7 +305,7 @@ public Subscription onSubscribe(Observer t1) { } }); - o.subscribe(new TestObserver(observer)); + o.subscribe(observer); verify(observer, times(0)).onNext(anyString()); verify(observer, times(0)).onCompleted(); verify(observer, times(1)).onError(re); @@ -319,7 +318,7 @@ public void testMaterializeDematerializeChaining() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - chained.subscribe(new TestObserver(observer)); + chained.subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onCompleted(); @@ -362,7 +361,7 @@ public void run() { }).start(); return s; } - }).subscribe(new Observer() { + }).subscribe(new Subscriber() { @Override public void onCompleted() { System.out.println("completed"); @@ -415,7 +414,7 @@ public Subscription onSubscribe(Observer observer) { observer.onCompleted(); return Subscriptions.empty(); } - }).subscribe(new Observer() { + }).subscribe(new Subscriber() { @Override public void onCompleted() { @@ -463,7 +462,7 @@ public Subscription onSubscribe(Observer observer) { observer.onNext("2"); throw new NumberFormatException(); } - }).subscribe(new Observer() { + }).subscribe(new Subscriber() { @Override public void onCompleted() { @@ -773,7 +772,7 @@ public void call(String t1) { public void testTakeWithErrorInObserver() { final AtomicInteger count = new AtomicInteger(); final AtomicReference error = new AtomicReference(); - Observable.from("1", "2", "three", "4").take(3).subscribe(new Observer() { + Observable.from("1", "2", "three", "4").take(3).subscribe(new Subscriber() { @Override public void onCompleted() { @@ -809,7 +808,7 @@ public void testOfType() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(1); verify(observer, times(1)).onNext("abc"); verify(observer, never()).onNext(false); @@ -831,7 +830,7 @@ public void testOfTypeWithPolymorphism() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(l1); verify(observer, times(1)).onNext(l2); verify(observer, never()).onNext("123"); @@ -846,7 +845,7 @@ public void testContains() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(true); verify(observer, never()).onNext(false); verify(observer, never()).onError( @@ -860,7 +859,7 @@ public void testContainsWithInexistence() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError( @@ -874,7 +873,7 @@ public void testContainsWithNull() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(true); verify(observer, never()).onNext(false); verify(observer, never()).onError( @@ -888,7 +887,7 @@ public void testContainsWithEmptyObservable() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError( @@ -902,7 +901,7 @@ public void testIgnoreElements() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(any(Integer.class)); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -915,7 +914,7 @@ public void testFromWithScheduler() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); @@ -933,7 +932,7 @@ public void testStartWithWithScheduler() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); @@ -953,7 +952,7 @@ public void testRangeWithScheduler() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); diff --git a/rxjava-core/src/test/java/rx/RefCountTests.java b/rxjava-core/src/test/java/rx/RefCountTests.java index f2c0aeb309..a017d40b2d 100644 --- a/rxjava-core/src/test/java/rx/RefCountTests.java +++ b/rxjava-core/src/test/java/rx/RefCountTests.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.mockito.MockitoAnnotations; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subscriptions.Subscriptions; import rx.util.functions.Action0; @@ -58,9 +57,9 @@ public void call() { }); Observable refCounted = observable.publish().refCount(); Observer observer = mock(Observer.class); - Subscription first = refCounted.subscribe(new TestObserver(observer)); + Subscription first = refCounted.subscribe(observer); assertEquals(1, subscriptionCount.get()); - Subscription second = refCounted.subscribe(new TestObserver(observer)); + Subscription second = refCounted.subscribe(observer); assertEquals(1, subscriptionCount.get()); first.unsubscribe(); assertEquals(0, unsubscriptionCount.get()); diff --git a/rxjava-core/src/test/java/rx/ThrottleFirstTests.java b/rxjava-core/src/test/java/rx/ThrottleFirstTests.java index e486e5dd46..b0902f5f1b 100644 --- a/rxjava-core/src/test/java/rx/ThrottleFirstTests.java +++ b/rxjava-core/src/test/java/rx/ThrottleFirstTests.java @@ -22,7 +22,6 @@ import org.junit.Test; import org.mockito.InOrder; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -34,7 +33,7 @@ public void testThrottle() { Observer observer = mock(Observer.class); TestScheduler s = new TestScheduler(); PublishSubject o = PublishSubject.create(); - o.toObservable().throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(new TestObserver(observer)); + o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(observer); // send events with simulated time increments s.advanceTimeTo(0, TimeUnit.MILLISECONDS); diff --git a/rxjava-core/src/test/java/rx/ThrottleLastTests.java b/rxjava-core/src/test/java/rx/ThrottleLastTests.java index 14f18fb5e9..7c1a3c301b 100644 --- a/rxjava-core/src/test/java/rx/ThrottleLastTests.java +++ b/rxjava-core/src/test/java/rx/ThrottleLastTests.java @@ -22,7 +22,6 @@ import org.junit.Test; import org.mockito.InOrder; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -34,7 +33,7 @@ public void testThrottle() { Observer observer = mock(Observer.class); TestScheduler s = new TestScheduler(); PublishSubject o = PublishSubject.create(); - o.toObservable().throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(new TestObserver(observer)); + o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(observer); // send events with simulated time increments s.advanceTimeTo(0, TimeUnit.MILLISECONDS); diff --git a/rxjava-core/src/test/java/rx/ThrottleWithTimeoutTests.java b/rxjava-core/src/test/java/rx/ThrottleWithTimeoutTests.java index 6a7eae2b0a..c023d0b174 100644 --- a/rxjava-core/src/test/java/rx/ThrottleWithTimeoutTests.java +++ b/rxjava-core/src/test/java/rx/ThrottleWithTimeoutTests.java @@ -22,7 +22,6 @@ import org.junit.Test; import org.mockito.InOrder; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -34,7 +33,7 @@ public void testThrottle() { Observer observer = mock(Observer.class); TestScheduler s = new TestScheduler(); PublishSubject o = PublishSubject.create(); - o.toObservable().throttleWithTimeout(500, TimeUnit.MILLISECONDS, s).subscribe(new TestObserver(observer)); + o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s).subscribe(observer); // send events with simulated time increments s.advanceTimeTo(0, TimeUnit.MILLISECONDS); diff --git a/rxjava-core/src/test/java/rx/TimeoutTests.java b/rxjava-core/src/test/java/rx/TimeoutTests.java index f35bcba7f3..2e1bf6412e 100644 --- a/rxjava-core/src/test/java/rx/TimeoutTests.java +++ b/rxjava-core/src/test/java/rx/TimeoutTests.java @@ -26,7 +26,6 @@ import org.mockito.InOrder; import org.mockito.MockitoAnnotations; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -43,14 +42,14 @@ public void setUp() { underlyingSubject = PublishSubject.create(); testScheduler = new TestScheduler(); - withTimeout = underlyingSubject.toObservable().timeout(TIMEOUT, TIME_UNIT, testScheduler); + withTimeout = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler); } @Test public void shouldNotTimeoutIfOnNextWithinTimeout() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = withTimeout.subscribe(new TestObserver(observer)); + Subscription subscription = withTimeout.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); verify(observer).onNext("One"); @@ -63,7 +62,7 @@ public void shouldNotTimeoutIfOnNextWithinTimeout() { public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = withTimeout.subscribe(new TestObserver(observer)); + Subscription subscription = withTimeout.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -78,7 +77,7 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { public void shouldTimeoutIfOnNextNotWithinTimeout() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = withTimeout.subscribe(new TestObserver(observer)); + Subscription subscription = withTimeout.subscribe(observer); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); verify(observer).onError(any(TimeoutException.class)); subscription.unsubscribe(); @@ -88,7 +87,7 @@ public void shouldTimeoutIfOnNextNotWithinTimeout() { public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = withTimeout.subscribe(new TestObserver(observer)); + Subscription subscription = withTimeout.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); verify(observer).onNext("One"); @@ -101,7 +100,7 @@ public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { public void shouldCompleteIfUnderlyingComletes() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = withTimeout.subscribe(new TestObserver(observer)); + Subscription subscription = withTimeout.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onCompleted(); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -114,7 +113,7 @@ public void shouldCompleteIfUnderlyingComletes() { public void shouldErrorIfUnderlyingErrors() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = withTimeout.subscribe(new TestObserver(observer)); + Subscription subscription = withTimeout.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onError(new UnsupportedOperationException()); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -125,11 +124,11 @@ public void shouldErrorIfUnderlyingErrors() { @Test public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { Observable other = Observable.from("a", "b", "c"); - Observable source = underlyingSubject.toObservable().timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = source.subscribe(new TestObserver(observer)); + Subscription subscription = source.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); @@ -148,11 +147,11 @@ public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { @Test public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { Observable other = Observable.from("a", "b", "c"); - Observable source = underlyingSubject.toObservable().timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = source.subscribe(new TestObserver(observer)); + Subscription subscription = source.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); @@ -171,11 +170,11 @@ public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { @Test public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { Observable other = Observable.from("a", "b", "c"); - Observable source = underlyingSubject.toObservable().timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = source.subscribe(new TestObserver(observer)); + Subscription subscription = source.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); @@ -194,11 +193,11 @@ public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { @Test public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() { PublishSubject other = PublishSubject.create(); - Observable source = underlyingSubject.toObservable().timeout(TIMEOUT, TIME_UNIT, other.toObservable(), testScheduler); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = source.subscribe(new TestObserver(observer)); + Subscription subscription = source.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); diff --git a/rxjava-core/src/test/java/rx/observables/BlockingObservableTest.java b/rxjava-core/src/test/java/rx/observables/BlockingObservableTest.java index 2d50027dad..2490f754ee 100644 --- a/rxjava-core/src/test/java/rx/observables/BlockingObservableTest.java +++ b/rxjava-core/src/test/java/rx/observables/BlockingObservableTest.java @@ -28,6 +28,7 @@ import rx.Observable; import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.subscriptions.BooleanSubscription; import rx.subscriptions.Subscriptions; @@ -37,7 +38,7 @@ public class BlockingObservableTest { @Mock - Observer w; + Subscriber w; @Before public void before() { diff --git a/rxjava-core/src/test/java/rx/observers/SafeObserverTest.java b/rxjava-core/src/test/java/rx/observers/SafeObserverTest.java index 0d546024be..4b8d2e42a5 100644 --- a/rxjava-core/src/test/java/rx/observers/SafeObserverTest.java +++ b/rxjava-core/src/test/java/rx/observers/SafeObserverTest.java @@ -21,7 +21,7 @@ import org.junit.Test; -import rx.Observer; +import rx.Subscriber; import rx.subscriptions.Subscriptions; import rx.util.CompositeException; import rx.util.OnErrorNotImplementedException; @@ -46,7 +46,7 @@ public void onNextFailure() { public void onNextFailureSafe() { AtomicReference onError = new AtomicReference(); try { - new SafeObserver(OBSERVER_ONNEXT_FAIL(onError)).onNext("one"); + new SafeSubscriber(OBSERVER_ONNEXT_FAIL(onError)).onNext("one"); assertNotNull(onError.get()); assertTrue(onError.get() instanceof SafeObserverTestException); assertEquals("onNextFail", onError.get().getMessage()); @@ -72,7 +72,7 @@ public void onCompletedFailure() { public void onCompletedFailureSafe() { AtomicReference onError = new AtomicReference(); try { - new SafeObserver(OBSERVER_ONCOMPLETED_FAIL(onError)).onCompleted(); + new SafeSubscriber(OBSERVER_ONCOMPLETED_FAIL(onError)).onCompleted(); assertNotNull(onError.get()); assertTrue(onError.get() instanceof SafeObserverTestException); assertEquals("onCompletedFail", onError.get().getMessage()); @@ -95,7 +95,7 @@ public void onErrorFailure() { @Test public void onErrorFailureSafe() { try { - new SafeObserver(OBSERVER_ONERROR_FAIL()).onError(new SafeObserverTestException("error!")); + new SafeSubscriber(OBSERVER_ONERROR_FAIL()).onError(new SafeObserverTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -119,7 +119,7 @@ public void onErrorFailureSafe() { @Test public void onErrorNotImplementedFailureSafe() { try { - new SafeObserver(OBSERVER_ONERROR_NOTIMPLEMENTED()).onError(new SafeObserverTestException("error!")); + new SafeSubscriber(OBSERVER_ONERROR_NOTIMPLEMENTED()).onError(new SafeObserverTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { assertTrue(e instanceof OnErrorNotImplementedException); @@ -143,7 +143,7 @@ public void onNextOnErrorFailure() { @Test public void onNextOnErrorFailureSafe() { try { - new SafeObserver(OBSERVER_ONNEXT_ONERROR_FAIL()).onNext("one"); + new SafeSubscriber(OBSERVER_ONNEXT_ONERROR_FAIL()).onNext("one"); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -166,7 +166,7 @@ public void onNextOnErrorFailureSafe() { @Test public void onCompleteSuccessWithUnsubscribeFailure() { - Observer o = OBSERVER_SUCCESS(); + Subscriber o = OBSERVER_SUCCESS(); try { o.add(Subscriptions.create(new Action0() { @@ -176,7 +176,7 @@ public void call() { throw new SafeObserverTestException("failure from unsubscribe"); } })); - new SafeObserver(o).onCompleted(); + new SafeSubscriber(o).onCompleted(); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -192,7 +192,7 @@ public void call() { @Test public void onErrorSuccessWithUnsubscribeFailure() { AtomicReference onError = new AtomicReference(); - Observer o = OBSERVER_SUCCESS(onError); + Subscriber o = OBSERVER_SUCCESS(onError); try { o.add(Subscriptions.create(new Action0() { @@ -202,7 +202,7 @@ public void call() { throw new SafeObserverTestException("failure from unsubscribe"); } })); - new SafeObserver(o).onError(new SafeObserverTestException("failed")); + new SafeSubscriber(o).onError(new SafeObserverTestException("failed")); fail("we expect the unsubscribe failure to cause an exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -222,7 +222,7 @@ public void call() { @Test public void onErrorFailureWithUnsubscribeFailure() { - Observer o = OBSERVER_ONERROR_FAIL(); + Subscriber o = OBSERVER_ONERROR_FAIL(); try { o.add(Subscriptions.create(new Action0() { @@ -232,7 +232,7 @@ public void call() { throw new SafeObserverTestException("failure from unsubscribe"); } })); - new SafeObserver(o).onError(new SafeObserverTestException("onError failure")); + new SafeSubscriber(o).onError(new SafeObserverTestException("onError failure")); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -263,7 +263,7 @@ public void call() { @Test public void onErrorNotImplementedFailureWithUnsubscribeFailure() { - Observer o = OBSERVER_ONERROR_NOTIMPLEMENTED(); + Subscriber o = OBSERVER_ONERROR_NOTIMPLEMENTED(); try { o.add(Subscriptions.create(new Action0() { @@ -273,7 +273,7 @@ public void call() { throw new SafeObserverTestException("failure from unsubscribe"); } })); - new SafeObserver(o).onError(new SafeObserverTestException("error!")); + new SafeSubscriber(o).onError(new SafeObserverTestException("error!")); fail("expects exception to be thrown"); } catch (Exception e) { e.printStackTrace(); @@ -298,8 +298,8 @@ public void call() { } } - private static Observer OBSERVER_SUCCESS() { - return new Observer() { + private static Subscriber OBSERVER_SUCCESS() { + return new Subscriber() { @Override public void onCompleted() { @@ -319,8 +319,8 @@ public void onNext(String args) { } - private static Observer OBSERVER_SUCCESS(final AtomicReference onError) { - return new Observer() { + private static Subscriber OBSERVER_SUCCESS(final AtomicReference onError) { + return new Subscriber() { @Override public void onCompleted() { @@ -340,8 +340,8 @@ public void onNext(String args) { } - private static Observer OBSERVER_ONNEXT_FAIL(final AtomicReference onError) { - return new Observer() { + private static Subscriber OBSERVER_ONNEXT_FAIL(final AtomicReference onError) { + return new Subscriber() { @Override public void onCompleted() { @@ -361,8 +361,8 @@ public void onNext(String args) { } - private static Observer OBSERVER_ONNEXT_ONERROR_FAIL() { - return new Observer() { + private static Subscriber OBSERVER_ONNEXT_ONERROR_FAIL() { + return new Subscriber() { @Override public void onCompleted() { @@ -382,8 +382,8 @@ public void onNext(String args) { }; } - private static Observer OBSERVER_ONERROR_FAIL() { - return new Observer() { + private static Subscriber OBSERVER_ONERROR_FAIL() { + return new Subscriber() { @Override public void onCompleted() { @@ -403,8 +403,8 @@ public void onNext(String args) { }; } - private static Observer OBSERVER_ONERROR_NOTIMPLEMENTED() { - return new Observer() { + private static Subscriber OBSERVER_ONERROR_NOTIMPLEMENTED() { + return new Subscriber() { @Override public void onCompleted() { @@ -424,8 +424,8 @@ public void onNext(String args) { }; } - private static Observer OBSERVER_ONCOMPLETED_FAIL(final AtomicReference onError) { - return new Observer() { + private static Subscriber OBSERVER_ONCOMPLETED_FAIL(final AtomicReference onError) { + return new Subscriber() { @Override public void onCompleted() { diff --git a/rxjava-core/src/test/java/rx/observers/SynchronizedObserverTest.java b/rxjava-core/src/test/java/rx/observers/SynchronizedObserverTest.java index 7bd063cb7e..b1bc776ce2 100644 --- a/rxjava-core/src/test/java/rx/observers/SynchronizedObserverTest.java +++ b/rxjava-core/src/test/java/rx/observers/SynchronizedObserverTest.java @@ -34,13 +34,14 @@ import rx.Observable; import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.operators.SafeObservableSubscription; public class SynchronizedObserverTest { @Mock - Observer observer; + Subscriber observer; @Before public void before() { @@ -420,7 +421,7 @@ private static enum TestConcurrencyObserverEvent { onCompleted, onError, onNext } - private static class TestConcurrencyObserver extends Observer { + private static class TestConcurrencyObserver extends Subscriber { /** * used to store the order and number of events received @@ -645,7 +646,7 @@ public void waitToFinish() { } } - private static class BusyObserver extends Observer { + private static class BusyObserver extends Subscriber { volatile boolean onCompleted = false; volatile boolean onError = false; AtomicInteger onNextCount = new AtomicInteger(); diff --git a/rxjava-core/src/test/java/rx/observers/TestObserverTest.java b/rxjava-core/src/test/java/rx/observers/TestObserverTest.java index f2394b670c..70e22d8fb2 100644 --- a/rxjava-core/src/test/java/rx/observers/TestObserverTest.java +++ b/rxjava-core/src/test/java/rx/observers/TestObserverTest.java @@ -77,7 +77,7 @@ public void testAssertNotMatchValue() { public void testAssertTerminalEventNotReceived() { PublishSubject p = PublishSubject.create(); TestObserver o = new TestObserver(); - p.toObservable().subscribe(o); + p.subscribe(o); p.onNext(1); p.onNext(2); diff --git a/rxjava-core/src/test/java/rx/observers/TestSubscriberTest.java b/rxjava-core/src/test/java/rx/observers/TestSubscriberTest.java new file mode 100644 index 0000000000..d3f0830128 --- /dev/null +++ b/rxjava-core/src/test/java/rx/observers/TestSubscriberTest.java @@ -0,0 +1,121 @@ +/** + * Copyright 2014 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package rx.observers; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.util.Arrays; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InOrder; + +import rx.Observable; +import rx.Observer; +import rx.subjects.PublishSubject; + +public class TestSubscriberTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testAssert() { + Observable oi = Observable.from(Arrays.asList(1, 2)); + TestSubscriber o = new TestSubscriber(); + oi.subscribe(o); + + o.assertReceivedOnNext(Arrays.asList(1, 2)); + assertEquals(2, o.getOnNextEvents().size()); + o.assertTerminalEvent(); + } + + @Test + public void testAssertNotMatchCount() { + Observable oi = Observable.from(Arrays.asList(1, 2)); + TestSubscriber o = new TestSubscriber(); + oi.subscribe(o); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Number of items does not match. Provided: 1 Actual: 2"); + + o.assertReceivedOnNext(Arrays.asList(1)); + assertEquals(2, o.getOnNextEvents().size()); + o.assertTerminalEvent(); + } + + @Test + public void testAssertNotMatchValue() { + Observable oi = Observable.from(Arrays.asList(1, 2)); + TestSubscriber o = new TestSubscriber(); + oi.subscribe(o); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Value at index: 1 expected to be [3] but was: [2]"); + + o.assertReceivedOnNext(Arrays.asList(1, 3)); + assertEquals(2, o.getOnNextEvents().size()); + o.assertTerminalEvent(); + } + + @Test + public void testAssertTerminalEventNotReceived() { + PublishSubject p = PublishSubject.create(); + TestSubscriber o = new TestSubscriber(); + p.subscribe(o); + + p.onNext(1); + p.onNext(2); + + thrown.expect(AssertionError.class); + thrown.expectMessage("No terminal events received."); + + o.assertReceivedOnNext(Arrays.asList(1, 2)); + assertEquals(2, o.getOnNextEvents().size()); + o.assertTerminalEvent(); + } + + @Test + public void testWrappingMock() { + Observable oi = Observable.from(Arrays.asList(1, 2)); + @SuppressWarnings("unchecked") + Observer mockObserver = mock(Observer.class); + oi.subscribe(new TestSubscriber(mockObserver)); + + InOrder inOrder = inOrder(mockObserver); + inOrder.verify(mockObserver, times(1)).onNext(1); + inOrder.verify(mockObserver, times(1)).onNext(2); + inOrder.verify(mockObserver, times(1)).onCompleted(); + inOrder.verifyNoMoreInteractions(); + } + + @Test + public void testWrappingMockWhenUnsubscribeInvolved() { + Observable oi = Observable.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); + @SuppressWarnings("unchecked") + Observer mockObserver = mock(Observer.class); + oi.subscribe(new TestSubscriber(mockObserver)); + + InOrder inOrder = inOrder(mockObserver); + inOrder.verify(mockObserver, times(1)).onNext(1); + inOrder.verify(mockObserver, times(1)).onNext(2); + inOrder.verify(mockObserver, times(1)).onCompleted(); + inOrder.verifyNoMoreInteractions(); + } + +} diff --git a/rxjava-core/src/test/java/rx/operators/OperationAllTest.java b/rxjava-core/src/test/java/rx/operators/OperationAllTest.java index 70ce855c0a..2ae2eccd5f 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationAllTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationAllTest.java @@ -22,7 +22,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationAllTest { @@ -38,7 +37,7 @@ public void testAll() { public Boolean call(String s) { return s.length() == 3; } - })).subscribe(new TestObserver(observer)); + })).subscribe(observer); verify(observer).onNext(true); verify(observer).onCompleted(); @@ -56,7 +55,7 @@ public void testNotAll() { public Boolean call(String s) { return s.length() == 3; } - })).subscribe(new TestObserver(observer)); + })).subscribe(observer); verify(observer).onNext(false); verify(observer).onCompleted(); @@ -74,7 +73,7 @@ public void testEmpty() { public Boolean call(String s) { return s.length() == 3; } - })).subscribe(new TestObserver(observer)); + })).subscribe(observer); verify(observer).onNext(true); verify(observer).onCompleted(); @@ -93,7 +92,7 @@ public void testError() { public Boolean call(String s) { return s.length() == 3; } - })).subscribe(new TestObserver(observer)); + })).subscribe(observer); verify(observer).onError(error); verifyNoMoreInteractions(observer); diff --git a/rxjava-core/src/test/java/rx/operators/OperationAmbTest.java b/rxjava-core/src/test/java/rx/operators/OperationAmbTest.java index 6e76ad0a23..4a1fbefb01 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationAmbTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationAmbTest.java @@ -29,7 +29,6 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subscriptions.CompositeSubscription; import rx.util.functions.Action0; @@ -91,7 +90,7 @@ public void testAmb() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - o.subscribe(new TestObserver(observer)); + o.subscribe(observer); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -120,7 +119,7 @@ public void testAmb2() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - o.subscribe(new TestObserver(observer)); + o.subscribe(observer); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -147,7 +146,7 @@ public void testAmb3() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - o.subscribe(new TestObserver(observer)); + o.subscribe(observer); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); InOrder inOrder = inOrder(observer); diff --git a/rxjava-core/src/test/java/rx/operators/OperationAnyTest.java b/rxjava-core/src/test/java/rx/operators/OperationAnyTest.java index fecbf725dc..a22cbb8740 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationAnyTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationAnyTest.java @@ -22,7 +22,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationAnyTest { @@ -34,7 +33,7 @@ public void testAnyWithTwoItems() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(false); verify(observer, times(1)).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -48,7 +47,7 @@ public void testIsEmptyWithTwoItems() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(true); verify(observer, times(1)).onNext(false); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -62,7 +61,7 @@ public void testAnyWithOneItem() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(false); verify(observer, times(1)).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -76,7 +75,7 @@ public void testIsEmptyWithOneItem() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(true); verify(observer, times(1)).onNext(false); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -90,7 +89,7 @@ public void testAnyWithEmpty() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -104,7 +103,7 @@ public void testIsEmptyWithEmpty() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(true); verify(observer, never()).onNext(false); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -125,7 +124,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(false); verify(observer, times(1)).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -146,7 +145,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(false); verify(observer, times(1)).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -167,7 +166,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); @@ -189,7 +188,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); diff --git a/rxjava-core/src/test/java/rx/operators/OperationAverageTest.java b/rxjava-core/src/test/java/rx/operators/OperationAverageTest.java index 5a6852d29e..6587e118e8 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationAverageTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationAverageTest.java @@ -23,7 +23,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.operators.OperationReduceTest.CustomException; import rx.util.functions.Func1; @@ -41,7 +40,7 @@ public class OperationAverageTest { @Test public void testAverageOfAFewInts() throws Throwable { Observable src = Observable.from(1, 2, 3, 4, 6); - average(src).subscribe(new TestObserver(w)); + average(src).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(3); @@ -52,7 +51,7 @@ public void testAverageOfAFewInts() throws Throwable { @Test public void testEmptyAverage() throws Throwable { Observable src = Observable.empty(); - average(src).subscribe(new TestObserver(w)); + average(src).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onError(isA(IllegalArgumentException.class)); @@ -62,7 +61,7 @@ public void testEmptyAverage() throws Throwable { @Test public void testAverageOfAFewLongs() throws Throwable { Observable src = Observable.from(1L, 2L, 3L, 4L, 6L); - averageLongs(src).subscribe(new TestObserver(wl)); + averageLongs(src).subscribe(wl); verify(wl, times(1)).onNext(anyLong()); verify(wl).onNext(3L); @@ -73,7 +72,7 @@ public void testAverageOfAFewLongs() throws Throwable { @Test public void testEmptyAverageLongs() throws Throwable { Observable src = Observable.empty(); - averageLongs(src).subscribe(new TestObserver(wl)); + averageLongs(src).subscribe(wl); verify(wl, never()).onNext(anyLong()); verify(wl, times(1)).onError(isA(IllegalArgumentException.class)); @@ -83,7 +82,7 @@ public void testEmptyAverageLongs() throws Throwable { @Test public void testAverageOfAFewFloats() throws Throwable { Observable src = Observable.from(1.0f, 2.0f); - averageFloats(src).subscribe(new TestObserver(wf)); + averageFloats(src).subscribe(wf); verify(wf, times(1)).onNext(anyFloat()); verify(wf).onNext(1.5f); @@ -94,7 +93,7 @@ public void testAverageOfAFewFloats() throws Throwable { @Test public void testEmptyAverageFloats() throws Throwable { Observable src = Observable.empty(); - averageFloats(src).subscribe(new TestObserver(wf)); + averageFloats(src).subscribe(wf); verify(wf, never()).onNext(anyFloat()); verify(wf, times(1)).onError(isA(IllegalArgumentException.class)); @@ -104,7 +103,7 @@ public void testEmptyAverageFloats() throws Throwable { @Test public void testAverageOfAFewDoubles() throws Throwable { Observable src = Observable.from(1.0d, 2.0d); - averageDoubles(src).subscribe(new TestObserver(wd)); + averageDoubles(src).subscribe(wd); verify(wd, times(1)).onNext(anyDouble()); verify(wd).onNext(1.5d); @@ -115,7 +114,7 @@ public void testAverageOfAFewDoubles() throws Throwable { @Test public void testEmptyAverageDoubles() throws Throwable { Observable src = Observable.empty(); - averageDoubles(src).subscribe(new TestObserver(wd)); + averageDoubles(src).subscribe(wd); verify(wd, never()).onNext(anyDouble()); verify(wd, times(1)).onError(isA(IllegalArgumentException.class)); @@ -146,7 +145,7 @@ public Integer call(String t1) { Observable result = source.averageInteger(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 2); } @@ -163,7 +162,7 @@ public Long call(String t1) { Observable result = source.averageLong(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 2L); } @@ -180,7 +179,7 @@ public Float call(String t1) { Observable result = source.averageFloat(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 2.5f); } @@ -197,7 +196,7 @@ public Double call(String t1) { Observable result = source.averageDouble(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 2.5d); } @@ -214,7 +213,7 @@ public Integer call(String t1) { Observable result = source.averageInteger(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -231,7 +230,7 @@ public Long call(String t1) { Observable result = source.averageLong(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -248,7 +247,7 @@ public Float call(String t1) { Observable result = source.averageFloat(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -265,7 +264,7 @@ public Double call(String t1) { Observable result = source.averageDouble(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -282,7 +281,7 @@ public Integer call(String t1) { Observable result = source.averageInteger(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, CustomException.class); } @@ -299,7 +298,7 @@ public Long call(String t1) { Observable result = source.averageLong(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, CustomException.class); } @@ -316,7 +315,7 @@ public Float call(String t1) { Observable result = source.averageFloat(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, CustomException.class); } @@ -333,7 +332,7 @@ public Double call(String t1) { Observable result = source.averageDouble(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, CustomException.class); } diff --git a/rxjava-core/src/test/java/rx/operators/OperationBufferTest.java b/rxjava-core/src/test/java/rx/operators/OperationBufferTest.java index 8228c89845..1864af8ac8 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationBufferTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationBufferTest.java @@ -34,7 +34,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; import rx.subscriptions.Subscriptions; @@ -66,7 +65,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable> buffered = Observable.create(buffer(source, 3, 3)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); Mockito.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class)); Mockito.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); @@ -88,7 +87,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable> buffered = Observable.create(buffer(source, 3, 1)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two", "three")); @@ -115,7 +114,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable> buffered = Observable.create(buffer(source, 3, 3)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two", "three")); @@ -141,7 +140,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable> buffered = Observable.create(buffer(source, 2, 3)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two")); @@ -167,7 +166,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable> buffered = Observable.create(buffer(source, 100, TimeUnit.MILLISECONDS, 2, scheduler)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); scheduler.advanceTimeTo(100, TimeUnit.MILLISECONDS); @@ -199,7 +198,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable> buffered = Observable.create(buffer(source, 100, TimeUnit.MILLISECONDS, scheduler)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); scheduler.advanceTimeTo(101, TimeUnit.MILLISECONDS); @@ -252,7 +251,7 @@ public Subscription onSubscribe(Observer observer) { }; Observable> buffered = Observable.create(buffer(source, openings, closer)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); @@ -293,7 +292,7 @@ public Subscription onSubscribe(Observer observer) { }; Observable> buffered = Observable.create(buffer(source, closer)); - buffered.subscribe(new TestObserver>(observer)); + buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); @@ -371,7 +370,7 @@ public void testBufferStopsWhenUnsubscribed1() { Observer> o = mock(Observer.class); - Subscription s = source.buffer(100, 200, TimeUnit.MILLISECONDS, scheduler).subscribe(new TestObserver>(o)); + Subscription s = source.buffer(100, 200, TimeUnit.MILLISECONDS, scheduler).subscribe(o); InOrder inOrder = Mockito.inOrder(o); @@ -395,7 +394,7 @@ public void bufferWithBONormal1() { Observer o = mock(Observer.class); InOrder inOrder = Mockito.inOrder(o); - source.toObservable().buffer(boundary.toObservable()).subscribe(new TestObserver(o)); + source.buffer(boundary).subscribe(o); source.onNext(1); source.onNext(2); @@ -431,7 +430,7 @@ public void bufferWithBOEmptyLastViaBoundary() { Observer o = mock(Observer.class); InOrder inOrder = Mockito.inOrder(o); - source.toObservable().buffer(boundary.toObservable()).subscribe(new TestObserver(o)); + source.buffer(boundary).subscribe(o); boundary.onCompleted(); @@ -451,7 +450,7 @@ public void bufferWithBOEmptyLastViaSource() { Observer o = mock(Observer.class); InOrder inOrder = Mockito.inOrder(o); - source.toObservable().buffer(boundary.toObservable()).subscribe(new TestObserver(o)); + source.buffer(boundary).subscribe(o); source.onCompleted(); @@ -471,7 +470,7 @@ public void bufferWithBOEmptyLastViaBoth() { Observer o = mock(Observer.class); InOrder inOrder = Mockito.inOrder(o); - source.toObservable().buffer(boundary.toObservable()).subscribe(new TestObserver(o)); + source.buffer(boundary).subscribe(o); source.onCompleted(); boundary.onCompleted(); @@ -491,7 +490,7 @@ public void bufferWithBOSourceThrows() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.toObservable().buffer(boundary.toObservable()).subscribe(new TestObserver(o)); + source.buffer(boundary).subscribe(o); source.onNext(1); source.onError(new OperationReduceTest.CustomException()); @@ -508,7 +507,7 @@ public void bufferWithBOBoundaryThrows() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.toObservable().buffer(boundary.toObservable()).subscribe(new TestObserver(o)); + source.buffer(boundary).subscribe(o); source.onNext(1); boundary.onError(new OperationReduceTest.CustomException()); diff --git a/rxjava-core/src/test/java/rx/operators/OperationCombineLatestTest.java b/rxjava-core/src/test/java/rx/operators/OperationCombineLatestTest.java index 0f08a8d671..6160f78df5 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationCombineLatestTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationCombineLatestTest.java @@ -28,7 +28,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; import rx.subscriptions.Subscriptions; import rx.util.functions.Func2; @@ -52,7 +51,7 @@ public String call(String v1, String v2) { throw new RuntimeException("I don't work."); } })); - combined.subscribe(new TestObserver(w)); + combined.subscribe(w); w1.observer.onNext("first value of w1"); w2.observer.onNext("first value of w2"); @@ -73,7 +72,7 @@ public void testCombineLatestDifferentLengthObservableSequences1() { TestObservable w3 = new TestObservable(); Observable combineLatestW = Observable.create(combineLatest(Observable.create(w1), Observable.create(w2), Observable.create(w3), getConcat3StringsCombineLatestFunction())); - combineLatestW.subscribe(new TestObserver(w)); + combineLatestW.subscribe(w); /* simulate sending data */ // once for w1 @@ -111,7 +110,7 @@ public void testCombineLatestDifferentLengthObservableSequences2() { TestObservable w3 = new TestObservable(); Observable combineLatestW = Observable.create(combineLatest(Observable.create(w1), Observable.create(w2), Observable.create(w3), getConcat3StringsCombineLatestFunction())); - combineLatestW.subscribe(new TestObserver(w)); + combineLatestW.subscribe(w); /* simulate sending data */ // 4 times for w1 @@ -147,7 +146,7 @@ public void testCombineLatestWithInterleavingSequences() { TestObservable w3 = new TestObservable(); Observable combineLatestW = Observable.create(combineLatest(Observable.create(w1), Observable.create(w2), Observable.create(w3), getConcat3StringsCombineLatestFunction())); - combineLatestW.subscribe(new TestObserver(w)); + combineLatestW.subscribe(w); /* simulate sending data */ w1.observer.onNext("1a"); @@ -186,7 +185,7 @@ public void testCombineLatest2Types() { Observer observer = mock(Observer.class); Observable w = Observable.create(combineLatest(Observable.from("one", "two"), Observable.from(2, 3, 4), combineLatestFunction)); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -205,7 +204,7 @@ public void testCombineLatest3TypesA() { Observer observer = mock(Observer.class); Observable w = Observable.create(combineLatest(Observable.from("one", "two"), Observable.from(2), Observable.from(new int[] { 4, 5, 6 }), combineLatestFunction)); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -222,7 +221,7 @@ public void testCombineLatest3TypesB() { Observer observer = mock(Observer.class); Observable w = Observable.create(combineLatest(Observable.from("one"), Observable.from(2), Observable.from(new int[] { 4, 5, 6 }, new int[] { 7, 8 }), combineLatestFunction)); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -331,11 +330,11 @@ public void combineSimple() { PublishSubject a = PublishSubject.create(); PublishSubject b = PublishSubject.create(); - Observable source = Observable.combineLatest(a.toObservable(), b.toObservable(), or); + Observable source = Observable.combineLatest(a, b, or); Observer observer = mock(Observer.class); - source.subscribe(new TestObserver(observer)); + source.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -376,13 +375,13 @@ public void combineMultipleObservers() { PublishSubject a = PublishSubject.create(); PublishSubject b = PublishSubject.create(); - Observable source = Observable.combineLatest(a.toObservable(), b.toObservable(), or); + Observable source = Observable.combineLatest(a, b, or); Observer observer1 = mock(Observer.class); Observer observer2 = mock(Observer.class); - source.subscribe(new TestObserver(observer1)); - source.subscribe(new TestObserver(observer2)); + source.subscribe(observer1); + source.subscribe(observer2); InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); @@ -432,11 +431,11 @@ public void testFirstNeverProduces() { PublishSubject a = PublishSubject.create(); PublishSubject b = PublishSubject.create(); - Observable source = Observable.combineLatest(a.toObservable(), b.toObservable(), or); + Observable source = Observable.combineLatest(a, b, or); Observer observer = mock(Observer.class); - source.subscribe(new TestObserver(observer)); + source.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -455,11 +454,11 @@ public void testSecondNeverProduces() { PublishSubject a = PublishSubject.create(); PublishSubject b = PublishSubject.create(); - Observable source = Observable.combineLatest(a.toObservable(), b.toObservable(), or); + Observable source = Observable.combineLatest(a, b, or); Observer observer = mock(Observer.class); - source.subscribe(new TestObserver(observer)); + source.subscribe(observer); InOrder inOrder = inOrder(observer); diff --git a/rxjava-core/src/test/java/rx/operators/OperationConcatTest.java b/rxjava-core/src/test/java/rx/operators/OperationConcatTest.java index 2eb052aa61..4a3599fb0e 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationConcatTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationConcatTest.java @@ -33,7 +33,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subscriptions.BooleanSubscription; @@ -52,7 +51,7 @@ public void testConcat() { @SuppressWarnings("unchecked") Observable concat = Observable.create(concat(odds, even)); - concat.subscribe(new TestObserver(observer)); + concat.subscribe(observer); verify(observer, times(7)).onNext(anyString()); } @@ -71,7 +70,7 @@ public void testConcatWithList() { list.add(odds); list.add(even); Observable concat = Observable.create(concat(list)); - concat.subscribe(new TestObserver(observer)); + concat.subscribe(observer); verify(observer, times(7)).onNext(anyString()); } @@ -109,7 +108,7 @@ public void unsubscribe() { }); Observable concat = Observable.create(concat(observableOfObservables)); - concat.subscribe(new TestObserver(observer)); + concat.subscribe(observer); verify(observer, times(7)).onNext(anyString()); } @@ -125,7 +124,7 @@ public void testSimpleAsyncConcat() { TestObservable o1 = new TestObservable("one", "two", "three"); TestObservable o2 = new TestObservable("four", "five", "six"); - Observable.concat(Observable.create(o1), Observable.create(o2)).subscribe(new TestObserver(observer)); + Observable.concat(Observable.create(o1), Observable.create(o2)).subscribe(observer); try { // wait for async observables to complete @@ -205,7 +204,7 @@ public void run() { } }); - Observable.create(concat(observableOfObservables)).subscribe(new TestObserver(observer)); + Observable.create(concat(observableOfObservables)).subscribe(observer); // wait for parent to start parentHasStarted.await(); @@ -267,7 +266,7 @@ public void testBlockedObservableOfObservables() { TestObservable> observableOfObservables = new TestObservable>(callOnce, okToContinue, odds, even); Observable.OnSubscribeFunc concatF = concat(Observable.create(observableOfObservables)); Observable concat = Observable.create(concatF); - concat.subscribe(new TestObserver(observer)); + concat.subscribe(observer); try { //Block main thread to allow observables to serve up o1. callOnce.await(); @@ -309,7 +308,7 @@ public void testConcatConcurrentWithInfinity() { Observable concat = Observable.create(concatF); - concat.take(50).subscribe(new TestObserver(observer)); + concat.take(50).subscribe(observer); //Wait for the thread to start up. try { @@ -360,7 +359,7 @@ public void unsubscribe() { }); Observable concat = Observable.create(concat(observableOfObservables)); - concat.subscribe(new TestObserver(observer)); + concat.subscribe(observer); verify(observer, times(0)).onCompleted(); @@ -403,7 +402,7 @@ public void testConcatUnsubscribe() { try { // Subscribe - Subscription s1 = concat.subscribe(new TestObserver(observer)); + Subscription s1 = concat.subscribe(observer); //Block main thread to allow observable "w1" to complete and observable "w2" to call onNext once. callOnce.await(); // Unsubcribe @@ -446,7 +445,7 @@ public void testConcatUnsubscribeConcurrent() { Observable concat = Observable.create(concatF); - Subscription s1 = concat.subscribe(new TestObserver(observer)); + Subscription s1 = concat.subscribe(observer); try { //Block main thread to allow observable "w1" to complete and observable "w2" to call onNext exactly once. @@ -564,8 +563,8 @@ public void testMultipleObservers() { Observable timer = Observable.interval(500, TimeUnit.MILLISECONDS, s).take(2); Observable o = Observable.concat(timer, timer); - o.subscribe(new TestObserver(o1)); - o.subscribe(new TestObserver(o2)); + o.subscribe(o1); + o.subscribe(o2); InOrder inOrder1 = inOrder(o1); InOrder inOrder2 = inOrder(o2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationDebounceTest.java b/rxjava-core/src/test/java/rx/operators/OperationDebounceTest.java index 5a3af532e1..80b7e0fc5e 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDebounceTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationDebounceTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; import rx.subscriptions.Subscriptions; @@ -61,7 +60,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationDebounce.debounce(source, 400, TimeUnit.MILLISECONDS, scheduler)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); InOrder inOrder = inOrder(observer); @@ -94,7 +93,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationDebounce.debounce(source, 200, TimeUnit.MILLISECONDS, scheduler)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); InOrder inOrder = inOrder(observer); @@ -119,7 +118,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationDebounce.debounce(source, 400, TimeUnit.MILLISECONDS, scheduler)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); InOrder inOrder = inOrder(observer); @@ -170,7 +169,7 @@ public void debounceSelectorNormal1() { @Override public Observable call(Integer t1) { - return debouncer.toObservable(); + return debouncer; } }; @@ -178,7 +177,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().debounce(debounceSel).subscribe(new TestObserver(o)); + source.debounce(debounceSel).subscribe(o); source.onNext(1); debouncer.onNext(1); @@ -214,7 +213,7 @@ public Observable call(Integer t1) { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.toObservable().debounce(debounceSel).subscribe(new TestObserver(o)); + source.debounce(debounceSel).subscribe(o); source.onNext(1); @@ -237,7 +236,7 @@ public Observable call(Integer t1) { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.toObservable().debounce(debounceSel).subscribe(new TestObserver(o)); + source.debounce(debounceSel).subscribe(o); source.onNext(1); diff --git a/rxjava-core/src/test/java/rx/operators/OperationDefaultIfEmptyTest.java b/rxjava-core/src/test/java/rx/operators/OperationDefaultIfEmptyTest.java index 257224f2bd..50c86bde17 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDefaultIfEmptyTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationDefaultIfEmptyTest.java @@ -22,7 +22,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; public class OperationDefaultIfEmptyTest { @@ -34,7 +33,7 @@ public void testDefaultIfEmpty() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(10); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(2); @@ -52,7 +51,7 @@ public void testDefaultIfEmptyWithEmpty() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(10); verify(observer, never()).onError( org.mockito.Matchers.any(Throwable.class)); diff --git a/rxjava-core/src/test/java/rx/operators/OperationDeferTest.java b/rxjava-core/src/test/java/rx/operators/OperationDeferTest.java index be13b3696a..3c01c11ae8 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDeferTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationDeferTest.java @@ -21,7 +21,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func0; public class OperationDeferTest { @@ -41,7 +40,7 @@ public void testDefer() throws Throwable { verifyZeroInteractions(factory); Observer firstObserver = mock(Observer.class); - deferred.subscribe(new TestObserver(firstObserver)); + deferred.subscribe(firstObserver); verify(factory, times(1)).call(); verify(firstObserver, times(1)).onNext("one"); @@ -51,7 +50,7 @@ public void testDefer() throws Throwable { verify(firstObserver, times(1)).onCompleted(); Observer secondObserver = mock(Observer.class); - deferred.subscribe(new TestObserver(secondObserver)); + deferred.subscribe(secondObserver); verify(factory, times(2)).call(); verify(secondObserver, times(0)).onNext("one"); diff --git a/rxjava-core/src/test/java/rx/operators/OperationDelayTest.java b/rxjava-core/src/test/java/rx/operators/OperationDelayTest.java index cd8deaa64d..9b583d96f8 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDelayTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationDelayTest.java @@ -32,7 +32,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; import rx.util.functions.Func0; @@ -56,7 +55,7 @@ public void before() { public void testDelay() { Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); - delayed.subscribe(new TestObserver(observer)); + delayed.subscribe(observer); InOrder inOrder = inOrder(observer); scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS); @@ -96,7 +95,7 @@ public void testDelay() { public void testLongDelay() { Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); Observable delayed = source.delay(5L, TimeUnit.SECONDS, scheduler); - delayed.subscribe(new TestObserver(observer)); + delayed.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -133,7 +132,7 @@ public Long call(Long value) { } }); Observable delayed = source.delay(1L, TimeUnit.SECONDS, scheduler); - delayed.subscribe(new TestObserver(observer)); + delayed.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -159,8 +158,8 @@ public Long call(Long value) { public void testDelayWithMultipleSubscriptions() { Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); - delayed.subscribe(new TestObserver(observer)); - delayed.subscribe(new TestObserver(observer2)); + delayed.subscribe(observer); + delayed.subscribe(observer2); InOrder inOrder = inOrder(observer); InOrder inOrder2 = inOrder(observer2); @@ -205,7 +204,7 @@ public void testDelaySubscription() { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - result.subscribe(new TestObserver(o)); + result.subscribe(o); inOrder.verify(o, never()).onNext(any()); inOrder.verify(o, never()).onCompleted(); @@ -228,7 +227,7 @@ public void testDelaySubscriptionCancelBeforeTime() { Observer o = mock(Observer.class); - Subscription s = result.subscribe(new TestObserver(o)); + Subscription s = result.subscribe(o); s.unsubscribe(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); @@ -250,7 +249,7 @@ public void testDelayWithObservableNormal1() { Func1> delayFunc = new Func1>() { @Override public Observable call(Integer t1) { - return delays.get(t1).toObservable(); + return delays.get(t1); } }; @@ -258,7 +257,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(delayFunc).subscribe(new TestObserver(o)); + source.delay(delayFunc).subscribe(o); for (int i = 0; i < n; i++) { source.onNext(i); @@ -282,14 +281,14 @@ public void testDelayWithObservableSingleSend1() { @Override public Observable call(Integer t1) { - return delay.toObservable(); + return delay; } }; @SuppressWarnings("unchecked") Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(delayFunc).subscribe(new TestObserver(o)); + source.delay(delayFunc).subscribe(o); source.onNext(1); delay.onNext(1); @@ -309,14 +308,14 @@ public void testDelayWithObservableSourceThrows() { @Override public Observable call(Integer t1) { - return delay.toObservable(); + return delay; } }; @SuppressWarnings("unchecked") Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(delayFunc).subscribe(new TestObserver(o)); + source.delay(delayFunc).subscribe(o); source.onNext(1); source.onError(new OperationReduceTest.CustomException()); delay.onNext(1); @@ -342,7 +341,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(delayFunc).subscribe(new TestObserver(o)); + source.delay(delayFunc).subscribe(o); source.onNext(1); inOrder.verify(o).onError(any(OperationReduceTest.CustomException.class)); @@ -360,14 +359,14 @@ public void testDelayWithObservableDelayThrows() { @Override public Observable call(Integer t1) { - return delay.toObservable(); + return delay; } }; @SuppressWarnings("unchecked") Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(delayFunc).subscribe(new TestObserver(o)); + source.delay(delayFunc).subscribe(o); source.onNext(1); delay.onError(new OperationReduceTest.CustomException()); @@ -384,14 +383,14 @@ public void testDelayWithObservableSubscriptionNormal() { Func0> subFunc = new Func0>() { @Override public Observable call() { - return delay.toObservable(); + return delay; } }; Func1> delayFunc = new Func1>() { @Override public Observable call(Integer t1) { - return delay.toObservable(); + return delay; } }; @@ -399,7 +398,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(subFunc, delayFunc).subscribe(new TestObserver(o)); + source.delay(subFunc, delayFunc).subscribe(o); source.onNext(1); delay.onNext(1); @@ -427,7 +426,7 @@ public Observable call() { @Override public Observable call(Integer t1) { - return delay.toObservable(); + return delay; } }; @@ -435,7 +434,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(subFunc, delayFunc).subscribe(new TestObserver(o)); + source.delay(subFunc, delayFunc).subscribe(o); source.onNext(1); delay.onNext(1); @@ -455,14 +454,14 @@ public void testDelayWithObservableSubscriptionThrows() { Func0> subFunc = new Func0>() { @Override public Observable call() { - return delay.toObservable(); + return delay; } }; Func1> delayFunc = new Func1>() { @Override public Observable call(Integer t1) { - return delay.toObservable(); + return delay; } }; @@ -470,7 +469,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(subFunc, delayFunc).subscribe(new TestObserver(o)); + source.delay(subFunc, delayFunc).subscribe(o); source.onNext(1); delay.onError(new OperationReduceTest.CustomException()); @@ -498,7 +497,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(delayFunc).subscribe(new TestObserver(o)); + source.delay(delayFunc).subscribe(o); source.onNext(1); source.onCompleted(); @@ -517,14 +516,14 @@ public void testDelayWithObservableSubscriptionRunCompletion() { Func0> subFunc = new Func0>() { @Override public Observable call() { - return sdelay.toObservable(); + return sdelay; } }; Func1> delayFunc = new Func1>() { @Override public Observable call(Integer t1) { - return delay.toObservable(); + return delay; } }; @@ -532,7 +531,7 @@ public Observable call(Integer t1) { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().delay(subFunc, delayFunc).subscribe(new TestObserver(o)); + source.delay(subFunc, delayFunc).subscribe(o); source.onNext(1); sdelay.onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationDematerializeTest.java b/rxjava-core/src/test/java/rx/operators/OperationDematerializeTest.java index 1ce6729018..147ec2ea1c 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDematerializeTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationDematerializeTest.java @@ -24,7 +24,6 @@ import rx.Notification; import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; public class OperationDematerializeTest { @@ -35,7 +34,7 @@ public void testDematerialize1() { Observable dematerialize = notifications.dematerialize(); Observer observer = mock(Observer.class); - dematerialize.subscribe(new TestObserver(observer)); + dematerialize.subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(2); @@ -51,7 +50,7 @@ public void testDematerialize2() { Observable dematerialize = Observable.create(dematerialize(observable.materialize())); Observer observer = mock(Observer.class); - dematerialize.subscribe(new TestObserver(observer)); + dematerialize.subscribe(observer); verify(observer, times(1)).onError(exception); verify(observer, times(0)).onCompleted(); @@ -66,7 +65,7 @@ public void testDematerialize3() { Observable dematerialize = Observable.create(dematerialize(observable.materialize())); Observer observer = mock(Observer.class); - dematerialize.subscribe(new TestObserver(observer)); + dematerialize.subscribe(observer); verify(observer, times(1)).onError(exception); verify(observer, times(0)).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationDistinctTest.java b/rxjava-core/src/test/java/rx/operators/OperationDistinctTest.java index 29f79ee8c6..d03781df17 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDistinctTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationDistinctTest.java @@ -29,7 +29,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationDistinctTest { @@ -65,7 +64,7 @@ public void before() { @Test public void testDistinctOfNone() { Observable src = Observable.empty(); - Observable.create(distinct(src)).subscribe(new TestObserver(w)); + Observable.create(distinct(src)).subscribe(w); verify(w, never()).onNext(anyString()); verify(w, never()).onError(any(Throwable.class)); @@ -75,7 +74,7 @@ public void testDistinctOfNone() { @Test public void testDistinctOfNoneWithKeySelector() { Observable src = Observable.empty(); - Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION)).subscribe(new TestObserver(w)); + Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION)).subscribe(w); verify(w, never()).onNext(anyString()); verify(w, never()).onError(any(Throwable.class)); @@ -85,7 +84,7 @@ public void testDistinctOfNoneWithKeySelector() { @Test public void testDistinctOfNormalSource() { Observable src = Observable.from("a", "b", "c", "c", "c", "b", "b", "a", "e"); - Observable.create(distinct(src)).subscribe(new TestObserver(w)); + Observable.create(distinct(src)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); @@ -100,7 +99,7 @@ public void testDistinctOfNormalSource() { @Test public void testDistinctOfNormalSourceWithKeySelector() { Observable src = Observable.from("a", "B", "c", "C", "c", "B", "b", "a", "E"); - Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION)).subscribe(new TestObserver(w)); + Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); @@ -115,7 +114,7 @@ public void testDistinctOfNormalSourceWithKeySelector() { @Test public void testDistinctOfNormalSourceWithComparator() { Observable src = Observable.from("1", "12", "123", "aaa", "321", "12", "21", "1", "12345"); - Observable.create(distinct(src, COMPARE_LENGTH)).subscribe(new TestObserver(w)); + Observable.create(distinct(src, COMPARE_LENGTH)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("1"); @@ -130,7 +129,7 @@ public void testDistinctOfNormalSourceWithComparator() { @Test public void testDistinctOfNormalSourceWithKeySelectorAndComparator() { Observable src = Observable.from("a", "x", "ab", "abc", "cba", "de", "x", "a", "abcd"); - Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(new TestObserver(w)); + Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); @@ -145,12 +144,12 @@ public void testDistinctOfNormalSourceWithKeySelectorAndComparator() { @Test public void testDistinctOfNormalSourceWithKeySelectorAndComparatorAndTwoSubscriptions() { Observable src = Observable.from("a", "x", "ab", "abc", "cba", "de", "x", "a", "abcd"); - Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(new TestObserver(w)); + Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); inOrder.verify(w, times(1)).onNext("x"); - Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(new TestObserver(w2)); + Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w2); inOrder.verify(w, times(1)).onNext("abc"); inOrder.verify(w, times(1)).onNext("abcd"); inOrder.verify(w, times(1)).onCompleted(); @@ -170,7 +169,7 @@ public void testDistinctOfNormalSourceWithKeySelectorAndComparatorAndTwoSubscrip @Test public void testDistinctOfSourceWithNulls() { Observable src = Observable.from(null, "a", "a", null, null, "b", null); - Observable.create(distinct(src)).subscribe(new TestObserver(w)); + Observable.create(distinct(src)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(null); @@ -184,7 +183,7 @@ public void testDistinctOfSourceWithNulls() { @Test public void testDistinctOfSourceWithExceptionsFromKeySelector() { Observable src = Observable.from("a", "b", null, "c"); - Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION)).subscribe(new TestObserver(new TestObserver(w))); + Observable.create(distinct(src, TO_UPPER_WITH_EXCEPTION)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); diff --git a/rxjava-core/src/test/java/rx/operators/OperationDistinctUntilChangedTest.java b/rxjava-core/src/test/java/rx/operators/OperationDistinctUntilChangedTest.java index 5ed08ad2a5..e924370f5c 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDistinctUntilChangedTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationDistinctUntilChangedTest.java @@ -29,7 +29,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationDistinctUntilChangedTest { @@ -65,7 +64,7 @@ public void before() { @Test public void testDistinctUntilChangedOfNone() { Observable src = Observable.empty(); - Observable.create(distinctUntilChanged(src)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src)).subscribe(w); verify(w, never()).onNext(anyString()); verify(w, never()).onError(any(Throwable.class)); @@ -75,7 +74,7 @@ public void testDistinctUntilChangedOfNone() { @Test public void testDistinctUntilChangedOfNoneWithKeySelector() { Observable src = Observable.empty(); - Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION)).subscribe(w); verify(w, never()).onNext(anyString()); verify(w, never()).onError(any(Throwable.class)); @@ -85,7 +84,7 @@ public void testDistinctUntilChangedOfNoneWithKeySelector() { @Test public void testDistinctUntilChangedOfNormalSource() { Observable src = Observable.from("a", "b", "c", "c", "c", "b", "b", "a", "e"); - Observable.create(distinctUntilChanged(src)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); @@ -102,7 +101,7 @@ public void testDistinctUntilChangedOfNormalSource() { @Test public void testDistinctUntilChangedOfNormalSourceWithKeySelector() { Observable src = Observable.from("a", "b", "c", "C", "c", "B", "b", "a", "e"); - Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); @@ -119,7 +118,7 @@ public void testDistinctUntilChangedOfNormalSourceWithKeySelector() { @Test public void testDistinctUntilChangedOfSourceWithNulls() { Observable src = Observable.from(null, "a", "a", null, null, "b", null, null); - Observable.create(distinctUntilChanged(src)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(null); @@ -135,7 +134,7 @@ public void testDistinctUntilChangedOfSourceWithNulls() { @Test public void testDistinctUntilChangedOfSourceWithExceptionsFromKeySelector() { Observable src = Observable.from("a", "b", null, "c"); - Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); @@ -148,7 +147,7 @@ public void testDistinctUntilChangedOfSourceWithExceptionsFromKeySelector() { @Test public void testDistinctUntilChangedWithComparator() { Observable src = Observable.from("a", "b", "c", "aa", "bb", "c", "ddd"); - Observable.create(distinctUntilChanged(src, COMPARE_LENGTH)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src, COMPARE_LENGTH)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); inOrder.verify(w, times(1)).onNext("aa"); @@ -162,7 +161,7 @@ public void testDistinctUntilChangedWithComparator() { @Test public void testDistinctUntilChangedWithComparatorAndKeySelector() { Observable src = Observable.from("a", "b", "x", "aa", "bb", "c", "ddd"); - Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); inOrder.verify(w, times(1)).onNext("x"); @@ -176,11 +175,11 @@ public void testDistinctUntilChangedWithComparatorAndKeySelector() { @Test public void testDistinctUntilChangedWithComparatorAndKeySelectorandTwoSubscriptions() { Observable src = Observable.from("a", "b", "x", "aa", "bb", "c", "ddd"); - Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(new TestObserver(w)); + Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); inOrder.verify(w, times(1)).onNext("x"); - Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(new TestObserver(w2)); + Observable.create(distinctUntilChanged(src, TO_UPPER_WITH_EXCEPTION, COMPARE_LENGTH)).subscribe(w2); inOrder.verify(w, times(1)).onNext("c"); inOrder.verify(w, times(1)).onNext("ddd"); inOrder.verify(w, times(1)).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationElementAtTest.java b/rxjava-core/src/test/java/rx/operators/OperationElementAtTest.java index 2b8400d4b9..7728c8791b 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationElementAtTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationElementAtTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; public class OperationElementAtTest { @@ -38,7 +37,7 @@ public void testElementAt() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(1); verify(observer, times(1)).onNext(2); verify(observer, never()).onError( @@ -86,7 +85,7 @@ public void testElementAtOrDefault() throws InterruptedException, @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(1); verify(observer, times(1)).onNext(2); verify(observer, never()).onError(any(Throwable.class)); @@ -102,7 +101,7 @@ public void testElementAtOrDefaultWithIndexOutOfBounds() @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(1); verify(observer, never()).onNext(2); verify(observer, times(1)).onNext(0); diff --git a/rxjava-core/src/test/java/rx/operators/OperationFilterTest.java b/rxjava-core/src/test/java/rx/operators/OperationFilterTest.java index 939fb33757..d27b573d80 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationFilterTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationFilterTest.java @@ -24,7 +24,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationFilterTest { @@ -42,7 +41,7 @@ public Boolean call(String t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, Mockito.never()).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, Mockito.never()).onNext("three"); diff --git a/rxjava-core/src/test/java/rx/operators/OperationFinallyTest.java b/rxjava-core/src/test/java/rx/operators/OperationFinallyTest.java index 98a5365d7c..ce85adcb57 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationFinallyTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationFinallyTest.java @@ -23,7 +23,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Action0; public class OperationFinallyTest { @@ -40,7 +39,7 @@ public void before() { } private void checkActionCalled(Observable input) { - Observable.create(finallyDo(input, aAction0)).subscribe(new TestObserver(observer)); + Observable.create(finallyDo(input, aAction0)).subscribe(observer); verify(aAction0, times(1)).call(); } diff --git a/rxjava-core/src/test/java/rx/operators/OperationFirstOrDefaultTest.java b/rxjava-core/src/test/java/rx/operators/OperationFirstOrDefaultTest.java index fe1e9590dd..b14c285acc 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationFirstOrDefaultTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationFirstOrDefaultTest.java @@ -26,7 +26,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationFirstOrDefaultTest { @@ -49,7 +48,7 @@ public void before() { @Test public void testFirstOrElseOfNone() { Observable src = Observable.empty(); - src.firstOrDefault("default").subscribe(new TestObserver(w)); + src.firstOrDefault("default").subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("default"); @@ -60,7 +59,7 @@ public void testFirstOrElseOfNone() { @Test public void testFirstOrElseOfSome() { Observable src = Observable.from("a", "b", "c"); - src.firstOrDefault("default").subscribe(new TestObserver(w)); + src.firstOrDefault("default").subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("a"); @@ -71,7 +70,7 @@ public void testFirstOrElseOfSome() { @Test public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { Observable src = Observable.from("a", "b", "c"); - src.firstOrDefault("default", IS_D).subscribe(new TestObserver(w)); + src.firstOrDefault("default", IS_D).subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("default"); @@ -82,7 +81,7 @@ public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { @Test public void testFirstOrElseWithPredicateOfSome() { Observable src = Observable.from("a", "b", "c", "d", "e", "f"); - src.firstOrDefault("default", IS_D).subscribe(new TestObserver(w)); + src.firstOrDefault("default", IS_D).subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("d"); @@ -96,7 +95,7 @@ public void testFirst() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -110,7 +109,7 @@ public void testFirstWithOneElement() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -124,7 +123,7 @@ public void testFirstWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -145,7 +144,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -166,7 +165,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -186,7 +185,7 @@ public Boolean call(Integer t1) { }); @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -201,7 +200,7 @@ public void testFirstOrDefault() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -215,7 +214,7 @@ public void testFirstOrDefaultWithOneElement() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -230,7 +229,7 @@ public void testFirstOrDefaultWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -251,7 +250,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -272,7 +271,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -293,7 +292,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationFlatMapTest.java b/rxjava-core/src/test/java/rx/operators/OperationFlatMapTest.java index b48774a78a..bbb6e5d7cf 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationFlatMapTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationFlatMapTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func0; import rx.util.functions.Func1; import rx.util.functions.Func2; @@ -54,7 +53,7 @@ public Integer call(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.from(source).mergeMapIterable(func, resFunc).subscribe(new TestObserver(o)); + Observable.from(source).mergeMapIterable(func, resFunc).subscribe(o); for (Integer s : source) { for (Integer v : list) { @@ -86,7 +85,7 @@ public Integer call(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.from(source).mergeMapIterable(func, resFunc).subscribe(new TestObserver(o)); + Observable.from(source).mergeMapIterable(func, resFunc).subscribe(o); verify(o, never()).onCompleted(); verify(o, never()).onNext(any()); @@ -116,7 +115,7 @@ public Integer call(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.from(source).mergeMapIterable(func, resFunc).subscribe(new TestObserver(o)); + Observable.from(source).mergeMapIterable(func, resFunc).subscribe(o); verify(o, never()).onCompleted(); verify(o, never()).onNext(any()); @@ -144,7 +143,7 @@ public Integer call(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.from(source).mergeMap(func, resFunc).subscribe(new TestObserver(o)); + Observable.from(source).mergeMap(func, resFunc).subscribe(o); verify(o, never()).onCompleted(); verify(o, never()).onNext(any()); @@ -182,7 +181,7 @@ public void testFlatMapTransformsNormal() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.mergeMap(just(onNext), just(onError), just0(onCompleted)).subscribe(new TestObserver(o)); + source.mergeMap(just(onNext), just(onError), just0(onCompleted)).subscribe(o); verify(o, times(3)).onNext(1); verify(o, times(3)).onNext(2); @@ -208,7 +207,7 @@ public void testFlatMapTransformsException() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.mergeMap(just(onNext), just(onError), just0(onCompleted)).subscribe(new TestObserver(o)); + source.mergeMap(just(onNext), just(onError), just0(onCompleted)).subscribe(o); verify(o, times(3)).onNext(1); verify(o, times(3)).onNext(2); @@ -248,7 +247,7 @@ public void testFlatMapTransformsOnNextFuncThrows() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.mergeMap(funcThrow(1, onError), just(onError), just0(onCompleted)).subscribe(new TestObserver(o)); + source.mergeMap(funcThrow(1, onError), just(onError), just0(onCompleted)).subscribe(o); verify(o).onError(any(OperationReduceTest.CustomException.class)); verify(o, never()).onNext(any()); @@ -266,7 +265,7 @@ public void testFlatMapTransformsOnErrorFuncThrows() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.mergeMap(just(onNext), funcThrow((Throwable) null, onError), just0(onCompleted)).subscribe(new TestObserver(o)); + source.mergeMap(just(onNext), funcThrow((Throwable) null, onError), just0(onCompleted)).subscribe(o); verify(o).onError(any(OperationReduceTest.CustomException.class)); verify(o, never()).onNext(any()); @@ -284,7 +283,7 @@ public void testFlatMapTransformsOnCompletedFuncThrows() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.mergeMap(just(onNext), just(onError), funcThrow0(onCompleted)).subscribe(new TestObserver(o)); + source.mergeMap(just(onNext), just(onError), funcThrow0(onCompleted)).subscribe(o); verify(o).onError(any(OperationReduceTest.CustomException.class)); verify(o, never()).onNext(any()); @@ -302,7 +301,7 @@ public void testFlatMapTransformsMergeException() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.mergeMap(just(onNext), just(onError), funcThrow0(onCompleted)).subscribe(new TestObserver(o)); + source.mergeMap(just(onNext), just(onError), funcThrow0(onCompleted)).subscribe(o); verify(o).onError(any(OperationReduceTest.CustomException.class)); verify(o, never()).onNext(any()); diff --git a/rxjava-core/src/test/java/rx/operators/OperationGroupByUntilTest.java b/rxjava-core/src/test/java/rx/operators/OperationGroupByUntilTest.java index 50d8577b51..d926a10bf2 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationGroupByUntilTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationGroupByUntilTest.java @@ -33,8 +33,8 @@ import rx.Observable; import rx.Observer; +import rx.Subscriber; import rx.observables.GroupedObservable; -import rx.observers.TestObserver; import rx.util.functions.Action1; import rx.util.functions.Func1; import rx.util.functions.Functions; @@ -131,7 +131,7 @@ public String call(String t1) { keysel, valuesel, duration).map(getkey); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext("foo"); @@ -247,7 +247,7 @@ public Integer call(GroupedObservable t1) { identity, dbl, duration).map(getkey); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onNext(0); verify(observer, times(1)).onError(any(Throwable.class)); @@ -278,7 +278,7 @@ public void call(GroupedObservable t1) { } }); - inner.get().subscribe(new TestObserver(observer)); + inner.get().subscribe(observer); verify(observer, times(1)).onCompleted(); verify(observer, never()).onError(any(Throwable.class)); @@ -295,7 +295,7 @@ public void innerEscapeError() { Observable> m = source.groupByUntil(identity, dbl, duration); - m.subscribe(new Observer>() { + m.subscribe(new Subscriber>() { @Override public void onNext(GroupedObservable t1) { inner.set(t1); diff --git a/rxjava-core/src/test/java/rx/operators/OperationGroupJoinTest.java b/rxjava-core/src/test/java/rx/operators/OperationGroupJoinTest.java index 87cc849b8c..a347cbf587 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationGroupJoinTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationGroupJoinTest.java @@ -27,7 +27,7 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; +import rx.Subscriber; import rx.subjects.PublishSubject; import rx.util.functions.Action1; import rx.util.functions.Func1; @@ -85,11 +85,11 @@ public void behaveAsJoin() { PublishSubject source1 = PublishSubject.create(); PublishSubject source2 = PublishSubject.create(); - Observable m = Observable.merge(source1.toObservable().groupJoin(source2.toObservable(), + Observable m = Observable.merge(source1.groupJoin(source2, just(Observable.never()), just(Observable.never()), add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source1.onNext(2); @@ -172,7 +172,7 @@ public PPF call(Person t1, Observable t2) { }); q.subscribe( - new Observer() { + new Subscriber() { @Override public void onNext(final PPF ppf) { ppf.fruits.where(new Func1() { @@ -214,11 +214,11 @@ public void leftThrows() { PublishSubject source1 = PublishSubject.create(); PublishSubject source2 = PublishSubject.create(); - Observable> m = source1.toObservable().groupJoin(source2.toObservable(), + Observable> m = source1.groupJoin(source2, just(Observable.never()), just(Observable.never()), add2); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source2.onNext(1); source1.onError(new RuntimeException("Forced failure")); @@ -233,11 +233,11 @@ public void rightThrows() { PublishSubject source1 = PublishSubject.create(); PublishSubject source2 = PublishSubject.create(); - Observable> m = source1.toObservable().groupJoin(source2.toObservable(), + Observable> m = source1.groupJoin(source2, just(Observable.never()), just(Observable.never()), add2); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source2.onError(new RuntimeException("Forced failure")); @@ -254,10 +254,10 @@ public void leftDurationThrows() { Observable duration1 = Observable. error(new RuntimeException("Forced failure")); - Observable> m = source1.toObservable().groupJoin(source2.toObservable(), + Observable> m = source1.groupJoin(source2, just(duration1), just(Observable.never()), add2); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); @@ -273,10 +273,10 @@ public void rightDurationThrows() { Observable duration1 = Observable. error(new RuntimeException("Forced failure")); - Observable> m = source1.toObservable().groupJoin(source2.toObservable(), + Observable> m = source1.groupJoin(source2, just(Observable.never()), just(duration1), add2); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source2.onNext(1); @@ -297,10 +297,10 @@ public Observable call(Integer t1) { } }; - Observable> m = source1.toObservable().groupJoin(source2.toObservable(), + Observable> m = source1.groupJoin(source2, fail, just(Observable.never()), add2); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); @@ -321,10 +321,10 @@ public Observable call(Integer t1) { } }; - Observable> m = source1.toObservable().groupJoin(source2.toObservable(), + Observable> m = source1.groupJoin(source2, just(Observable.never()), fail, add2); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source2.onNext(1); @@ -345,10 +345,10 @@ public Integer call(Integer t1, Observable t2) { } }; - Observable m = source1.toObservable().groupJoin(source2.toObservable(), + Observable m = source1.groupJoin(source2, just(Observable.never()), just(Observable.never()), fail); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source2.onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationIntervalTest.java b/rxjava-core/src/test/java/rx/operators/OperationIntervalTest.java index 02d1206afd..0240796f18 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationIntervalTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationIntervalTest.java @@ -28,7 +28,6 @@ import rx.Observer; import rx.Subscription; import rx.observables.ConnectableObservable; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; public class OperationIntervalTest { @@ -49,7 +48,7 @@ public void before() { @Test public void testInterval() { Observable w = Observable.create(OperationInterval.interval(1, TimeUnit.SECONDS, scheduler)); - Subscription sub = w.subscribe(new TestObserver(observer)); + Subscription sub = w.subscribe(observer); verify(observer, never()).onNext(0L); verify(observer, never()).onCompleted(); @@ -74,8 +73,8 @@ public void testInterval() { @Test public void testWithMultipleSubscribersStartingAtSameTime() { Observable w = Observable.create(OperationInterval.interval(1, TimeUnit.SECONDS, scheduler)); - Subscription sub1 = w.subscribe(new TestObserver(observer)); - Subscription sub2 = w.subscribe(new TestObserver(observer2)); + Subscription sub1 = w.subscribe(observer); + Subscription sub2 = w.subscribe(observer2); verify(observer, never()).onNext(anyLong()); verify(observer2, never()).onNext(anyLong()); @@ -113,12 +112,12 @@ public void testWithMultipleSubscribersStartingAtSameTime() { @Test public void testWithMultipleStaggeredSubscribers() { Observable w = Observable.create(OperationInterval.interval(1, TimeUnit.SECONDS, scheduler)); - Subscription sub1 = w.subscribe(new TestObserver(observer)); + Subscription sub1 = w.subscribe(observer); verify(observer, never()).onNext(anyLong()); scheduler.advanceTimeTo(2, TimeUnit.SECONDS); - Subscription sub2 = w.subscribe(new TestObserver(observer2)); + Subscription sub2 = w.subscribe(observer2); InOrder inOrder1 = inOrder(observer); inOrder1.verify(observer, times(1)).onNext(0L); @@ -153,13 +152,13 @@ public void testWithMultipleStaggeredSubscribers() { @Test public void testWithMultipleStaggeredSubscribersAndPublish() { ConnectableObservable w = Observable.create(OperationInterval.interval(1, TimeUnit.SECONDS, scheduler)).publish(); - Subscription sub1 = w.subscribe(new TestObserver(observer)); + Subscription sub1 = w.subscribe(observer); w.connect(); verify(observer, never()).onNext(anyLong()); scheduler.advanceTimeTo(2, TimeUnit.SECONDS); - Subscription sub2 = w.subscribe(new TestObserver(observer2)); + Subscription sub2 = w.subscribe(observer2); InOrder inOrder1 = inOrder(observer); inOrder1.verify(observer, times(1)).onNext(0L); diff --git a/rxjava-core/src/test/java/rx/operators/OperationJoinTest.java b/rxjava-core/src/test/java/rx/operators/OperationJoinTest.java index cb19fad008..fd88df8370 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationJoinTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationJoinTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; import rx.util.functions.Func1; import rx.util.functions.Func2; @@ -60,11 +59,11 @@ public void normal1() { PublishSubject source1 = PublishSubject.create(); PublishSubject source2 = PublishSubject.create(); - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(Observable.never()), just(Observable.never()), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source1.onNext(2); @@ -98,10 +97,10 @@ public void normal1WithDuration() { PublishSubject duration1 = PublishSubject.create(); - Observable m = source1.toObservable().join(source2.toObservable(), - just(duration1.toObservable()), + Observable m = source1.join(source2, + just(duration1), just(Observable.never()), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source1.onNext(2); @@ -130,11 +129,11 @@ public void normal2() { PublishSubject source1 = PublishSubject.create(); PublishSubject source2 = PublishSubject.create(); - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(Observable.never()), just(Observable.never()), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source1.onNext(2); @@ -162,11 +161,11 @@ public void leftThrows() { PublishSubject source1 = PublishSubject.create(); PublishSubject source2 = PublishSubject.create(); - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(Observable.never()), just(Observable.never()), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source2.onNext(1); source1.onError(new RuntimeException("Forced failure")); @@ -181,11 +180,11 @@ public void rightThrows() { PublishSubject source1 = PublishSubject.create(); PublishSubject source2 = PublishSubject.create(); - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(Observable.never()), just(Observable.never()), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source2.onError(new RuntimeException("Forced failure")); @@ -202,10 +201,10 @@ public void leftDurationThrows() { Observable duration1 = Observable. error(new RuntimeException("Forced failure")); - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(duration1), just(Observable.never()), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); @@ -221,10 +220,10 @@ public void rightDurationThrows() { Observable duration1 = Observable. error(new RuntimeException("Forced failure")); - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(Observable.never()), just(duration1), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source2.onNext(1); @@ -245,10 +244,10 @@ public Observable call(Integer t1) { } }; - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, fail, just(Observable.never()), add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); @@ -269,10 +268,10 @@ public Observable call(Integer t1) { } }; - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(Observable.never()), fail, add); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source2.onNext(1); @@ -293,10 +292,10 @@ public Integer call(Integer t1, Integer t2) { } }; - Observable m = source1.toObservable().join(source2.toObservable(), + Observable m = source1.join(source2, just(Observable.never()), just(Observable.never()), fail); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source1.onNext(1); source2.onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationJoinsTest.java b/rxjava-core/src/test/java/rx/operators/OperationJoinsTest.java index e09f7a6bd7..8906e6cf62 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationJoinsTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationJoinsTest.java @@ -21,7 +21,6 @@ import java.util.Arrays; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.InOrder; import org.mockito.Mock; @@ -30,7 +29,7 @@ import rx.Observable; import rx.Observer; import rx.joins.Plan0; -import rx.observers.TestObserver; +import rx.observers.TestSubscriber; import rx.subjects.PublishSubject; import rx.util.functions.Func1; import rx.util.functions.Func2; @@ -108,7 +107,7 @@ public void and2() { Observable m = Observable.when(some.and(some).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onNext(2); @@ -123,7 +122,7 @@ public void and2Error1() { Observable m = Observable.when(error.and(some).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -138,7 +137,7 @@ public void and2Error2() { Observable m = Observable.when(some.and(error).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -151,7 +150,7 @@ public void and3() { Observable m = Observable.when(some.and(some).and(some).then(add3)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onNext(3); @@ -166,7 +165,7 @@ public void and3Error1() { Observable m = Observable.when(error.and(some).and(some).then(add3)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -181,7 +180,7 @@ public void and3Error2() { Observable m = Observable.when(some.and(error).and(some).then(add3)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -196,7 +195,7 @@ public void and3Error3() { Observable m = Observable.when(some.and(some).and(error).then(add3)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -229,7 +228,7 @@ public void then1() { Observable some = Observable.just(1); Observable m = Observable.when(some.then(Functions. identity())); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onNext(1); @@ -241,7 +240,7 @@ public void then1Error() { Observable some = Observable.error(new RuntimeException("Forced failure")); Observable m = Observable.when(some.then(Functions. identity())); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -253,7 +252,7 @@ public void then1Throws() { Observable some = Observable.just(1); Observable m = Observable.when(some.then(func1Throw)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -265,7 +264,7 @@ public void then2Throws() { Observable some = Observable.just(1); Observable m = Observable.when(some.and(some).then(func2Throw)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -277,7 +276,7 @@ public void then3Throws() { Observable some = Observable.just(1); Observable m = Observable.when(some.and(some).and(some).then(func3Throw)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -300,7 +299,7 @@ public void whenMultipleSymmetric() { Observable source2 = Observable.from(4, 5, 6); Observable m = Observable.when(source1.and(source2).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onNext(1 + 4); @@ -315,7 +314,7 @@ public void whenMultipleAsymSymmetric() { Observable source2 = Observable.from(4, 5); Observable m = Observable.when(source1.and(source2).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onNext(1 + 4); @@ -329,7 +328,7 @@ public void whenEmptyEmpty() { Observable source2 = Observable.empty(); Observable m = Observable.when(source1.and(source2).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -342,7 +341,7 @@ public void whenNeverNever() { Observable source2 = Observable.never(); Observable m = Observable.when(source1.and(source2).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -355,7 +354,7 @@ public void whenThrowNonEmpty() { Observable source2 = Observable.error(new RuntimeException("Forced failure")); Observable m = Observable.when(source1.and(source2).then(add2)); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onNext(any(Integer.class)); @@ -369,12 +368,12 @@ public void whenComplicated() { PublishSubject zs = PublishSubject.create(); Observable m = Observable.when( - xs.toObservable().and(ys.toObservable()).then(add2), // 1+4=5, 2+5=7, 3+6=9 - xs.toObservable().and(zs.toObservable()).then(mul2), // 1*7=7, 2*8=16, 3*9=27 - ys.toObservable().and(zs.toObservable()).then(sub2) // 4-7=-3, 5-8=-3, 6-9=-3 + xs.and(ys).then(add2), // 1+4=5, 2+5=7, 3+6=9 + xs.and(zs).then(mul2), // 1*7=7, 2*8=16, 3*9=27 + ys.and(zs).then(sub2) // 4-7=-3, 5-8=-3, 6-9=-3 ); - TestObserver to = new TestObserver(observer); + TestSubscriber to = new TestSubscriber(observer); m.subscribe(to); xs.onNext(1); // t == 210, xs[1], ys[], zs[] diff --git a/rxjava-core/src/test/java/rx/operators/OperationLastTest.java b/rxjava-core/src/test/java/rx/operators/OperationLastTest.java index c834d298c0..960d4a58e8 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationLastTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationLastTest.java @@ -24,7 +24,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationLastTest { @@ -59,7 +58,7 @@ public void testLast() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(3); @@ -73,7 +72,7 @@ public void testLastWithOneElement() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -87,7 +86,7 @@ public void testLastWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -108,7 +107,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(6); @@ -129,7 +128,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -149,7 +148,7 @@ public Boolean call(Integer t1) { }); @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -164,7 +163,7 @@ public void testLastOrDefault() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(3); @@ -178,7 +177,7 @@ public void testLastOrDefaultWithOneElement() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -193,7 +192,7 @@ public void testLastOrDefaultWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -214,7 +213,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(6); @@ -235,7 +234,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -256,7 +255,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationLatestTest.java b/rxjava-core/src/test/java/rx/operators/OperationLatestTest.java index f2b0e44c18..87cd7fdc23 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationLatestTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationLatestTest.java @@ -143,7 +143,7 @@ public void testNextThrows() { @Test(timeout = 1000) public void testFasterSource() { PublishSubject source = PublishSubject.create(); - BlockingObservable blocker = source.toObservable().toBlockingObservable(); + BlockingObservable blocker = source.toBlockingObservable(); Iterable iter = blocker.latest(); Iterator it = iter.iterator(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationMaterializeTest.java b/rxjava-core/src/test/java/rx/operators/OperationMaterializeTest.java index 6ef223ae3b..f00e6015a9 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationMaterializeTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationMaterializeTest.java @@ -27,6 +27,7 @@ import rx.Notification; import rx.Observable; import rx.Observer; +import rx.Subscriber; import rx.Subscription; public class OperationMaterializeTest { @@ -93,7 +94,7 @@ public void testMultipleSubscribes() throws InterruptedException, ExecutionExcep assertEquals(3, m.toList().toBlockingObservable().toFuture().get().size()); } - private static class TestObserver extends Observer> { + private static class TestObserver extends Subscriber> { boolean onCompleted = false; boolean onError = false; diff --git a/rxjava-core/src/test/java/rx/operators/OperationMergeDelayErrorTest.java b/rxjava-core/src/test/java/rx/operators/OperationMergeDelayErrorTest.java index 61d1a13435..9ff81f6181 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationMergeDelayErrorTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationMergeDelayErrorTest.java @@ -31,7 +31,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.util.CompositeException; public class OperationMergeDelayErrorTest { @@ -51,7 +50,7 @@ public void testErrorDelayed1() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(o1, o2)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); verify(stringObserver, never()).onCompleted(); @@ -72,7 +71,7 @@ public void testErrorDelayed2() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(o1, o2, o3, o4)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); verify(stringObserver, never()).onCompleted(); @@ -96,7 +95,7 @@ public void testErrorDelayed3() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(o1, o2, o3, o4)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); verify(stringObserver, never()).onCompleted(); @@ -120,7 +119,7 @@ public void testErrorDelayed4() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(o1, o2, o3, o4)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); verify(stringObserver, never()).onCompleted(); @@ -145,7 +144,7 @@ public void testErrorDelayed4WithThreading() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(Observable.create(o1), Observable.create(o2), Observable.create(o3), Observable.create(o4))); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); try { o1.t.join(); @@ -176,7 +175,7 @@ public void testCompositeErrorDelayed1() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(o1, o2)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(CompositeException.class)); verify(stringObserver, never()).onCompleted(); @@ -238,7 +237,7 @@ public void unsubscribe() { }); Observable m = Observable.create(mergeDelayError(observableOfObservables)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(1)).onCompleted(); @@ -252,7 +251,7 @@ public void testMergeArray() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(o1, o2)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(2)).onNext("hello"); @@ -268,7 +267,7 @@ public void testMergeList() { listOfObservables.add(o2); Observable m = Observable.create(mergeDelayError(listOfObservables)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(1)).onCompleted(); @@ -282,7 +281,7 @@ public void testUnSubscribe() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(Observable.create(tA), Observable.create(tB))); - Subscription s = m.subscribe(new TestObserver(stringObserver)); + Subscription s = m.subscribe(stringObserver); tA.sendOnNext("Aone"); tB.sendOnNext("Bone"); @@ -309,7 +308,7 @@ public void testMergeArrayWithThreading() { @SuppressWarnings("unchecked") Observable m = Observable.create(mergeDelayError(Observable.create(o1), Observable.create(o2))); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); try { o1.t.join(); @@ -494,7 +493,7 @@ public void unsubscribe() { } } - private static class CaptureObserver extends Observer { + private static class CaptureObserver implements Observer { volatile Throwable e; @Override diff --git a/rxjava-core/src/test/java/rx/operators/OperationMinMaxTest.java b/rxjava-core/src/test/java/rx/operators/OperationMinMaxTest.java index c1ca704bc9..a4ee85d550 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationMinMaxTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationMinMaxTest.java @@ -29,7 +29,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationMinMaxTest { @@ -40,7 +39,7 @@ public void testMin() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); inOrder.verify(observer, times(1)).onCompleted(); @@ -54,7 +53,7 @@ public void testMinWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( isA(IllegalArgumentException.class)); @@ -74,7 +73,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(4); inOrder.verify(observer, times(1)).onCompleted(); @@ -94,7 +93,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( isA(IllegalArgumentException.class)); @@ -115,7 +114,7 @@ public Integer call(String t1) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(Arrays.asList("2", "4", "6")); inOrder.verify(observer, times(1)).onCompleted(); @@ -135,7 +134,7 @@ public Integer call(String t1) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(new ArrayList()); inOrder.verify(observer, times(1)).onCompleted(); @@ -161,7 +160,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(Arrays.asList("1", "3", "5")); inOrder.verify(observer, times(1)).onCompleted(); @@ -186,7 +185,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(new ArrayList()); inOrder.verify(observer, times(1)).onCompleted(); @@ -200,7 +199,7 @@ public void testMax() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(4); inOrder.verify(observer, times(1)).onCompleted(); @@ -214,7 +213,7 @@ public void testMaxWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( isA(IllegalArgumentException.class)); @@ -234,7 +233,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); inOrder.verify(observer, times(1)).onCompleted(); @@ -254,7 +253,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( isA(IllegalArgumentException.class)); @@ -275,7 +274,7 @@ public Integer call(String t1) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(Arrays.asList("1", "3", "5")); inOrder.verify(observer, times(1)).onCompleted(); @@ -295,7 +294,7 @@ public Integer call(String t1) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(new ArrayList()); inOrder.verify(observer, times(1)).onCompleted(); @@ -321,7 +320,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(Arrays.asList("2", "4", "6")); inOrder.verify(observer, times(1)).onCompleted(); @@ -346,7 +345,7 @@ public int compare(Integer o1, Integer o2) { @SuppressWarnings("unchecked") Observer> observer = (Observer>) mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(new ArrayList()); inOrder.verify(observer, times(1)).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationMostRecentTest.java b/rxjava-core/src/test/java/rx/operators/OperationMostRecentTest.java index 81a589d336..c9de7064f9 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationMostRecentTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationMostRecentTest.java @@ -36,7 +36,7 @@ public class OperationMostRecentTest { public void testMostRecent() { Subject s = PublishSubject.create(); - Iterator it = mostRecent(s.toObservable(), "default").iterator(); + Iterator it = mostRecent(s, "default").iterator(); assertTrue(it.hasNext()); assertEquals("default", it.next()); @@ -61,7 +61,7 @@ public void testMostRecent() { public void testMostRecentWithException() { Subject s = PublishSubject.create(); - Iterator it = mostRecent(s.toObservable(), "default").iterator(); + Iterator it = mostRecent(s, "default").iterator(); assertTrue(it.hasNext()); assertEquals("default", it.next()); diff --git a/rxjava-core/src/test/java/rx/operators/OperationMulticastTest.java b/rxjava-core/src/test/java/rx/operators/OperationMulticastTest.java index 0918ab9c1e..bd1450f2f9 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationMulticastTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationMulticastTest.java @@ -22,7 +22,6 @@ import rx.Observer; import rx.Subscription; import rx.observables.ConnectableObservable; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; import rx.subjects.Subject; @@ -32,12 +31,12 @@ public class OperationMulticastTest { public void testMulticast() { Subject source = PublishSubject.create(); - ConnectableObservable multicasted = OperationMulticast.multicast(source.toObservable(), + ConnectableObservable multicasted = OperationMulticast.multicast(source, PublishSubject. create()); @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - multicasted.subscribe(new TestObserver(observer)); + multicasted.subscribe(observer); source.onNext("one"); source.onNext("two"); @@ -60,12 +59,12 @@ public void testMulticast() { public void testMulticastConnectTwice() { Subject source = PublishSubject.create(); - ConnectableObservable multicasted = OperationMulticast.multicast(source.toObservable(), + ConnectableObservable multicasted = OperationMulticast.multicast(source, PublishSubject. create()); @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - multicasted.subscribe(new TestObserver(observer)); + multicasted.subscribe(observer); source.onNext("one"); @@ -85,12 +84,12 @@ public void testMulticastConnectTwice() { public void testMulticastDisconnect() { Subject source = PublishSubject.create(); - ConnectableObservable multicasted = OperationMulticast.multicast(source.toObservable(), + ConnectableObservable multicasted = OperationMulticast.multicast(source, PublishSubject. create()); @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - multicasted.subscribe(new TestObserver(observer)); + multicasted.subscribe(observer); source.onNext("one"); diff --git a/rxjava-core/src/test/java/rx/operators/OperationNextTest.java b/rxjava-core/src/test/java/rx/operators/OperationNextTest.java index f1ec636d1c..5630507c92 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationNextTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationNextTest.java @@ -70,7 +70,7 @@ public void run() { @Test public void testNext() { Subject obs = PublishSubject.create(); - Iterator it = next(obs.toObservable()).iterator(); + Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); assertEquals("one", it.next()); @@ -99,7 +99,7 @@ public void testNext() { @Test public void testNextWithError() { Subject obs = PublishSubject.create(); - Iterator it = next(obs.toObservable()).iterator(); + Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); assertEquals("one", it.next()); @@ -138,7 +138,7 @@ public void testNextWithEmpty() { @Test public void testOnError() throws Throwable { Subject obs = PublishSubject.create(); - Iterator it = next(obs.toObservable()).iterator(); + Iterator it = next(obs).iterator(); obs.onError(new TestException()); try { @@ -154,7 +154,7 @@ public void testOnError() throws Throwable { @Test public void testOnErrorInNewThread() { Subject obs = PublishSubject.create(); - Iterator it = next(obs.toObservable()).iterator(); + Iterator it = next(obs).iterator(); fireOnErrorInNewThread(obs); @@ -185,7 +185,7 @@ private void assertErrorAfterObservableFail(Iterator it) { @Test public void testNextWithOnlyUsingNextMethod() { Subject obs = PublishSubject.create(); - Iterator it = next(obs.toObservable()).iterator(); + Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertEquals("one", it.next()); @@ -203,7 +203,7 @@ public void testNextWithOnlyUsingNextMethod() { @Test public void testNextWithCallingHasNextMultipleTimes() { Subject obs = PublishSubject.create(); - Iterator it = next(obs.toObservable()).iterator(); + Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); assertTrue(it.hasNext()); diff --git a/rxjava-core/src/test/java/rx/operators/OperationObserveOnTest.java b/rxjava-core/src/test/java/rx/operators/OperationObserveOnTest.java index 66671bfb0e..0e3a892599 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationObserveOnTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationObserveOnTest.java @@ -31,7 +31,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.schedulers.Schedulers; import rx.schedulers.TestScheduler; import rx.util.functions.Action0; @@ -47,7 +46,7 @@ public class OperationObserveOnTest { @SuppressWarnings("unchecked") public void testObserveOn() { Observer observer = mock(Observer.class); - Observable.create(observeOn(Observable.from(1, 2, 3), Schedulers.immediate())).subscribe(new TestObserver(observer)); + Observable.create(observeOn(Observable.from(1, 2, 3), Schedulers.immediate())).subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(2); @@ -74,7 +73,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable { } }).when(observer).onCompleted(); - obs.observeOn(Schedulers.computation()).subscribe(new TestObserver(observer)); + obs.observeOn(Schedulers.computation()).subscribe(observer); if (!completedLatch.await(1000, TimeUnit.MILLISECONDS)) { fail("timed out waiting"); @@ -130,7 +129,7 @@ public void call() { completedLatch.countDown(); } - }).subscribe(new TestObserver(observer)); + }).subscribe(observer); if (!completedLatch.await(1000, TimeUnit.MILLISECONDS)) { fail("timed out waiting"); @@ -156,8 +155,8 @@ public void observeOnTheSameSchedulerTwice() { InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); - o2.subscribe(new TestObserver(observer1)); - o2.subscribe(new TestObserver(observer2)); + o2.subscribe(observer1); + o2.subscribe(observer2); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); @@ -194,8 +193,8 @@ public void observeSameOnMultipleSchedulers() { InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); - o1.subscribe(new TestObserver(observer1)); - o2.subscribe(new TestObserver(observer2)); + o1.subscribe(observer1); + o2.subscribe(observer2); scheduler1.advanceTimeBy(1, TimeUnit.SECONDS); scheduler2.advanceTimeBy(1, TimeUnit.SECONDS); diff --git a/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaFunctionTest.java b/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaFunctionTest.java index a2de0808b0..1ce4f16821 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaFunctionTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaFunctionTest.java @@ -28,7 +28,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.subscriptions.Subscriptions; import rx.util.functions.Func1; @@ -60,7 +59,7 @@ public Observable call(Throwable t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -90,7 +89,7 @@ public Observable call(Throwable t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { w.t.join(); @@ -127,7 +126,7 @@ public Observable call(Throwable t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { w.t.join(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaObservableTest.java b/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaObservableTest.java index b9599cc70c..8951edc836 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaObservableTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationOnErrorResumeNextViaObservableTest.java @@ -26,7 +26,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationOnErrorResumeNextViaObservableTest { @@ -42,7 +41,7 @@ public void testResumeNext() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); @@ -83,7 +82,7 @@ public String call(String s) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationOnErrorReturnTest.java b/rxjava-core/src/test/java/rx/operators/OperationOnErrorReturnTest.java index 9495495c93..11813fac81 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationOnErrorReturnTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationOnErrorReturnTest.java @@ -28,7 +28,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationOnErrorReturnTest { @@ -52,7 +51,7 @@ public String call(Throwable e) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); @@ -89,7 +88,7 @@ public String call(Throwable e) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationOnExceptionResumeNextViaObservableTest.java b/rxjava-core/src/test/java/rx/operators/OperationOnExceptionResumeNextViaObservableTest.java index 094954133b..e15a1eabfb 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationOnExceptionResumeNextViaObservableTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationOnExceptionResumeNextViaObservableTest.java @@ -26,7 +26,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationOnExceptionResumeNextViaObservableTest { @@ -42,7 +41,7 @@ public void testResumeNextWithException() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); @@ -71,7 +70,7 @@ public void testResumeNextWithRuntimeException() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); @@ -100,7 +99,7 @@ public void testThrowablePassesThru() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); @@ -129,7 +128,7 @@ public void testErrorPassesThru() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { f.t.join(); @@ -171,7 +170,7 @@ public String call(String s) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); try { // if the thread gets started (which it shouldn't if it's working correctly) diff --git a/rxjava-core/src/test/java/rx/operators/OperationParallelMergeTest.java b/rxjava-core/src/test/java/rx/operators/OperationParallelMergeTest.java index 0ad7d23edf..84aa301aa3 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationParallelMergeTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationParallelMergeTest.java @@ -38,7 +38,7 @@ public void testParallelMerge() { PublishSubject p3 = PublishSubject. create(); PublishSubject p4 = PublishSubject. create(); - Observable> fourStreams = Observable.> from(p1.toObservable(), p2.toObservable(), p3.toObservable(), p4.toObservable()); + Observable> fourStreams = Observable.> from(p1, p2, p3, p4); Observable> twoStreams = OperationParallelMerge.parallelMerge(fourStreams, 2); Observable> threeStreams = OperationParallelMerge.parallelMerge(fourStreams, 3); diff --git a/rxjava-core/src/test/java/rx/operators/OperationReduceTest.java b/rxjava-core/src/test/java/rx/operators/OperationReduceTest.java index 878c1ee964..adbce40da7 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationReduceTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationReduceTest.java @@ -26,7 +26,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; import rx.util.functions.Func2; import rx.util.functions.Functions; @@ -52,7 +51,7 @@ public void testAggregateAsIntSum() { Observable result = Observable.from(1, 2, 3, 4, 5).reduce(0, sum).map(Functions. identity()); - result.subscribe(new TestObserver(observer)); + result.subscribe(observer); verify(observer).onNext(1 + 2 + 3 + 4 + 5); verify(observer).onCompleted(); @@ -68,7 +67,7 @@ public void testAggregateAsIntSumSourceThrows() { Observable. error(new CustomException())) .reduce(0, sum).map(Functions. identity()); - result.subscribe(new TestObserver(observer)); + result.subscribe(observer); verify(observer, never()).onNext(any()); verify(observer, never()).onCompleted(); @@ -87,7 +86,7 @@ public Integer call(Integer t1, Integer t2) { Observable result = Observable.from(1, 2, 3, 4, 5) .reduce(0, sumErr).map(Functions. identity()); - result.subscribe(new TestObserver(observer)); + result.subscribe(observer); verify(observer, never()).onNext(any()); verify(observer, never()).onCompleted(); @@ -108,7 +107,7 @@ public Integer call(Integer t1) { Observable result = Observable.from(1, 2, 3, 4, 5) .reduce(0, sum).map(error); - result.subscribe(new TestObserver(observer)); + result.subscribe(observer); verify(observer, never()).onNext(any()); verify(observer, never()).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationReplayTest.java b/rxjava-core/src/test/java/rx/operators/OperationReplayTest.java index d615b57f30..e3fd042202 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationReplayTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationReplayTest.java @@ -28,7 +28,6 @@ import rx.Observable; import rx.Observer; import rx.observables.ConnectableObservable; -import rx.observers.TestObserver; import rx.operators.OperationReplay.VirtualBoundedList; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -91,14 +90,14 @@ public void testReadAfter() { public void testBufferedReplay() { PublishSubject source = PublishSubject.create(); - ConnectableObservable co = source.toObservable().replay(3); + ConnectableObservable co = source.replay(3); co.connect(); { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); source.onNext(1); source.onNext(2); @@ -121,7 +120,7 @@ public void testBufferedReplay() { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); inOrder.verify(observer1, times(1)).onNext(2); inOrder.verify(observer1, times(1)).onNext(3); @@ -138,14 +137,14 @@ public void testWindowedReplay() { PublishSubject source = PublishSubject.create(); - ConnectableObservable co = source.toObservable().replay(100, TimeUnit.MILLISECONDS, scheduler); + ConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); source.onNext(1); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); @@ -169,7 +168,7 @@ public void testWindowedReplay() { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); inOrder.verify(observer1, times(1)).onNext(3); inOrder.verify(observer1, times(1)).onCompleted(); @@ -200,13 +199,13 @@ public Observable call(Observable t1) { PublishSubject source = PublishSubject.create(); - Observable co = source.toObservable().replay(selector); + Observable co = source.replay(selector); { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); source.onNext(1); source.onNext(2); @@ -229,7 +228,7 @@ public Observable call(Observable t1) { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); inOrder.verify(observer1, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); @@ -262,13 +261,13 @@ public Observable call(Observable t1) { PublishSubject source = PublishSubject.create(); - Observable co = source.toObservable().replay(selector, 3); + Observable co = source.replay(selector, 3); { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); source.onNext(1); source.onNext(2); @@ -291,7 +290,7 @@ public Observable call(Observable t1) { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); inOrder.verify(observer1, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); @@ -324,13 +323,13 @@ public Observable call(Observable t1) { PublishSubject source = PublishSubject.create(); - Observable co = source.toObservable().replay(selector, 100, TimeUnit.MILLISECONDS, scheduler); + Observable co = source.replay(selector, 100, TimeUnit.MILLISECONDS, scheduler); { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); source.onNext(1); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); @@ -354,7 +353,7 @@ public Observable call(Observable t1) { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); inOrder.verify(observer1, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); @@ -366,14 +365,14 @@ public Observable call(Observable t1) { public void testBufferedReplayError() { PublishSubject source = PublishSubject.create(); - ConnectableObservable co = source.toObservable().replay(3); + ConnectableObservable co = source.replay(3); co.connect(); { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); source.onNext(1); source.onNext(2); @@ -397,7 +396,7 @@ public void testBufferedReplayError() { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); inOrder.verify(observer1, times(1)).onNext(2); inOrder.verify(observer1, times(1)).onNext(3); @@ -414,14 +413,14 @@ public void testWindowedReplayError() { PublishSubject source = PublishSubject.create(); - ConnectableObservable co = source.toObservable().replay(100, TimeUnit.MILLISECONDS, scheduler); + ConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); source.onNext(1); scheduler.advanceTimeBy(60, TimeUnit.MILLISECONDS); @@ -445,7 +444,7 @@ public void testWindowedReplayError() { Observer observer1 = mock(Observer.class); InOrder inOrder = inOrder(observer1); - co.subscribe(new TestObserver(observer1)); + co.subscribe(observer1); inOrder.verify(observer1, times(1)).onNext(3); inOrder.verify(observer1, times(1)).onError(any(RuntimeException.class)); diff --git a/rxjava-core/src/test/java/rx/operators/OperationRetryTest.java b/rxjava-core/src/test/java/rx/operators/OperationRetryTest.java index 82de24328d..f49c2ac572 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationRetryTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationRetryTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.subscriptions.Subscriptions; public class OperationRetryTest { @@ -37,7 +36,7 @@ public void testOriginFails() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); Observable origin = Observable.create(new FuncWithErrors(2)); - origin.subscribe(new TestObserver(observer)); + origin.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext("beginningEveryTime"); @@ -53,7 +52,7 @@ public void testRetryFail() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); - Observable.create(retry(origin, NUM_RETRIES)).subscribe(new TestObserver(observer)); + Observable.create(retry(origin, NUM_RETRIES)).subscribe(observer); InOrder inOrder = inOrder(observer); // should show 2 attempts (first time fail, second time (1st retry) fail) @@ -73,7 +72,7 @@ public void testRetrySuccess() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); - Observable.create(retry(origin, NUM_RETRIES)).subscribe(new TestObserver(observer)); + Observable.create(retry(origin, NUM_RETRIES)).subscribe(observer); InOrder inOrder = inOrder(observer); // should show 3 attempts @@ -93,7 +92,7 @@ public void testInfiniteRetry() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); - Observable.create(retry(origin)).subscribe(new TestObserver(observer)); + Observable.create(retry(origin)).subscribe(observer); InOrder inOrder = inOrder(observer); // should show 3 attempts diff --git a/rxjava-core/src/test/java/rx/operators/OperationSampleTest.java b/rxjava-core/src/test/java/rx/operators/OperationSampleTest.java index 7db155154f..461add8421 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSampleTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSampleTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; import rx.subscriptions.Subscriptions; @@ -76,7 +75,7 @@ public void call() { }); Observable sampled = Observable.create(OperationSample.sample(source, 400L, TimeUnit.MILLISECONDS, scheduler)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -115,8 +114,8 @@ public void sampleWithSamplerNormal() { PublishSubject source = PublishSubject.create(); PublishSubject sampler = PublishSubject.create(); - Observable m = source.toObservable().sample(sampler.toObservable()); - m.subscribe(new TestObserver(observer2)); + Observable m = source.sample(sampler); + m.subscribe(observer2); source.onNext(1); source.onNext(2); @@ -141,8 +140,8 @@ public void sampleWithSamplerNoDuplicates() { PublishSubject source = PublishSubject.create(); PublishSubject sampler = PublishSubject.create(); - Observable m = source.toObservable().sample(sampler.toObservable()); - m.subscribe(new TestObserver(observer2)); + Observable m = source.sample(sampler); + m.subscribe(observer2); source.onNext(1); source.onNext(2); @@ -171,8 +170,8 @@ public void sampleWithSamplerTerminatingEarly() { PublishSubject source = PublishSubject.create(); PublishSubject sampler = PublishSubject.create(); - Observable m = source.toObservable().sample(sampler.toObservable()); - m.subscribe(new TestObserver(observer2)); + Observable m = source.sample(sampler); + m.subscribe(observer2); source.onNext(1); source.onNext(2); @@ -195,8 +194,8 @@ public void sampleWithSamplerEmitAndTerminate() { PublishSubject source = PublishSubject.create(); PublishSubject sampler = PublishSubject.create(); - Observable m = source.toObservable().sample(sampler.toObservable()); - m.subscribe(new TestObserver(observer2)); + Observable m = source.sample(sampler); + m.subscribe(observer2); source.onNext(1); source.onNext(2); @@ -220,8 +219,8 @@ public void sampleWithSamplerEmptySource() { PublishSubject source = PublishSubject.create(); PublishSubject sampler = PublishSubject.create(); - Observable m = source.toObservable().sample(sampler.toObservable()); - m.subscribe(new TestObserver(observer2)); + Observable m = source.sample(sampler); + m.subscribe(observer2); source.onCompleted(); sampler.onNext(1); @@ -237,8 +236,8 @@ public void sampleWithSamplerSourceThrows() { PublishSubject source = PublishSubject.create(); PublishSubject sampler = PublishSubject.create(); - Observable m = source.toObservable().sample(sampler.toObservable()); - m.subscribe(new TestObserver(observer2)); + Observable m = source.sample(sampler); + m.subscribe(observer2); source.onNext(1); source.onError(new RuntimeException("Forced failure!")); @@ -255,8 +254,8 @@ public void sampleWithSamplerThrows() { PublishSubject source = PublishSubject.create(); PublishSubject sampler = PublishSubject.create(); - Observable m = source.toObservable().sample(sampler.toObservable()); - m.subscribe(new TestObserver(observer2)); + Observable m = source.sample(sampler); + m.subscribe(observer2); source.onNext(1); sampler.onNext(1); diff --git a/rxjava-core/src/test/java/rx/operators/OperationScanTest.java b/rxjava-core/src/test/java/rx/operators/OperationScanTest.java index 844d2aef37..47a3274e52 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationScanTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationScanTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func2; public class OperationScanTest { @@ -50,7 +49,7 @@ public String call(String s, Integer n) { } })); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onNext(""); @@ -77,7 +76,7 @@ public Integer call(Integer t1, Integer t2) { } })); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, never()).onNext(0); @@ -104,7 +103,7 @@ public Integer call(Integer t1, Integer t2) { } })); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, never()).onNext(0); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSequenceEqualTests.java b/rxjava-core/src/test/java/rx/operators/OperationSequenceEqualTests.java index fb45525a0b..23a589c4a2 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSequenceEqualTests.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSequenceEqualTests.java @@ -23,7 +23,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func2; public class OperationSequenceEqualTests { @@ -133,7 +132,7 @@ public Boolean call(String t1, String t2) { private void verifyResult(Observable observable, boolean result) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(result); @@ -144,7 +143,7 @@ private void verifyResult(Observable observable, boolean result) { private void verifyError(Observable observable) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(isA(TestException.class)); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSingleTest.java b/rxjava-core/src/test/java/rx/operators/OperationSingleTest.java index af1bb980ea..78cd08b1be 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSingleTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSingleTest.java @@ -23,7 +23,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationSingleTest { @@ -34,7 +33,7 @@ public void testSingle() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -48,7 +47,7 @@ public void testSingleWithTooManyElements() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -62,7 +61,7 @@ public void testSingleWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -83,7 +82,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -104,7 +103,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -124,7 +123,7 @@ public Boolean call(Integer t1) { }); @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -138,7 +137,7 @@ public void testSingleOrDefault() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -153,7 +152,7 @@ public void testSingleOrDefaultWithTooManyElements() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -168,7 +167,7 @@ public void testSingleOrDefaultWithEmpty() { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); @@ -189,7 +188,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); @@ -210,7 +209,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError( @@ -231,7 +230,7 @@ public Boolean call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = (Observer) mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSkipLastTest.java b/rxjava-core/src/test/java/rx/operators/OperationSkipLastTest.java index 66b3bb476b..59026c99df 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSkipLastTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSkipLastTest.java @@ -26,9 +26,8 @@ import rx.Observable; import rx.Observer; -import rx.schedulers.TestScheduler; -import rx.observers.TestObserver; import rx.operators.OperationSkipTest.CustomException; +import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; public class OperationSkipLastTest { @@ -40,7 +39,7 @@ public void testSkipLastEmpty() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(any(String.class)); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -54,7 +53,7 @@ public void testSkipLast1() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); InOrder inOrder = inOrder(observer); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); inOrder.verify(observer, never()).onNext("two"); inOrder.verify(observer, never()).onNext("three"); verify(observer, times(1)).onNext("one"); @@ -69,7 +68,7 @@ public void testSkipLast2() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(any(String.class)); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -82,7 +81,7 @@ public void testSkipLastWithZeroCount() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, never()).onError(any(Throwable.class)); @@ -96,7 +95,7 @@ public void testSkipLastWithNull() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext(null); verify(observer, never()).onNext("two"); @@ -111,7 +110,7 @@ public void testSkipLastWithNegativeCount() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, never()).onNext(any(String.class)); verify(observer, times(1)).onError( any(IndexOutOfBoundsException.class)); @@ -124,11 +123,11 @@ public void testSkipLastTimed() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().skipLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); @@ -162,11 +161,11 @@ public void testSkipLastTimedErrorBeforeTime() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().skipLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); @@ -187,11 +186,11 @@ public void testSkipLastTimedCompleteBeforeTime() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().skipLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSkipTest.java b/rxjava-core/src/test/java/rx/operators/OperationSkipTest.java index 05d3d73e24..5999e07fee 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSkipTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSkipTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; import rx.schedulers.TestScheduler; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; public class OperationSkipTest { @@ -39,7 +38,7 @@ public void testSkip1() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - skip.subscribe(new TestObserver(observer)); + skip.subscribe(observer); verify(observer, never()).onNext("one"); verify(observer, never()).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -54,7 +53,7 @@ public void testSkip2() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - skip.subscribe(new TestObserver(observer)); + skip.subscribe(observer); verify(observer, never()).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -68,11 +67,11 @@ public void testSkipTimed() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); @@ -105,11 +104,11 @@ public void testSkipTimedFinishBeforeTime() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); @@ -135,11 +134,11 @@ public void testSkipTimedErrorBeforeTime() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); @@ -162,11 +161,11 @@ public void testSkipTimedErrorAfterTime() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSkipUntilTest.java b/rxjava-core/src/test/java/rx/operators/OperationSkipUntilTest.java index 114fc4ba06..6d5b187dbd 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSkipUntilTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSkipUntilTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; public class OperationSkipUntilTest { @@ -42,8 +41,8 @@ public void normal1() { PublishSubject source = PublishSubject.create(); PublishSubject other = PublishSubject.create(); - Observable m = source.toObservable().skipUntil(other.toObservable()); - m.subscribe(new TestObserver(observer)); + Observable m = source.skipUntil(other); + m.subscribe(observer); source.onNext(0); source.onNext(1); @@ -66,9 +65,9 @@ public void normal1() { public void otherNeverFires() { PublishSubject source = PublishSubject.create(); - Observable m = source.toObservable().skipUntil(Observable.never()); + Observable m = source.skipUntil(Observable.never()); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); source.onNext(0); source.onNext(1); @@ -86,9 +85,9 @@ public void otherNeverFires() { public void otherEmpty() { PublishSubject source = PublishSubject.create(); - Observable m = source.toObservable().skipUntil(Observable.empty()); + Observable m = source.skipUntil(Observable.empty()); - m.subscribe(new TestObserver(observer)); + m.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, never()).onNext(any()); @@ -100,8 +99,8 @@ public void otherFiresAndCompletes() { PublishSubject source = PublishSubject.create(); PublishSubject other = PublishSubject.create(); - Observable m = source.toObservable().skipUntil(other.toObservable()); - m.subscribe(new TestObserver(observer)); + Observable m = source.skipUntil(other); + m.subscribe(observer); source.onNext(0); source.onNext(1); @@ -126,8 +125,8 @@ public void sourceThrows() { PublishSubject source = PublishSubject.create(); PublishSubject other = PublishSubject.create(); - Observable m = source.toObservable().skipUntil(other.toObservable()); - m.subscribe(new TestObserver(observer)); + Observable m = source.skipUntil(other); + m.subscribe(observer); source.onNext(0); source.onNext(1); @@ -148,8 +147,8 @@ public void otherThrowsImmediately() { PublishSubject source = PublishSubject.create(); PublishSubject other = PublishSubject.create(); - Observable m = source.toObservable().skipUntil(other.toObservable()); - m.subscribe(new TestObserver(observer)); + Observable m = source.skipUntil(other); + m.subscribe(observer); source.onNext(0); source.onNext(1); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSkipWhileTest.java b/rxjava-core/src/test/java/rx/operators/OperationSkipWhileTest.java index 0ac909f2ea..b2800015cf 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSkipWhileTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSkipWhileTest.java @@ -24,7 +24,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; import rx.util.functions.Func2; @@ -52,7 +51,7 @@ public Boolean call(Integer value, Integer index) { @Test public void testSkipWithIndex() { Observable src = Observable.from(1, 2, 3, 4, 5); - Observable.create(skipWhileWithIndex(src, INDEX_LESS_THAN_THREE)).subscribe(new TestObserver(w)); + Observable.create(skipWhileWithIndex(src, INDEX_LESS_THAN_THREE)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(4); @@ -64,7 +63,7 @@ public void testSkipWithIndex() { @Test public void testSkipEmpty() { Observable src = Observable.empty(); - Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(new TestObserver(w)); + Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onCompleted(); @@ -73,7 +72,7 @@ public void testSkipEmpty() { @Test public void testSkipEverything() { Observable src = Observable.from(1, 2, 3, 4, 3, 2, 1); - Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(new TestObserver(w)); + Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onCompleted(); @@ -82,7 +81,7 @@ public void testSkipEverything() { @Test public void testSkipNothing() { Observable src = Observable.from(5, 3, 1); - Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(new TestObserver(w)); + Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(5); @@ -95,7 +94,7 @@ public void testSkipNothing() { @Test public void testSkipSome() { Observable src = Observable.from(1, 2, 3, 4, 5, 3, 1, 5); - Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(new TestObserver(w)); + Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(5); @@ -109,7 +108,7 @@ public void testSkipSome() { @Test public void testSkipError() { Observable src = Observable.from(1, 2, 42, 5, 3, 1); - Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(new TestObserver(w)); + Observable.create(skipWhile(src, LESS_THAN_FIVE)).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, never()).onNext(anyInt()); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSubscribeOnTest.java b/rxjava-core/src/test/java/rx/operators/OperationSubscribeOnTest.java index a980de5b47..da78c8644a 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSubscribeOnTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSubscribeOnTest.java @@ -25,7 +25,6 @@ import rx.Observer; import rx.Scheduler; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.Schedulers; import rx.test.OperatorTester; import rx.util.functions.Action0; @@ -41,7 +40,7 @@ public void testSubscribeOn() { Scheduler scheduler = spy(OperatorTester.forwardingScheduler(Schedulers.immediate())); Observer observer = mock(Observer.class); - Subscription subscription = Observable.create(subscribeOn(w, scheduler)).subscribe(new TestObserver(observer)); + Subscription subscription = Observable.create(subscribeOn(w, scheduler)).subscribe(observer); verify(scheduler, times(1)).schedule(isNull(), any(Func2.class)); subscription.unsubscribe(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSumTest.java b/rxjava-core/src/test/java/rx/operators/OperationSumTest.java index 7cb8f77ee4..478158eb21 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSumTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSumTest.java @@ -23,7 +23,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func1; public class OperationSumTest { @@ -40,7 +39,7 @@ public class OperationSumTest { @Test public void testSumOfAFewInts() throws Throwable { Observable src = Observable.from(1, 2, 3, 4, 5); - sum(src).subscribe(new TestObserver(w)); + sum(src).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(15); @@ -51,7 +50,7 @@ public void testSumOfAFewInts() throws Throwable { @Test public void testEmptySum() throws Throwable { Observable src = Observable.empty(); - sum(src).subscribe(new TestObserver(w)); + sum(src).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(0); @@ -62,7 +61,7 @@ public void testEmptySum() throws Throwable { @Test public void testSumOfAFewLongs() throws Throwable { Observable src = Observable.from(1L, 2L, 3L, 4L, 5L); - sumLongs(src).subscribe(new TestObserver(wl)); + sumLongs(src).subscribe(wl); verify(wl, times(1)).onNext(anyLong()); verify(wl).onNext(15L); @@ -73,7 +72,7 @@ public void testSumOfAFewLongs() throws Throwable { @Test public void testEmptySumLongs() throws Throwable { Observable src = Observable.empty(); - sumLongs(src).subscribe(new TestObserver(wl)); + sumLongs(src).subscribe(wl); verify(wl, times(1)).onNext(anyLong()); verify(wl).onNext(0L); @@ -84,7 +83,7 @@ public void testEmptySumLongs() throws Throwable { @Test public void testSumOfAFewFloats() throws Throwable { Observable src = Observable.from(1.0f); - sumFloats(src).subscribe(new TestObserver(wf)); + sumFloats(src).subscribe(wf); verify(wf, times(1)).onNext(anyFloat()); verify(wf).onNext(1.0f); @@ -95,7 +94,7 @@ public void testSumOfAFewFloats() throws Throwable { @Test public void testEmptySumFloats() throws Throwable { Observable src = Observable.empty(); - sumFloats(src).subscribe(new TestObserver(wf)); + sumFloats(src).subscribe(wf); verify(wf, times(1)).onNext(anyFloat()); verify(wf).onNext(0.0f); @@ -106,7 +105,7 @@ public void testEmptySumFloats() throws Throwable { @Test public void testSumOfAFewDoubles() throws Throwable { Observable src = Observable.from(0.0d, 1.0d, 0.5d); - sumDoubles(src).subscribe(new TestObserver(wd)); + sumDoubles(src).subscribe(wd); verify(wd, times(1)).onNext(anyDouble()); verify(wd).onNext(1.5d); @@ -117,7 +116,7 @@ public void testSumOfAFewDoubles() throws Throwable { @Test public void testEmptySumDoubles() throws Throwable { Observable src = Observable.empty(); - sumDoubles(src).subscribe(new TestObserver(wd)); + sumDoubles(src).subscribe(wd); verify(wd, times(1)).onNext(anyDouble()); verify(wd).onNext(0.0d); @@ -149,7 +148,7 @@ public Integer call(String t1) { Observable result = source.sumInteger(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 10); } @@ -166,7 +165,7 @@ public Long call(String t1) { Observable result = source.sumLong(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 10L); } @@ -183,7 +182,7 @@ public Float call(String t1) { Observable result = source.sumFloat(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 10f); } @@ -200,7 +199,7 @@ public Double call(String t1) { Observable result = source.sumDouble(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testValue(o, 10d); } @@ -217,7 +216,7 @@ public Integer call(String t1) { Observable result = source.sumInteger(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -234,7 +233,7 @@ public Long call(String t1) { Observable result = source.sumLong(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -251,7 +250,7 @@ public Float call(String t1) { Observable result = source.sumFloat(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -268,7 +267,7 @@ public Double call(String t1) { Observable result = source.sumDouble(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, IllegalArgumentException.class); } @@ -285,7 +284,7 @@ public Integer call(String t1) { Observable result = source.sumInteger(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, OperationReduceTest.CustomException.class); } @@ -302,7 +301,7 @@ public Long call(String t1) { Observable result = source.sumLong(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, OperationReduceTest.CustomException.class); } @@ -319,7 +318,7 @@ public Float call(String t1) { Observable result = source.sumFloat(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, OperationReduceTest.CustomException.class); } @@ -336,7 +335,7 @@ public Double call(String t1) { Observable result = source.sumDouble(length); Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); testThrows(o, OperationReduceTest.CustomException.class); } diff --git a/rxjava-core/src/test/java/rx/operators/OperationSwitchTest.java b/rxjava-core/src/test/java/rx/operators/OperationSwitchTest.java index 05c7fc94f6..818dbbf27b 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSwitchTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSwitchTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subscriptions.Subscriptions; import rx.util.functions.Action0; @@ -65,7 +64,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationSwitch.switchDo(source)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -105,7 +104,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationSwitch.switchDo(source)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -151,7 +150,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationSwitch.switchDo(source)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -211,7 +210,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationSwitch.switchDo(source)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -276,7 +275,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationSwitch.switchDo(source)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -331,7 +330,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationSwitch.switchDo(source)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -415,7 +414,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationSwitch.switchDo(source)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS); diff --git a/rxjava-core/src/test/java/rx/operators/OperationSynchronizeTest.java b/rxjava-core/src/test/java/rx/operators/OperationSynchronizeTest.java index 425857637d..7d796b5b89 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationSynchronizeTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationSynchronizeTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; public class OperationSynchronizeTest { @@ -39,12 +38,13 @@ public void testOnCompletedAfterUnSubscribe() { @SuppressWarnings("unchecked") Observer w = mock(Observer.class); - Subscription ws = st.subscribe(new TestObserver(w)); + Subscription ws = st.subscribe(w); System.out.println("ws: " + ws); t.sendOnNext("one"); ws.unsubscribe(); + System.out.println("send onCompleted"); t.sendOnCompleted(); verify(w, times(1)).onNext("one"); @@ -61,7 +61,7 @@ public void testOnNextAfterUnSubscribe() { @SuppressWarnings("unchecked") Observer w = mock(Observer.class); - Subscription ws = st.subscribe(new TestObserver(w)); + Subscription ws = st.subscribe(w); t.sendOnNext("one"); ws.unsubscribe(); @@ -81,7 +81,7 @@ public void testOnErrorAfterUnSubscribe() { @SuppressWarnings("unchecked") Observer w = mock(Observer.class); - Subscription ws = st.subscribe(new TestObserver(w)); + Subscription ws = st.subscribe(w); t.sendOnNext("one"); ws.unsubscribe(); @@ -102,7 +102,7 @@ public void testOnNextAfterOnError() { @SuppressWarnings("unchecked") Observer w = mock(Observer.class); @SuppressWarnings("unused") - Subscription ws = st.subscribe(new TestObserver(w)); + Subscription ws = st.subscribe(w); t.sendOnNext("one"); t.sendOnError(new RuntimeException("bad")); @@ -124,7 +124,7 @@ public void testOnCompletedAfterOnError() { @SuppressWarnings("unchecked") Observer w = mock(Observer.class); @SuppressWarnings("unused") - Subscription ws = st.subscribe(new TestObserver(w)); + Subscription ws = st.subscribe(w); t.sendOnNext("one"); t.sendOnError(new RuntimeException("bad")); @@ -146,7 +146,7 @@ public void testOnNextAfterOnCompleted() { @SuppressWarnings("unchecked") Observer w = mock(Observer.class); @SuppressWarnings("unused") - Subscription ws = st.subscribe(new TestObserver(w)); + Subscription ws = st.subscribe(w); t.sendOnNext("one"); t.sendOnCompleted(); @@ -169,7 +169,7 @@ public void testOnErrorAfterOnCompleted() { @SuppressWarnings("unchecked") Observer w = mock(Observer.class); @SuppressWarnings("unused") - Subscription ws = st.subscribe(new TestObserver(w)); + Subscription ws = st.subscribe(w); t.sendOnNext("one"); t.sendOnCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationTakeLastTest.java b/rxjava-core/src/test/java/rx/operators/OperationTakeLastTest.java index 014847ecb4..0751213269 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationTakeLastTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationTakeLastTest.java @@ -26,7 +26,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -39,7 +38,7 @@ public void testTakeLastEmpty() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, never()).onNext(any(String.class)); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -53,7 +52,7 @@ public void testTakeLast1() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); InOrder inOrder = inOrder(observer); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); inOrder.verify(observer, times(1)).onNext("two"); inOrder.verify(observer, times(1)).onNext("three"); verify(observer, never()).onNext("one"); @@ -68,7 +67,7 @@ public void testTakeLast2() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -81,7 +80,7 @@ public void testTakeLastWithZeroCount() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, never()).onNext("one"); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -94,7 +93,7 @@ public void testTakeLastWithNull() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, never()).onNext("one"); verify(observer, times(1)).onNext(null); verify(observer, times(1)).onNext("three"); @@ -109,7 +108,7 @@ public void testTakeLastWithNegativeCount() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, never()).onNext("one"); verify(observer, times(1)).onError( any(IndexOutOfBoundsException.class)); @@ -122,13 +121,13 @@ public void takeLastTimed() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().takeLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -157,13 +156,13 @@ public void takeLastTimedDelayCompletion() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().takeLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -189,13 +188,13 @@ public void takeLastTimedWithCapacity() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().takeLast(2, 1, TimeUnit.SECONDS, scheduler); + Observable result = source.takeLast(2, 1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -226,13 +225,13 @@ public void takeLastTimedThrowingSource() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().takeLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); @@ -258,13 +257,13 @@ public void takeLastTimedWithZeroCapacity() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().takeLast(0, 1, TimeUnit.SECONDS, scheduler); + Observable result = source.takeLast(0, 1, TimeUnit.SECONDS, scheduler); Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); // T: 0ms scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS); diff --git a/rxjava-core/src/test/java/rx/operators/OperationTakeTimedTest.java b/rxjava-core/src/test/java/rx/operators/OperationTakeTimedTest.java index 17bac5b251..e150dbc44b 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationTakeTimedTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationTakeTimedTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.operators.OperationSkipTest.CustomException; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -38,12 +37,12 @@ public void testTakeTimed() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().take(1, TimeUnit.SECONDS, scheduler); + Observable result = source.take(1, TimeUnit.SECONDS, scheduler); @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); @@ -70,12 +69,12 @@ public void testTakeTimedErrorBeforeTime() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().take(1, TimeUnit.SECONDS, scheduler); + Observable result = source.take(1, TimeUnit.SECONDS, scheduler); @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); @@ -103,12 +102,12 @@ public void testTakeTimedErrorAfterTime() { PublishSubject source = PublishSubject.create(); - Observable result = source.toObservable().take(1, TimeUnit.SECONDS, scheduler); + Observable result = source.take(1, TimeUnit.SECONDS, scheduler); @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - result.subscribe(new TestObserver(o)); + result.subscribe(o); source.onNext(1); source.onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperationTakeUntilTest.java b/rxjava-core/src/test/java/rx/operators/OperationTakeUntilTest.java index 14ff228cee..df0c395d73 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationTakeUntilTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationTakeUntilTest.java @@ -23,7 +23,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; public class OperationTakeUntilTest { @@ -37,7 +36,7 @@ public void testTakeUntil() { Observer result = mock(Observer.class); Observable stringObservable = takeUntil(Observable.create(source), Observable.create(other)); - stringObservable.subscribe(new TestObserver(result)); + stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); other.sendOnNext("three"); @@ -64,7 +63,7 @@ public void testTakeUntilSourceCompleted() { Observer result = mock(Observer.class); Observable stringObservable = takeUntil(Observable.create(source), Observable.create(other)); - stringObservable.subscribe(new TestObserver(result)); + stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); source.sendOnCompleted(); @@ -87,13 +86,15 @@ public void testTakeUntilSourceError() { Observer result = mock(Observer.class); Observable stringObservable = takeUntil(Observable.create(source), Observable.create(other)); - stringObservable.subscribe(new TestObserver(result)); + stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); source.sendOnError(error); + source.sendOnNext("three"); verify(result, times(1)).onNext("one"); verify(result, times(1)).onNext("two"); + verify(result, times(0)).onNext("three"); verify(result, times(1)).onError(error); verify(sSource, times(1)).unsubscribe(); verify(sOther, times(1)).unsubscribe(); @@ -111,13 +112,15 @@ public void testTakeUntilOtherError() { Observer result = mock(Observer.class); Observable stringObservable = takeUntil(Observable.create(source), Observable.create(other)); - stringObservable.subscribe(new TestObserver(result)); + stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); other.sendOnError(error); + source.sendOnNext("three"); verify(result, times(1)).onNext("one"); verify(result, times(1)).onNext("two"); + verify(result, times(0)).onNext("three"); verify(result, times(1)).onError(error); verify(result, times(0)).onCompleted(); verify(sSource, times(1)).unsubscribe(); @@ -125,6 +128,9 @@ public void testTakeUntilOtherError() { } + /** + * If the 'other' onCompletes then we unsubscribe from the source and onComplete + */ @Test @SuppressWarnings("unchecked") public void testTakeUntilOtherCompleted() { @@ -135,16 +141,18 @@ public void testTakeUntilOtherCompleted() { Observer result = mock(Observer.class); Observable stringObservable = takeUntil(Observable.create(source), Observable.create(other)); - stringObservable.subscribe(new TestObserver(result)); + stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); other.sendOnCompleted(); + source.sendOnNext("three"); verify(result, times(1)).onNext("one"); verify(result, times(1)).onNext("two"); - verify(result, times(0)).onCompleted(); - verify(sSource, times(0)).unsubscribe(); - verify(sOther, times(0)).unsubscribe(); + verify(result, times(0)).onNext("three"); + verify(result, times(1)).onCompleted(); + verify(sSource, times(1)).unsubscribe(); + verify(sOther, times(1)).unsubscribe(); // unsubscribed since SafeSubscriber unsubscribes after onComplete } diff --git a/rxjava-core/src/test/java/rx/operators/OperationTakeWhileTest.java b/rxjava-core/src/test/java/rx/operators/OperationTakeWhileTest.java index ce23fe3796..033ea8e7d9 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationTakeWhileTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationTakeWhileTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; import rx.subjects.Subject; import rx.subscriptions.Subscriptions; @@ -46,7 +45,7 @@ public Boolean call(Integer input) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(2); verify(observer, never()).onNext(3); @@ -57,7 +56,7 @@ public Boolean call(Integer input) { @Test public void testTakeWhileOnSubject1() { Subject s = PublishSubject.create(); - Observable take = Observable.create(takeWhile(s.toObservable(), new Func1() { + Observable take = Observable.create(takeWhile(s, new Func1() { @Override public Boolean call(Integer input) { return input < 3; @@ -66,7 +65,7 @@ public Boolean call(Integer input) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); s.onNext(1); s.onNext(2); @@ -96,7 +95,7 @@ public Boolean call(String input, Integer index) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, never()).onNext("three"); @@ -136,7 +135,7 @@ public Boolean call(String s) { throw testException; } })); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); // wait for the Observable to complete try { @@ -163,7 +162,7 @@ public Boolean call(String s, Integer index) { return index < 1; } })); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); // wait for the Observable to complete try { diff --git a/rxjava-core/src/test/java/rx/operators/OperationThrottleFirstTest.java b/rxjava-core/src/test/java/rx/operators/OperationThrottleFirstTest.java index 9146dc4781..28375982ab 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationThrottleFirstTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationThrottleFirstTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subscriptions.Subscriptions; import rx.util.functions.Action0; @@ -60,7 +59,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationThrottleFirst.throttleFirst(source, 400, TimeUnit.MILLISECONDS, scheduler)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -88,7 +87,7 @@ public Subscription onSubscribe(Observer observer) { }); Observable sampled = Observable.create(OperationThrottleFirst.throttleFirst(source, 400, TimeUnit.MILLISECONDS, scheduler)); - sampled.subscribe(new TestObserver(observer)); + sampled.subscribe(observer); InOrder inOrder = inOrder(observer); diff --git a/rxjava-core/src/test/java/rx/operators/OperationTimeIntervalTest.java b/rxjava-core/src/test/java/rx/operators/OperationTimeIntervalTest.java index df70d97e44..5f3c349553 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationTimeIntervalTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationTimeIntervalTest.java @@ -27,7 +27,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; import rx.util.TimeInterval; @@ -48,13 +47,13 @@ public void setUp() { MockitoAnnotations.initMocks(this); testScheduler = new TestScheduler(); subject = PublishSubject.create(); - observable = subject.toObservable().timeInterval(testScheduler); + observable = subject.timeInterval(testScheduler); } @Test public void testTimeInterval() { InOrder inOrder = inOrder(observer); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); testScheduler.advanceTimeBy(1000, TIME_UNIT); subject.onNext(1); diff --git a/rxjava-core/src/test/java/rx/operators/OperationTimeoutTest.java b/rxjava-core/src/test/java/rx/operators/OperationTimeoutTest.java index ee94c134d6..8644127110 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationTimeoutTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationTimeoutTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; import rx.util.functions.Func0; import rx.util.functions.Func1; @@ -39,14 +38,14 @@ public void testTimeoutSelectorNormal1() { Func1> timeoutFunc = new Func1>() { @Override public Observable call(Integer t1) { - return timeout.toObservable(); + return timeout; } }; Func0> firstTimeoutFunc = new Func0>() { @Override public Observable call() { - return timeout.toObservable(); + return timeout; } }; @@ -56,7 +55,7 @@ public Observable call() { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(new TestObserver(o)); + source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); source.onNext(1); source.onNext(2); @@ -80,14 +79,14 @@ public void testTimeoutSelectorTimeoutFirst() throws InterruptedException { Func1> timeoutFunc = new Func1>() { @Override public Observable call(Integer t1) { - return timeout.toObservable(); + return timeout; } }; Func0> firstTimeoutFunc = new Func0>() { @Override public Observable call() { - return timeout.toObservable(); + return timeout; } }; @@ -97,7 +96,7 @@ public Observable call() { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(new TestObserver(o)); + source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); timeout.onNext(1); @@ -115,7 +114,7 @@ public void testTimeoutSelectorFirstThrows() { Func1> timeoutFunc = new Func1>() { @Override public Observable call(Integer t1) { - return timeout.toObservable(); + return timeout; } }; @@ -131,7 +130,7 @@ public Observable call() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(new TestObserver(o)); + source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); verify(o).onError(any(OperationReduceTest.CustomException.class)); verify(o, never()).onNext(any()); @@ -154,7 +153,7 @@ public Observable call(Integer t1) { Func0> firstTimeoutFunc = new Func0>() { @Override public Observable call() { - return timeout.toObservable(); + return timeout; } }; @@ -164,7 +163,7 @@ public Observable call() { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(new TestObserver(o)); + source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); source.onNext(1); @@ -182,7 +181,7 @@ public void testTimeoutSelectorFirstObservableThrows() { Func1> timeoutFunc = new Func1>() { @Override public Observable call(Integer t1) { - return timeout.toObservable(); + return timeout; } }; @@ -198,7 +197,7 @@ public Observable call() { @SuppressWarnings("unchecked") Observer o = mock(Observer.class); - source.toObservable().timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(new TestObserver(o)); + source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); verify(o).onError(any(OperationReduceTest.CustomException.class)); verify(o, never()).onNext(any()); @@ -221,7 +220,7 @@ public Observable call(Integer t1) { Func0> firstTimeoutFunc = new Func0>() { @Override public Observable call() { - return timeout.toObservable(); + return timeout; } }; @@ -231,7 +230,7 @@ public Observable call() { Observer o = mock(Observer.class); InOrder inOrder = inOrder(o); - source.toObservable().timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(new TestObserver(o)); + source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); source.onNext(1); diff --git a/rxjava-core/src/test/java/rx/operators/OperationTimerTest.java b/rxjava-core/src/test/java/rx/operators/OperationTimerTest.java index 9305e2fdae..33c29589c9 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationTimerTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationTimerTest.java @@ -29,7 +29,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; public class OperationTimerTest { @@ -45,7 +44,7 @@ public void before() { @Test public void testTimerOnce() { - Observable.timer(100, TimeUnit.MILLISECONDS, s).subscribe(new TestObserver(observer)); + Observable.timer(100, TimeUnit.MILLISECONDS, s).subscribe(observer); s.advanceTimeBy(100, TimeUnit.MILLISECONDS); verify(observer, times(1)).onNext(0L); @@ -55,7 +54,7 @@ public void testTimerOnce() { @Test public void testTimerPeriodically() { - Subscription c = Observable.timer(100, 100, TimeUnit.MILLISECONDS, s).subscribe(new TestObserver(observer)); + Subscription c = Observable.timer(100, 100, TimeUnit.MILLISECONDS, s).subscribe(observer); s.advanceTimeBy(100, TimeUnit.MILLISECONDS); InOrder inOrder = inOrder(observer); diff --git a/rxjava-core/src/test/java/rx/operators/OperationToMapTest.java b/rxjava-core/src/test/java/rx/operators/OperationToMapTest.java index c5134a7378..6f9db93250 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationToMapTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationToMapTest.java @@ -29,7 +29,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func0; import rx.util.functions.Func1; import rx.util.functions.Functions; @@ -68,7 +67,7 @@ public void testToMap() { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onError(any(Throwable.class)); verify(objectObserver, times(1)).onNext(expected); @@ -87,7 +86,7 @@ public void testToMapWithValueSelector() { expected.put(3, "cccccc"); expected.put(4, "dddddddd"); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onError(any(Throwable.class)); verify(objectObserver, times(1)).onNext(expected); @@ -115,7 +114,7 @@ public Integer call(String t1) { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onNext(expected); verify(objectObserver, never()).onCompleted(); @@ -145,7 +144,7 @@ public String call(String t1) { expected.put(3, "cccccc"); expected.put(4, "dddddddd"); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onNext(expected); verify(objectObserver, never()).onCompleted(); @@ -182,7 +181,7 @@ public Integer call(String t1) { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onError(any(Throwable.class)); verify(objectObserver, times(1)).onNext(expected); @@ -213,7 +212,7 @@ public Integer call(String t1) { expected.put(3, "ccc"); expected.put(4, "dddd"); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onNext(expected); verify(objectObserver, never()).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperationToMultimapTest.java b/rxjava-core/src/test/java/rx/operators/OperationToMultimapTest.java index 68e25a8d85..c9f6fec60e 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationToMultimapTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationToMultimapTest.java @@ -34,7 +34,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.operators.OperationToMultimap.DefaultMultimapCollectionFactory; import rx.operators.OperationToMultimap.DefaultToMultimapFactory; import rx.util.functions.Func0; @@ -73,7 +72,7 @@ public void testToMultimap() { expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onError(any(Throwable.class)); verify(objectObserver, times(1)).onNext(expected); @@ -90,7 +89,7 @@ public void testToMultimapWithValueSelector() { expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onError(any(Throwable.class)); verify(objectObserver, times(1)).onNext(expected); @@ -122,7 +121,7 @@ lengthFunc, Functions. identity(), expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Arrays.asList("eee", "fff")); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onError(any(Throwable.class)); verify(objectObserver, times(1)).onNext(expected); @@ -154,7 +153,7 @@ source, lengthFunc, Functions. identity(), expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, new HashSet(Arrays.asList("eee"))); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, never()).onError(any(Throwable.class)); verify(objectObserver, times(1)).onNext(expected); @@ -181,7 +180,7 @@ public Integer call(String t1) { expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, times(1)).onError(any(Throwable.class)); verify(objectObserver, never()).onNext(expected); @@ -208,7 +207,7 @@ public String call(String t1) { expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, times(1)).onError(any(Throwable.class)); verify(objectObserver, never()).onNext(expected); @@ -233,7 +232,7 @@ public Map> call() { expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Arrays.asList("eee", "fff")); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, times(1)).onError(any(Throwable.class)); verify(objectObserver, never()).onNext(expected); @@ -264,7 +263,7 @@ public Collection call(Integer t1) { expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Collections.singleton("eee")); - mapped.subscribe(new TestObserver(objectObserver)); + mapped.subscribe(objectObserver); verify(objectObserver, times(1)).onError(any(Throwable.class)); verify(objectObserver, never()).onNext(expected); diff --git a/rxjava-core/src/test/java/rx/operators/OperationToObservableFutureTest.java b/rxjava-core/src/test/java/rx/operators/OperationToObservableFutureTest.java index 92a1f92a91..b79de2a69e 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationToObservableFutureTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationToObservableFutureTest.java @@ -23,6 +23,7 @@ import rx.Observer; import rx.Subscription; +import rx.observers.TestObserver; import rx.operators.OperationToObservableFuture.ToObservableFuture; public class OperationToObservableFutureTest { @@ -35,7 +36,7 @@ public void testSuccess() throws Exception { ToObservableFuture ob = new ToObservableFuture(future); Observer o = mock(Observer.class); - Subscription sub = ob.onSubscribe(o); + Subscription sub = ob.onSubscribe(new TestObserver(o)); sub.unsubscribe(); verify(o, times(1)).onNext(value); @@ -52,7 +53,7 @@ public void testFailure() throws Exception { ToObservableFuture ob = new ToObservableFuture(future); Observer o = mock(Observer.class); - Subscription sub = ob.onSubscribe(o); + Subscription sub = ob.onSubscribe(new TestObserver(o)); sub.unsubscribe(); verify(o, never()).onNext(null); diff --git a/rxjava-core/src/test/java/rx/operators/OperationUsingTest.java b/rxjava-core/src/test/java/rx/operators/OperationUsingTest.java index 0584e0f775..646dfc22db 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationUsingTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationUsingTest.java @@ -26,7 +26,6 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.subscriptions.Subscriptions; import rx.util.functions.Action0; import rx.util.functions.Func0; @@ -68,7 +67,7 @@ public Observable call(Resource resource) { Observer observer = (Observer) mock(Observer.class); Observable observable = Observable.create(using( resourceFactory, observableFactory)); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext("Hello"); @@ -118,8 +117,8 @@ public Observable call(Resource resource) { Observer observer = (Observer) mock(Observer.class); Observable observable = Observable.create(using( resourceFactory, observableFactory)); - observable.subscribe(new TestObserver(observer)); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); + observable.subscribe(observer); InOrder inOrder = inOrder(observer); diff --git a/rxjava-core/src/test/java/rx/operators/OperationWindowTest.java b/rxjava-core/src/test/java/rx/operators/OperationWindowTest.java index dfcb80b00e..a3f66d2e98 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationWindowTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationWindowTest.java @@ -30,7 +30,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.Schedulers; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; @@ -345,7 +344,7 @@ public void onNext(Observable args) { final Observer mo = mock(Observer.class); values.add(mo); - args.subscribe(new TestObserver(mo)); + args.subscribe(mo); } @Override @@ -359,7 +358,7 @@ public void onCompleted() { } }; - source.toObservable().window(boundary.toObservable()).subscribe(new TestObserver>(wo)); + source.window(boundary).subscribe(wo); int n = 30; for (int i = 0; i < n; i++) { @@ -403,7 +402,7 @@ public void onNext(Observable args) { final Observer mo = mock(Observer.class); values.add(mo); - args.subscribe(new TestObserver(mo)); + args.subscribe(mo); } @Override @@ -417,7 +416,7 @@ public void onCompleted() { } }; - source.toObservable().window(boundary.toObservable()).subscribe(new TestObserver>(wo)); + source.window(boundary).subscribe(wo); int n = 30; for (int i = 0; i < n; i++) { @@ -461,7 +460,7 @@ public void onNext(Observable args) { final Observer mo = mock(Observer.class); values.add(mo); - args.subscribe(new TestObserver(mo)); + args.subscribe(mo); } @Override @@ -475,7 +474,7 @@ public void onCompleted() { } }; - source.toObservable().window(boundary.toObservable()).subscribe(new TestObserver>(wo)); + source.window(boundary).subscribe(wo); source.onNext(0); source.onNext(1); @@ -513,7 +512,7 @@ public void onNext(Observable args) { final Observer mo = mock(Observer.class); values.add(mo); - args.subscribe(new TestObserver(mo)); + args.subscribe(mo); } @Override @@ -527,7 +526,7 @@ public void onCompleted() { } }; - source.toObservable().window(boundary.toObservable()).subscribe(new TestObserver>(wo)); + source.window(boundary).subscribe(wo); source.onNext(0); source.onNext(1); diff --git a/rxjava-core/src/test/java/rx/operators/OperationZipTest.java b/rxjava-core/src/test/java/rx/operators/OperationZipTest.java index 444372db54..97cb87870a 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationZipTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperationZipTest.java @@ -31,7 +31,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.operators.OperationReduceTest.CustomException; import rx.subjects.PublishSubject; import rx.subscriptions.Subscriptions; @@ -61,12 +60,12 @@ public String call(String t1, String t2) { s1 = PublishSubject.create(); s2 = PublishSubject.create(); - zipped = Observable.zip(s1.toObservable(), s2.toObservable(), concat2Strings); + zipped = Observable.zip(s1, s2, concat2Strings); observer = mock(Observer.class); inOrder = inOrder(observer); - zipped.subscribe(new TestObserver(observer)); + zipped.subscribe(observer); } @SuppressWarnings("unchecked") @@ -81,7 +80,7 @@ public void testCollectionSizeDifferentThanFunction() { @SuppressWarnings("rawtypes") Collection ws = java.util.Collections.singleton(Observable.from("one", "two")); Observable w = Observable.create(zip(ws, zipr)); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); verify(observer, never()).onCompleted(); @@ -99,7 +98,7 @@ public void testZippingDifferentLengthObservableSequences1() { TestObservable w3 = new TestObservable(); Observable zipW = Observable.create(zip(Observable.create(w1), Observable.create(w2), Observable.create(w3), getConcat3StringsZipr())); - zipW.subscribe(new TestObserver(w)); + zipW.subscribe(w); /* simulate sending data */ // once for w1 @@ -133,7 +132,7 @@ public void testZippingDifferentLengthObservableSequences2() { TestObservable w3 = new TestObservable(); Observable zipW = Observable.create(zip(Observable.create(w1), Observable.create(w2), Observable.create(w3), getConcat3StringsZipr())); - zipW.subscribe(new TestObserver(w)); + zipW.subscribe(w); /* simulate sending data */ // 4 times for w1 @@ -187,7 +186,7 @@ public void testAggregatorSimple() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Observable.zip(r1.toObservable(), r2.toObservable(), zipr2).subscribe(new TestObserver(observer)); + Observable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -224,7 +223,7 @@ public void testAggregatorDifferentSizedResultsWithOnComplete() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Observable.zip(r1.toObservable(), r2.toObservable(), zipr2).subscribe(new TestObserver(observer)); + Observable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -254,7 +253,7 @@ public void testAggregateMultipleTypes() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Observable.zip(r1.toObservable(), r2.toObservable(), zipr2).subscribe(new TestObserver(observer)); + Observable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -285,7 +284,7 @@ public void testAggregate3Types() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Observable.zip(r1.toObservable(), r2.toObservable(), r3.toObservable(), zipr3).subscribe(new TestObserver(observer)); + Observable.zip(r1, r2, r3, zipr3).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -306,7 +305,7 @@ public void testAggregatorsWithDifferentSizesAndTiming() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Observable.zip(r1.toObservable(), r2.toObservable(), zipr2).subscribe(new TestObserver(observer)); + Observable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("one"); @@ -343,7 +342,7 @@ public void testAggregatorError() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Observable.zip(r1.toObservable(), r2.toObservable(), zipr2).subscribe(new TestObserver(observer)); + Observable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -372,7 +371,7 @@ public void testAggregatorUnsubscribe() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Subscription subscription = Observable.zip(r1.toObservable(), r2.toObservable(), zipr2).subscribe(new TestObserver(observer)); + Subscription subscription = Observable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -401,7 +400,7 @@ public void testAggregatorEarlyCompletion() { /* define a Observer to receive aggregated events */ Observer observer = mock(Observer.class); - Observable.zip(r1.toObservable(), r2.toObservable(), zipr2).subscribe(new TestObserver(observer)); + Observable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("one"); @@ -432,7 +431,7 @@ public void testZip2Types() { Observer observer = mock(Observer.class); Observable w = Observable.create(zip(Observable.from("one", "two"), Observable.from(2, 3, 4), zipr)); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -451,7 +450,7 @@ public void testZip3Types() { Observer observer = mock(Observer.class); Observable w = Observable.create(zip(Observable.from("one", "two"), Observable.from(2), Observable.from(new int[] { 4, 5, 6 }), zipr)); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -467,7 +466,7 @@ public void testOnNextExceptionInvokesOnError() { Observer observer = mock(Observer.class); Observable w = Observable.create(zip(Observable.from(10, 20, 30), Observable.from(0, 1, 2), zipr)); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); } @@ -480,8 +479,8 @@ public void testOnFirstCompletion() { @SuppressWarnings("unchecked") Observer obs = mock(Observer.class); - Observable o = Observable.create(zip(oA.toObservable(), oB.toObservable(), getConcat2Strings())); - o.subscribe(new TestObserver(obs)); + Observable o = Observable.create(zip(oA, oB, getConcat2Strings())); + o.subscribe(obs); InOrder io = inOrder(obs); @@ -531,8 +530,8 @@ public void testOnErrorTermination() { @SuppressWarnings("unchecked") Observer obs = mock(Observer.class); - Observable o = Observable.create(zip(oA.toObservable(), oB.toObservable(), getConcat2Strings())); - o.subscribe(new TestObserver(obs)); + Observable o = Observable.create(zip(oA, oB, getConcat2Strings())); + o.subscribe(obs); InOrder io = inOrder(obs); @@ -770,7 +769,7 @@ public void testZipIterableSameSize() { Iterable r2 = Arrays.asList("1", "2", "3"); - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onNext("one-"); r1.onNext("two-"); @@ -795,7 +794,7 @@ public void testZipIterableEmptyFirstSize() { Iterable r2 = Arrays.asList("1", "2", "3"); - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onCompleted(); @@ -815,7 +814,7 @@ public void testZipIterableEmptySecond() { Iterable r2 = Arrays.asList(); - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onNext("one-"); r1.onNext("two-"); @@ -837,7 +836,7 @@ public void testZipIterableFirstShorter() { Iterable r2 = Arrays.asList("1", "2", "3"); - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onNext("one-"); r1.onNext("two-"); @@ -860,7 +859,7 @@ public void testZipIterableSecondShorter() { Iterable r2 = Arrays.asList("1", "2"); - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onNext("one-"); r1.onNext("two-"); @@ -884,7 +883,7 @@ public void testZipIterableFirstThrows() { Iterable r2 = Arrays.asList("1", "2", "3"); - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onNext("one-"); r1.onNext("two-"); @@ -912,7 +911,7 @@ public Iterator iterator() { } }; - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onNext("one-"); r1.onNext("two-"); @@ -963,7 +962,7 @@ public void remove() { }; - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onNext("one-"); r1.onError(new OperationReduceTest.CustomException()); @@ -1009,7 +1008,7 @@ public void remove() { }; - r1.toObservable().zip(r2, zipr2).subscribe(new TestObserver(o)); + r1.zip(r2, zipr2).subscribe(o); r1.onError(new OperationReduceTest.CustomException()); diff --git a/rxjava-core/src/test/java/rx/operators/OperationZipTestCompletion.java b/rxjava-core/src/test/java/rx/operators/OperationZipTestCompletion.java index 62c0b22860..3f1daa80c1 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationZipTestCompletion.java +++ b/rxjava-core/src/test/java/rx/operators/OperationZipTestCompletion.java @@ -23,7 +23,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.subjects.PublishSubject; import rx.util.functions.Func2; @@ -54,12 +53,12 @@ public String call(String t1, String t2) { s1 = PublishSubject.create(); s2 = PublishSubject.create(); - zipped = Observable.zip(s1.toObservable(), s2.toObservable(), concat2Strings); + zipped = Observable.zip(s1, s2, concat2Strings); observer = mock(Observer.class); inOrder = inOrder(observer); - zipped.subscribe(new TestObserver(observer)); + zipped.subscribe(observer); } @Test diff --git a/rxjava-core/src/test/java/rx/operators/OperatorCastTest.java b/rxjava-core/src/test/java/rx/operators/OperatorCastTest.java index 9399086957..7ef8c90408 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorCastTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorCastTest.java @@ -21,7 +21,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; public class OperatorCastTest { @@ -32,7 +31,7 @@ public void testCast() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(1); verify(observer, never()).onError( @@ -47,7 +46,7 @@ public void testCastWithWrongType() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onError( org.mockito.Matchers.any(ClassCastException.class)); } diff --git a/rxjava-core/src/test/java/rx/operators/OperationDoOnEachTest.java b/rxjava-core/src/test/java/rx/operators/OperatorDoOnEachTest.java similarity index 90% rename from rxjava-core/src/test/java/rx/operators/OperationDoOnEachTest.java rename to rxjava-core/src/test/java/rx/operators/OperatorDoOnEachTest.java index 4bc7c22af8..5b23d63dc3 100644 --- a/rxjava-core/src/test/java/rx/operators/OperationDoOnEachTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorDoOnEachTest.java @@ -25,11 +25,10 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Action1; import rx.util.functions.Func1; -public class OperationDoOnEachTest { +public class OperatorDoOnEachTest { @Mock Observer subscribedObserver; @@ -46,7 +45,7 @@ public void testDoOnEach() { Observable base = Observable.from("a", "b", "c"); Observable doOnEach = base.doOnEach(sideEffectObserver); - doOnEach.subscribe(new TestObserver(subscribedObserver)); + doOnEach.subscribe(subscribedObserver); // ensure the leaf observer is still getting called verify(subscribedObserver, never()).onError(any(Throwable.class)); @@ -76,9 +75,9 @@ public String call(String s) { } }); - Observable doOnEach = errs.doOnEach(new TestObserver(sideEffectObserver)); + Observable doOnEach = errs.doOnEach(sideEffectObserver); - doOnEach.subscribe(new TestObserver(subscribedObserver)); + doOnEach.subscribe(subscribedObserver); verify(subscribedObserver, times(1)).onNext("one"); verify(subscribedObserver, never()).onNext("two"); verify(subscribedObserver, never()).onNext("three"); @@ -104,7 +103,7 @@ public void call(String s) { } }); - doOnEach.subscribe(new TestObserver(subscribedObserver)); + doOnEach.subscribe(subscribedObserver); verify(subscribedObserver, times(1)).onNext("one"); verify(subscribedObserver, times(1)).onNext("two"); verify(subscribedObserver, never()).onNext("three"); diff --git a/rxjava-core/src/test/java/rx/operators/OperatorFromIterableTest.java b/rxjava-core/src/test/java/rx/operators/OperatorFromIterableTest.java index eddcf35ef3..2fbc6627da 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorFromIterableTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorFromIterableTest.java @@ -25,7 +25,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; public class OperatorFromIterableTest { @@ -35,7 +34,7 @@ public void testIterable() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -49,7 +48,7 @@ public void testObservableFromIterable() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - observable.subscribe(new TestObserver(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); diff --git a/rxjava-core/src/test/java/rx/operators/OperatorGroupByTest.java b/rxjava-core/src/test/java/rx/operators/OperatorGroupByTest.java index a62659644a..c808e396bb 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorGroupByTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorGroupByTest.java @@ -32,6 +32,7 @@ import rx.Observable; import rx.Observable.OnSubscribe; import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.observables.GroupedObservable; import rx.schedulers.Schedulers; @@ -96,7 +97,7 @@ public String call(String v) { } }); } - }).subscribe(new Observer() { + }).subscribe(new Subscriber() { @Override public void onCompleted() { @@ -207,7 +208,7 @@ public String call(Event event) { }); } - }).subscribe(new Observer() { + }).subscribe(new Subscriber() { @Override public void onCompleted() { @@ -285,7 +286,7 @@ public String call(Event event) { }); } - }).subscribe(new Observer() { + }).subscribe(new Subscriber() { @Override public void onCompleted() { @@ -501,7 +502,7 @@ public Integer call(Integer t) { } } }) - .subscribe(new Observer() { + .subscribe(new Subscriber() { @Override public void onCompleted() { @@ -541,7 +542,7 @@ public Integer call(Integer i) { return i % 2; } }) - .subscribe(new Observer>() { + .subscribe(new Subscriber>() { @Override public void onCompleted() { @@ -584,7 +585,7 @@ Observable SYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final A return Observable.create(new OnSubscribe() { @Override - public void call(final Observer op) { + public void call(final Subscriber op) { subscribeCounter.incrementAndGet(); int i = 0; while (!op.isUnsubscribed()) { diff --git a/rxjava-core/src/test/java/rx/operators/OperatorMapTest.java b/rxjava-core/src/test/java/rx/operators/OperatorMapTest.java index 68092cf22f..652ff720ac 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorMapTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorMapTest.java @@ -28,7 +28,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.schedulers.Schedulers; import rx.util.functions.Func1; import rx.util.functions.Func2; @@ -66,7 +65,7 @@ public String call(Map map) { } })); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(1)).onNext("OneFirst"); @@ -106,7 +105,7 @@ public String call(Map map) { } }); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(1)).onNext("OneFirst"); @@ -142,7 +141,7 @@ public String call(Map map) { } }); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(1)).onNext("OneFirst"); @@ -166,7 +165,7 @@ public String call(String s) { } })); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onNext("one"); verify(stringObserver, never()).onNext("two"); verify(stringObserver, never()).onNext("three"); diff --git a/rxjava-core/src/test/java/rx/operators/OperatorMergeTest.java b/rxjava-core/src/test/java/rx/operators/OperatorMergeTest.java index e9a7dc1ee5..d20cc8acb9 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorMergeTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorMergeTest.java @@ -35,8 +35,8 @@ import rx.Observable; import rx.Observer; +import rx.Subscriber; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.Schedulers; import rx.subscriptions.Subscriptions; import rx.util.functions.Action0; @@ -78,7 +78,7 @@ public void unsubscribe() { }); Observable m = Observable.merge(observableOfObservables); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(1)).onCompleted(); @@ -91,7 +91,7 @@ public void testMergeArray() { final Observable o2 = Observable.create(new TestSynchronousObservable()); Observable m = Observable.merge(o1, o2); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(2)).onNext("hello"); @@ -107,7 +107,7 @@ public void testMergeList() { listOfObservables.add(o2); Observable m = Observable.merge(listOfObservables); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); verify(stringObserver, times(1)).onCompleted(); @@ -186,7 +186,7 @@ public void testMergeArrayWithThreading() { final TestASynchronousObservable o2 = new TestASynchronousObservable(); Observable m = Observable.merge(Observable.create(o1), Observable.create(o2)); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); try { o1.t.join(); @@ -212,7 +212,7 @@ public void testSynchronizationOfMultipleSequences() throws Throwable { final AtomicInteger totalCounter = new AtomicInteger(); Observable m = Observable.merge(Observable.create(o1), Observable.create(o2)); - m.subscribe(new Observer() { + m.subscribe(new Subscriber() { @Override public void onCompleted() { @@ -282,7 +282,7 @@ public void testError1() { final Observable o2 = Observable.create(new TestErrorObservable("one", "two", "three")); // we expect to lose all of these since o1 is done first and fails Observable m = Observable.merge(o1, o2); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); verify(stringObserver, never()).onCompleted(); @@ -306,7 +306,7 @@ public void testError2() { final Observable o4 = Observable.create(new TestErrorObservable("nine"));// we expect to lose all of these since o2 is done first and fails Observable m = Observable.merge(o1, o2, o3, o4); - m.subscribe(new TestObserver(stringObserver)); + m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); verify(stringObserver, never()).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperatorTakeTest.java b/rxjava-core/src/test/java/rx/operators/OperatorTakeTest.java index 2a4c3d2f4b..a75fa703e8 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorTakeTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorTakeTest.java @@ -29,10 +29,9 @@ import rx.Observable; import rx.Observable.OnSubscribe; import rx.Observer; +import rx.Subscriber; import rx.Subscription; -import rx.observers.TestObserver; import rx.subscriptions.Subscriptions; -import rx.util.functions.Action0; import rx.util.functions.Action1; import rx.util.functions.Func1; @@ -45,7 +44,7 @@ public void testTake1() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, never()).onNext("three"); @@ -60,7 +59,7 @@ public void testTake2() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, never()).onNext("two"); verify(observer, never()).onNext("three"); @@ -87,7 +86,7 @@ public Integer call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(any(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); @@ -103,7 +102,7 @@ public Integer call(Integer t1) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - w.subscribe(new TestObserver(observer)); + w.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(any(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); @@ -123,7 +122,7 @@ public Subscription onSubscribe(Observer observer) { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - source.lift(new OperatorTake(1)).subscribe(new TestObserver(observer)); + source.lift(new OperatorTake(1)).subscribe(observer); verify(observer, times(1)).onNext("one"); // even though onError is called we take(1) so shouldn't see it @@ -153,7 +152,7 @@ public void unsubscribe() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - source.lift(new OperatorTake(0)).subscribe(new TestObserver(observer)); + source.lift(new OperatorTake(0)).subscribe(observer); assertTrue("source subscribed", subscribed.get()); assertTrue("source unsubscribed", unSubscribed.get()); @@ -173,7 +172,7 @@ public void testUnsubscribeAfterTake() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); Observable take = w.lift(new OperatorTake(1)); - take.subscribe(new TestObserver(observer)); + take.subscribe(observer); // wait for the Observable to complete try { @@ -247,7 +246,7 @@ public void run() { private static Observable INFINITE_OBSERVABLE = Observable.create(new OnSubscribe() { @Override - public void call(Observer op) { + public void call(Subscriber op) { long l = 1; while (!op.isUnsubscribed()) { op.onNext(l++); diff --git a/rxjava-core/src/test/java/rx/operators/OperatorTimestampTest.java b/rxjava-core/src/test/java/rx/operators/OperatorTimestampTest.java index 0f57004108..dd299d4367 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorTimestampTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorTimestampTest.java @@ -28,7 +28,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.schedulers.TestScheduler; import rx.subjects.PublishSubject; import rx.util.Timestamped; @@ -47,8 +46,8 @@ public void timestampWithScheduler() { TestScheduler scheduler = new TestScheduler(); PublishSubject source = PublishSubject.create(); - Observable> m = source.toObservable().timestamp(scheduler); - m.subscribe(new TestObserver(observer)); + Observable> m = source.timestamp(scheduler); + m.subscribe(observer); source.onNext(1); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); @@ -71,8 +70,8 @@ public void timestampWithScheduler2() { TestScheduler scheduler = new TestScheduler(); PublishSubject source = PublishSubject.create(); - Observable> m = source.toObservable().timestamp(scheduler); - m.subscribe(new TestObserver(observer)); + Observable> m = source.timestamp(scheduler); + m.subscribe(observer); source.onNext(1); source.onNext(2); diff --git a/rxjava-core/src/test/java/rx/operators/OperatorToObservableListTest.java b/rxjava-core/src/test/java/rx/operators/OperatorToObservableListTest.java index 8f757dd66d..980800a193 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorToObservableListTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorToObservableListTest.java @@ -26,7 +26,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; public class OperatorToObservableListTest { @@ -37,7 +36,7 @@ public void testList() { @SuppressWarnings("unchecked") Observer> observer = mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -50,7 +49,7 @@ public void testListViaObservable() { @SuppressWarnings("unchecked") Observer> observer = mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -63,11 +62,11 @@ public void testListMultipleObservers() { @SuppressWarnings("unchecked") Observer> o1 = mock(Observer.class); - observable.subscribe(new TestObserver>(o1)); + observable.subscribe(o1); @SuppressWarnings("unchecked") Observer> o2 = mock(Observer.class); - observable.subscribe(new TestObserver>(o2)); + observable.subscribe(o2); List expected = Arrays.asList("one", "two", "three"); @@ -87,7 +86,7 @@ public void testListWithNullValue() { @SuppressWarnings("unchecked") Observer> observer = mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(Arrays.asList("one", null, "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/operators/OperatorToObservableSortedListTest.java b/rxjava-core/src/test/java/rx/operators/OperatorToObservableSortedListTest.java index ddd59c9b99..4c324f207d 100644 --- a/rxjava-core/src/test/java/rx/operators/OperatorToObservableSortedListTest.java +++ b/rxjava-core/src/test/java/rx/operators/OperatorToObservableSortedListTest.java @@ -26,7 +26,6 @@ import rx.Observable; import rx.Observer; -import rx.observers.TestObserver; import rx.util.functions.Func2; public class OperatorToObservableSortedListTest { @@ -38,7 +37,7 @@ public void testSortedList() { @SuppressWarnings("unchecked") Observer> observer = mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(Arrays.asList(1, 2, 3, 4, 5)); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); @@ -58,7 +57,7 @@ public Integer call(Integer t1, Integer t2) { @SuppressWarnings("unchecked") Observer> observer = mock(Observer.class); - observable.subscribe(new TestObserver>(observer)); + observable.subscribe(observer); verify(observer, times(1)).onNext(Arrays.asList(5, 4, 3, 2, 1)); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onCompleted(); diff --git a/rxjava-core/src/test/java/rx/plugins/RxJavaPluginsTest.java b/rxjava-core/src/test/java/rx/plugins/RxJavaPluginsTest.java index 78bff98eaf..c3bfce52c5 100644 --- a/rxjava-core/src/test/java/rx/plugins/RxJavaPluginsTest.java +++ b/rxjava-core/src/test/java/rx/plugins/RxJavaPluginsTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import rx.Observable; -import rx.Observer; +import rx.Subscriber; public class RxJavaPluginsTest { @@ -112,7 +112,7 @@ public void testOnErrorWhenImplementedViaSubscribe() { RxJavaPlugins.getInstance().registerErrorHandler(errorHandler); RuntimeException re = new RuntimeException("test onError"); - Observable.error(re).subscribe(new Observer() { + Observable.error(re).subscribe(new Subscriber() { @Override public void onCompleted() { diff --git a/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerConcurrencyTests.java b/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerConcurrencyTests.java index e142b024ae..8a6e84ab6e 100644 --- a/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerConcurrencyTests.java +++ b/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerConcurrencyTests.java @@ -28,6 +28,7 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Scheduler; +import rx.Subscriber; import rx.Subscription; import rx.operators.SafeObservableSubscription; import rx.subscriptions.Subscriptions; @@ -65,7 +66,7 @@ public Long call(Long aLong) { }) .subscribeOn(getScheduler()) .observeOn(getScheduler()) - .subscribe(new Observer() { + .subscribe(new Subscriber() { @Override public void onCompleted() { System.out.println("--- completed"); @@ -244,7 +245,7 @@ public void call() { final AtomicInteger count = new AtomicInteger(); final AtomicBoolean completed = new AtomicBoolean(false); - Subscription subscribe = obs.subscribe(new Observer() { + Subscription subscribe = obs.subscribe(new Subscriber() { @Override public void onCompleted() { System.out.println("Completed"); diff --git a/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerTests.java b/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerTests.java index db84805cd4..f744ecc5ab 100644 --- a/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerTests.java +++ b/rxjava-core/src/test/java/rx/schedulers/AbstractSchedulerTests.java @@ -35,6 +35,7 @@ import rx.Observable.OnSubscribeFunc; import rx.Observer; import rx.Scheduler; +import rx.Subscriber; import rx.Subscription; import rx.subscriptions.BooleanSubscription; import rx.subscriptions.Subscriptions; @@ -561,7 +562,7 @@ public Subscription onSubscribe(final Observer observer) { * * @param */ - private static class ConcurrentObserverValidator extends Observer { + private static class ConcurrentObserverValidator extends Subscriber { final AtomicInteger concurrentCounter = new AtomicInteger(); final AtomicReference error = new AtomicReference(); diff --git a/rxjava-core/src/test/java/rx/subjects/AsyncSubjectTest.java b/rxjava-core/src/test/java/rx/subjects/AsyncSubjectTest.java index 4da5e7d123..e49d0b3bd4 100644 --- a/rxjava-core/src/test/java/rx/subjects/AsyncSubjectTest.java +++ b/rxjava-core/src/test/java/rx/subjects/AsyncSubjectTest.java @@ -28,7 +28,6 @@ import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.util.functions.Action1; public class AsyncSubjectTest { @@ -41,7 +40,7 @@ public void testNeverCompleted() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -58,7 +57,7 @@ public void testCompleted() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -76,7 +75,7 @@ public void testNull() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext(null); subject.onCompleted(); @@ -98,7 +97,7 @@ public void testSubscribeAfterCompleted() { subject.onNext("three"); subject.onCompleted(); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); verify(observer, times(1)).onNext("three"); verify(observer, Mockito.never()).onError(any(Throwable.class)); @@ -119,7 +118,7 @@ public void testSubscribeAfterError() { RuntimeException re = new RuntimeException("failed"); subject.onError(re); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); verify(observer, times(1)).onError(re); verify(observer, Mockito.never()).onNext(any(String.class)); @@ -132,7 +131,7 @@ public void testError() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -153,7 +152,7 @@ public void testUnsubscribeBeforeCompleted() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = subject.toObservable().subscribe(new TestObserver(observer)); + Subscription subscription = subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -178,7 +177,7 @@ public void testEmptySubjectCompleted() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onCompleted(); @@ -204,7 +203,7 @@ public void testSubscribeCompletionRaceCondition() { final AsyncSubject subject = AsyncSubject.create(); final AtomicReference value1 = new AtomicReference(); - subject.toObservable().subscribe(new Action1() { + subject.subscribe(new Action1() { @Override public void call(String t1) { @@ -270,7 +269,7 @@ public SubjectObserverThread(AsyncSubject subject) { public void run() { try { // a timeout exception will happen if we don't get a terminal state - String v = subject.toObservable().timeout(2000, TimeUnit.MILLISECONDS).toBlockingObservable().single(); + String v = subject.timeout(2000, TimeUnit.MILLISECONDS).toBlockingObservable().single(); value.set(v); } catch (Exception e) { e.printStackTrace(); diff --git a/rxjava-core/src/test/java/rx/subjects/BehaviorSubjectTest.java b/rxjava-core/src/test/java/rx/subjects/BehaviorSubjectTest.java index 690c9140b1..646e1acc26 100644 --- a/rxjava-core/src/test/java/rx/subjects/BehaviorSubjectTest.java +++ b/rxjava-core/src/test/java/rx/subjects/BehaviorSubjectTest.java @@ -24,7 +24,6 @@ import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; public class BehaviorSubjectTest { @@ -36,7 +35,7 @@ public void testThatObserverReceivesDefaultValueAndSubsequentEvents() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -58,7 +57,7 @@ public void testThatObserverReceivesLatestAndThenSubsequentEvents() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("two"); subject.onNext("three"); @@ -77,7 +76,7 @@ public void testSubscribeThenOnComplete() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onCompleted(); @@ -96,7 +95,7 @@ public void testSubscribeToCompletedOnlyEmitsOnComplete() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); verify(observer, never()).onNext("default"); verify(observer, never()).onNext("one"); @@ -113,7 +112,7 @@ public void testSubscribeToErrorOnlyEmitsOnError() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); verify(observer, never()).onNext("default"); verify(observer, never()).onNext("one"); @@ -131,8 +130,8 @@ public void testCompletedStopsEmittingData() { @SuppressWarnings("unchecked") Observer observerC = mock(Observer.class); - Subscription a = channel.toObservable().subscribe(new TestObserver(observerA)); - Subscription b = channel.toObservable().subscribe(new TestObserver(observerB)); + Subscription a = channel.subscribe(observerA); + Subscription b = channel.subscribe(observerB); InOrder inOrderA = inOrder(observerA); InOrder inOrderB = inOrder(observerB); @@ -157,7 +156,7 @@ public void testCompletedStopsEmittingData() { inOrderB.verify(observerB).onCompleted(); - Subscription c = channel.toObservable().subscribe(new TestObserver(observerC)); + Subscription c = channel.subscribe(observerC); inOrderC.verify(observerC).onCompleted(); @@ -173,7 +172,7 @@ public void testCompletedAfterErrorIsNotSent() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onError(testException); @@ -193,7 +192,7 @@ public void testCompletedAfterErrorIsNotSent2() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onError(testException); @@ -207,7 +206,7 @@ public void testCompletedAfterErrorIsNotSent2() { verify(observer, never()).onCompleted(); Observer o2 = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(o2)); + subject.subscribe(o2); verify(o2, times(1)).onError(testException); verify(o2, never()).onNext(any()); verify(o2, never()).onCompleted(); @@ -219,7 +218,7 @@ public void testCompletedAfterErrorIsNotSent3() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onCompleted(); @@ -233,7 +232,7 @@ public void testCompletedAfterErrorIsNotSent3() { verify(observer, never()).onNext("two"); Observer o2 = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(o2)); + subject.subscribe(o2); verify(o2, times(1)).onCompleted(); verify(o2, never()).onNext(any()); verify(observer, never()).onError(any(Throwable.class)); diff --git a/rxjava-core/src/test/java/rx/subjects/PublishSubjectTest.java b/rxjava-core/src/test/java/rx/subjects/PublishSubjectTest.java index 109ff5f636..b14b9131e6 100644 --- a/rxjava-core/src/test/java/rx/subjects/PublishSubjectTest.java +++ b/rxjava-core/src/test/java/rx/subjects/PublishSubjectTest.java @@ -29,7 +29,6 @@ import rx.Observable; import rx.Observer; import rx.Subscription; -import rx.observers.TestObserver; import rx.util.functions.Action1; import rx.util.functions.Func1; @@ -41,7 +40,7 @@ public void testCompleted() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -50,7 +49,7 @@ public void testCompleted() { @SuppressWarnings("unchecked") Observer anotherObserver = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(anotherObserver)); + subject.subscribe(anotherObserver); subject.onNext("four"); subject.onCompleted(); @@ -70,8 +69,8 @@ public void testCompletedStopsEmittingData() { @SuppressWarnings("unchecked") Observer observerC = mock(Observer.class); - Subscription a = channel.toObservable().subscribe(new TestObserver(observerA)); - Subscription b = channel.toObservable().subscribe(new TestObserver(observerB)); + Subscription a = channel.subscribe(observerA); + Subscription b = channel.subscribe(observerB); InOrder inOrderA = inOrder(observerA); InOrder inOrderB = inOrder(observerB); @@ -93,7 +92,7 @@ public void testCompletedStopsEmittingData() { inOrderB.verify(observerB).onCompleted(); - Subscription c = channel.toObservable().subscribe(new TestObserver(observerC)); + Subscription c = channel.subscribe(observerC); inOrderC.verify(observerC).onCompleted(); @@ -117,7 +116,7 @@ public void testError() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -126,7 +125,7 @@ public void testError() { @SuppressWarnings("unchecked") Observer anotherObserver = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(anotherObserver)); + subject.subscribe(anotherObserver); subject.onNext("four"); subject.onError(new Throwable()); @@ -150,7 +149,7 @@ public void testSubscribeMidSequence() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -159,7 +158,7 @@ public void testSubscribeMidSequence() { @SuppressWarnings("unchecked") Observer anotherObserver = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(anotherObserver)); + subject.subscribe(anotherObserver); subject.onNext("three"); subject.onCompleted(); @@ -182,7 +181,7 @@ public void testUnsubscribeFirstObserver() { @SuppressWarnings("unchecked") Observer observer = mock(Observer.class); - Subscription subscription = subject.toObservable().subscribe(new TestObserver(observer)); + Subscription subscription = subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -192,7 +191,7 @@ public void testUnsubscribeFirstObserver() { @SuppressWarnings("unchecked") Observer anotherObserver = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(anotherObserver)); + subject.subscribe(anotherObserver); subject.onNext("three"); subject.onCompleted(); @@ -219,14 +218,14 @@ public void testNestedSubscribe() { final ArrayList list = new ArrayList(); - s.toObservable().flatMap(new Func1>() { + s.flatMap(new Func1>() { @Override public Observable call(final Integer v) { countParent.incrementAndGet(); // then subscribe to subject again (it will not receive the previous value) - return s.toObservable().map(new Func1() { + return s.map(new Func1() { @Override public String call(Integer v2) { @@ -268,7 +267,7 @@ public void testReSubscribe() { final PublishSubject ps = PublishSubject.create(); Observer o1 = mock(Observer.class); - Subscription s1 = ps.toObservable().subscribe(new TestObserver(o1)); + Subscription s1 = ps.subscribe(o1); // emit ps.onNext(1); @@ -285,7 +284,7 @@ public void testReSubscribe() { ps.onNext(2); Observer o2 = mock(Observer.class); - Subscription s2 = ps.toObservable().subscribe(new TestObserver(o2)); + Subscription s2 = ps.subscribe(o2); // emit ps.onNext(3); diff --git a/rxjava-core/src/test/java/rx/subjects/ReplaySubjectConcurrencyTest.java b/rxjava-core/src/test/java/rx/subjects/ReplaySubjectConcurrencyTest.java index fd76f70f9b..4d941946b5 100644 --- a/rxjava-core/src/test/java/rx/subjects/ReplaySubjectConcurrencyTest.java +++ b/rxjava-core/src/test/java/rx/subjects/ReplaySubjectConcurrencyTest.java @@ -29,6 +29,7 @@ import rx.Observable; import rx.Observable.OnSubscribeFunc; import rx.Observer; +import rx.Subscriber; import rx.Subscription; import rx.subscriptions.Subscriptions; import rx.util.functions.Action1; @@ -71,7 +72,7 @@ public Subscription onSubscribe(Observer o) { }); source.start(); - long v = replay.toObservable().toBlockingObservable().last(); + long v = replay.toBlockingObservable().last(); assertEquals(10000, v); // it's been played through once so now it will all be replays @@ -80,7 +81,7 @@ public Subscription onSubscribe(Observer o) { @Override public void run() { - Observer slow = new Observer() { + Subscriber slow = new Subscriber() { @Override public void onCompleted() { @@ -106,7 +107,7 @@ public void onNext(Long args) { } } }; - replay.toObservable().subscribe(slow); + replay.subscribe(slow); try { slowLatch.await(); } catch (InterruptedException e1) { @@ -121,7 +122,7 @@ public void onNext(Long args) { @Override public void run() { final CountDownLatch fastLatch = new CountDownLatch(1); - Observer fast = new Observer() { + Subscriber fast = new Subscriber() { @Override public void onCompleted() { @@ -140,7 +141,7 @@ public void onNext(Long args) { } } }; - replay.toObservable().subscribe(fast); + replay.subscribe(fast); try { fastLatch.await(); } catch (InterruptedException e1) { @@ -199,7 +200,7 @@ public Subscription onSubscribe(Observer o) { @Override public void run() { - List values = replay.toObservable().toList().toBlockingObservable().last(); + List values = replay.toList().toBlockingObservable().last(); listOfListsOfValues.add(values); System.out.println("Finished thread: " + count); } @@ -250,7 +251,7 @@ public void testSubscribeCompletionRaceCondition() { final ReplaySubject subject = ReplaySubject.create(); final AtomicReference value1 = new AtomicReference(); - subject.toObservable().subscribe(new Action1() { + subject.subscribe(new Action1() { @Override public void call(String t1) { @@ -316,7 +317,7 @@ public SubjectObserverThread(ReplaySubject subject) { public void run() { try { // a timeout exception will happen if we don't get a terminal state - String v = subject.toObservable().timeout(2000, TimeUnit.MILLISECONDS).toBlockingObservable().single(); + String v = subject.timeout(2000, TimeUnit.MILLISECONDS).toBlockingObservable().single(); value.set(v); } catch (Exception e) { e.printStackTrace(); diff --git a/rxjava-core/src/test/java/rx/subjects/ReplaySubjectTest.java b/rxjava-core/src/test/java/rx/subjects/ReplaySubjectTest.java index 87cfdb4b8d..14a6bbb039 100644 --- a/rxjava-core/src/test/java/rx/subjects/ReplaySubjectTest.java +++ b/rxjava-core/src/test/java/rx/subjects/ReplaySubjectTest.java @@ -27,8 +27,8 @@ import org.mockito.Mockito; import rx.Observer; +import rx.Subscriber; import rx.Subscription; -import rx.observers.TestObserver; import rx.schedulers.Schedulers; public class ReplaySubjectTest { @@ -41,7 +41,7 @@ public void testCompleted() { ReplaySubject subject = ReplaySubject.create(); Observer o1 = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(o1)); + subject.subscribe(o1); subject.onNext("one"); subject.onNext("two"); @@ -56,7 +56,7 @@ public void testCompleted() { // assert that subscribing a 2nd time gets the same data Observer o2 = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(o2)); + subject.subscribe(o2); assertCompletedObserver(o2); } @@ -72,8 +72,8 @@ public void testCompletedStopsEmittingData() { @SuppressWarnings("unchecked") Observer observerD = mock(Observer.class); - Subscription a = channel.toObservable().subscribe(new TestObserver(observerA)); - Subscription b = channel.toObservable().subscribe(new TestObserver(observerB)); + Subscription a = channel.subscribe(observerA); + Subscription b = channel.subscribe(observerB); InOrder inOrderA = inOrder(observerA); InOrder inOrderB = inOrder(observerB); @@ -101,7 +101,7 @@ public void testCompletedStopsEmittingData() { // B is subscribed so should receive onCompleted inOrderB.verify(observerB).onCompleted(); - Subscription c = channel.toObservable().subscribe(new TestObserver(observerC)); + Subscription c = channel.subscribe(observerC); // when C subscribes it should receive 42, 4711, onCompleted inOrderC.verify(observerC).onNext(42); @@ -115,7 +115,7 @@ public void testCompletedStopsEmittingData() { channel.onError(new RuntimeException()); // a new subscription should only receive what was emitted prior to terminal state onCompleted - Subscription d = channel.toObservable().subscribe(new TestObserver(observerD)); + Subscription d = channel.subscribe(observerD); inOrderD.verify(observerD).onNext(42); inOrderD.verify(observerD).onNext(4711); @@ -141,7 +141,7 @@ public void testCompletedAfterError() { subject.onCompleted(); subject.onError(new RuntimeException()); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onError(testException); verifyNoMoreInteractions(observer); @@ -164,7 +164,7 @@ public void testError() { ReplaySubject subject = ReplaySubject.create(); Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -178,7 +178,7 @@ public void testError() { assertErrorObserver(observer); observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); assertErrorObserver(observer); } @@ -196,7 +196,7 @@ public void testSubscribeMidSequence() { ReplaySubject subject = ReplaySubject.create(); Observer observer = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(observer)); + subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -204,7 +204,7 @@ public void testSubscribeMidSequence() { assertObservedUntilTwo(observer); Observer anotherObserver = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(anotherObserver)); + subject.subscribe(anotherObserver); assertObservedUntilTwo(anotherObserver); subject.onNext("three"); @@ -220,7 +220,7 @@ public void testUnsubscribeFirstObserver() { ReplaySubject subject = ReplaySubject.create(); Observer observer = mock(Observer.class); - Subscription subscription = subject.toObservable().subscribe(new TestObserver(observer)); + Subscription subscription = subject.subscribe(observer); subject.onNext("one"); subject.onNext("two"); @@ -229,7 +229,7 @@ public void testUnsubscribeFirstObserver() { assertObservedUntilTwo(observer); Observer anotherObserver = mock(Observer.class); - subject.toObservable().subscribe(new TestObserver(anotherObserver)); + subject.subscribe(anotherObserver); assertObservedUntilTwo(anotherObserver); subject.onNext("three"); @@ -251,7 +251,7 @@ private void assertObservedUntilTwo(Observer observer) { public void testNewSubscriberDoesntBlockExisting() throws InterruptedException { final AtomicReference lastValueForObserver1 = new AtomicReference(); - Observer observer1 = new Observer() { + Subscriber observer1 = new Subscriber() { @Override public void onCompleted() { @@ -275,7 +275,7 @@ public void onNext(String v) { final CountDownLatch oneReceived = new CountDownLatch(1); final CountDownLatch makeSlow = new CountDownLatch(1); final CountDownLatch completed = new CountDownLatch(1); - Observer observer2 = new Observer() { + Subscriber observer2 = new Subscriber() { @Override public void onCompleted() { @@ -305,13 +305,13 @@ public void onNext(String v) { }; ReplaySubject subject = ReplaySubject.create(); - Subscription s1 = subject.toObservable().subscribe(new TestObserver(observer1)); + Subscription s1 = subject.subscribe(observer1); subject.onNext("one"); assertEquals("one", lastValueForObserver1.get()); subject.onNext("two"); assertEquals("two", lastValueForObserver1.get()); - Subscription s2 = subject.toObservable().observeOn(Schedulers.newThread()).subscribe(new TestObserver(observer2)); + Subscription s2 = subject.observeOn(Schedulers.newThread()).subscribe(observer2); System.out.println("before waiting for one");