From 71f01542c943d99947be3b707c8c3aa2ae9d83b2 Mon Sep 17 00:00:00 2001 From: Matt Wysocki Date: Fri, 22 Sep 2017 15:26:49 -0700 Subject: [PATCH] Fix checkstyle --- .../AutoDisposingCompletableObserverImpl.java | 1 - .../AutoDisposingMaybeObserverImpl.java | 1 - .../AutoDisposingSingleObserverImpl.java | 1 - .../AutoDisposingSubscriberImpl.java | 1 - .../AutoDisposingCompletableObserver.java | 10 +-- .../observers/AutoDisposingMaybeObserver.java | 10 +-- .../observers/AutoDisposingObserver.java | 8 +- .../AutoDisposingSingleObserver.java | 10 +-- .../observers/AutoDisposingSubscriber.java | 12 +-- .../AutoDisposeCompletableObserverTest.java | 87 +++++++++++------- .../AutoDisposeMaybeObserverTest.java | 89 ++++++++++++------- .../autodispose/AutoDisposeObserverTest.java | 5 +- .../AutoDisposeSingleObserverTest.java | 81 +++++++++++------ .../AutoDisposeSubscriberTest.java | 10 +-- 14 files changed, 201 insertions(+), 125 deletions(-) diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingCompletableObserverImpl.java b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingCompletableObserverImpl.java index e7579e21a..00b956718 100755 --- a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingCompletableObserverImpl.java +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingCompletableObserverImpl.java @@ -19,7 +19,6 @@ import com.uber.autodispose.observers.AutoDisposingCompletableObserver; import io.reactivex.CompletableObserver; import io.reactivex.Maybe; -import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import io.reactivex.functions.BiConsumer; diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingMaybeObserverImpl.java b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingMaybeObserverImpl.java index 79c9a8ed5..2fd67be6e 100755 --- a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingMaybeObserverImpl.java +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingMaybeObserverImpl.java @@ -19,7 +19,6 @@ import com.uber.autodispose.observers.AutoDisposingMaybeObserver; import io.reactivex.Maybe; import io.reactivex.MaybeObserver; -import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import io.reactivex.functions.BiConsumer; diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSingleObserverImpl.java b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSingleObserverImpl.java index a32347be4..e72980843 100755 --- a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSingleObserverImpl.java +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSingleObserverImpl.java @@ -18,7 +18,6 @@ import com.uber.autodispose.observers.AutoDisposingSingleObserver; import io.reactivex.Maybe; -import io.reactivex.Observer; import io.reactivex.SingleObserver; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; diff --git a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java index 7f5bd43f6..151b6d643 100755 --- a/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java +++ b/autodispose/src/main/java/com/uber/autodispose/AutoDisposingSubscriberImpl.java @@ -18,7 +18,6 @@ import com.uber.autodispose.observers.AutoDisposingSubscriber; import io.reactivex.Maybe; -import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.BiConsumer; import io.reactivex.functions.Consumer; diff --git a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingCompletableObserver.java b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingCompletableObserver.java index e13e4cdcf..003c4dc44 100644 --- a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingCompletableObserver.java +++ b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingCompletableObserver.java @@ -17,7 +17,6 @@ package com.uber.autodispose.observers; import io.reactivex.CompletableObserver; -import io.reactivex.Observer; import io.reactivex.disposables.Disposable; /** @@ -26,8 +25,9 @@ */ public interface AutoDisposingCompletableObserver extends CompletableObserver, Disposable { - /** - * @return The delegate {@link CompletableObserver} that is used under the hood for introspection purposes. - */ - CompletableObserver delegateObserver(); + /** + * @return The delegate {@link CompletableObserver} that is used under the hood forintrospection + * purposes. + */ + CompletableObserver delegateObserver(); } diff --git a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingMaybeObserver.java b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingMaybeObserver.java index 951781614..0e8df02e8 100644 --- a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingMaybeObserver.java +++ b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingMaybeObserver.java @@ -17,7 +17,6 @@ package com.uber.autodispose.observers; import io.reactivex.MaybeObserver; -import io.reactivex.Observer; import io.reactivex.disposables.Disposable; /** @@ -26,8 +25,9 @@ */ public interface AutoDisposingMaybeObserver extends MaybeObserver, Disposable { - /** - * @return The delegate {@link MayberObserver} that is used under the hood for introspection purposes. - */ - MaybeObserver delegateObserver(); + /** + * @return The delegate {@link MayberObserver} that is used under the hood for introspection + * purposes. + */ + MaybeObserver delegateObserver(); } diff --git a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingObserver.java b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingObserver.java index 5096bc7a7..7f98c7443 100644 --- a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingObserver.java +++ b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingObserver.java @@ -25,8 +25,8 @@ */ public interface AutoDisposingObserver extends Observer, Disposable { - /** - * @return The delegate {@link Observer} that is used under the hood for introspection purposes. - */ - Observer delegateObserver(); + /** + * @return The delegate {@link Observer} that is used under the hood for introspection purposes. + */ + Observer delegateObserver(); } diff --git a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSingleObserver.java b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSingleObserver.java index 3b3871f84..d5dabbd47 100644 --- a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSingleObserver.java +++ b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSingleObserver.java @@ -16,7 +16,6 @@ package com.uber.autodispose.observers; -import io.reactivex.Observer; import io.reactivex.SingleObserver; import io.reactivex.disposables.Disposable; @@ -26,8 +25,9 @@ */ public interface AutoDisposingSingleObserver extends SingleObserver, Disposable { - /** - * @return The delegate {@link SingleObserver} that is used under the hood for introspection purposes. - */ - SingleObserver delegateObserver(); + /** + * @return The delegate {@link SingleObserver} that is used under the hood for introspection + * purposes. + */ + SingleObserver delegateObserver(); } diff --git a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSubscriber.java b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSubscriber.java index df9fb9169..ddbe754c7 100644 --- a/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSubscriber.java +++ b/autodispose/src/main/java/com/uber/autodispose/observers/AutoDisposingSubscriber.java @@ -25,10 +25,12 @@ * A {@link Disposable} {@link Subscriber} that can automatically dispose itself. Interface here * for type safety but enforcement is left to the implementation. */ -public interface AutoDisposingSubscriber extends FlowableSubscriber, Subscription, Disposable { +public interface AutoDisposingSubscriber + extends FlowableSubscriber, Subscription, Disposable { - /** - * @return The delegate {@link Subscriber} that is used under the hood for introspection purposes. - */ - Subscriber delegateSubscriber(); + /** + * @return The delegate {@link Subscriber} that is used under the hood for introspection + * purposes. + */ + Subscriber delegateSubscriber(); } diff --git a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeCompletableObserverTest.java b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeCompletableObserverTest.java index 987b4c10f..9eef4e9cc 100755 --- a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeCompletableObserverTest.java +++ b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeCompletableObserverTest.java @@ -24,8 +24,6 @@ import io.reactivex.CompletableObserver; import io.reactivex.CompletableOnSubscribe; import io.reactivex.Maybe; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.functions.BiFunction; import io.reactivex.functions.Cancellable; import io.reactivex.functions.Consumer; @@ -35,6 +33,7 @@ import io.reactivex.subjects.BehaviorSubject; import io.reactivex.subjects.CompletableSubject; import io.reactivex.subjects.MaybeSubject; + import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -48,16 +47,19 @@ public class AutoDisposeCompletableObserverTest { private static final RecordingObserver.Logger LOGGER = new RecordingObserver.Logger() { - @Override public void log(String message) { + @Override + public void log(String message) { System.out.println(AutoDisposeCompletableObserverTest.class.getSimpleName() + ": " + message); } }; - @After public void resetPlugins() { + @After + public void resetPlugins() { AutoDisposePlugins.reset(); } - @Test public void autoDispose_withMaybe_normal() { + @Test + public void autoDispose_withMaybe_normal() { RecordingObserver o = new RecordingObserver<>(LOGGER); CompletableSubject source = CompletableSubject.create(); MaybeSubject lifecycle = MaybeSubject.create(); @@ -78,7 +80,8 @@ public class AutoDisposeCompletableObserverTest { assertThat(lifecycle.hasObservers()).isFalse(); } - @Test public void autoDispose_withMaybe_interrupted() { + @Test + public void autoDispose_withMaybe_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); CompletableSubject source = CompletableSubject.create(); MaybeSubject lifecycle = MaybeSubject.create(); @@ -99,7 +102,8 @@ public class AutoDisposeCompletableObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withProvider_completion() { + @Test + public void autoDispose_withProvider_completion() { RecordingObserver o = new RecordingObserver<>(LOGGER); CompletableSubject source = CompletableSubject.create(); MaybeSubject scope = MaybeSubject.create(); @@ -119,7 +123,8 @@ public class AutoDisposeCompletableObserverTest { assertThat(scope.hasObservers()).isFalse(); } - @Test public void autoDispose_withProvider_interrupted() { + @Test + public void autoDispose_withProvider_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); CompletableSubject source = CompletableSubject.create(); MaybeSubject scope = MaybeSubject.create(); @@ -142,7 +147,8 @@ public class AutoDisposeCompletableObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withLifecycleProvider_completion() { + @Test + public void autoDispose_withLifecycleProvider_completion() { RecordingObserver o = new RecordingObserver<>(LOGGER); CompletableSubject source = CompletableSubject.create(); BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); @@ -167,7 +173,8 @@ public class AutoDisposeCompletableObserverTest { assertThat(lifecycle.hasObservers()).isFalse(); } - @Test public void autoDispose_withLifecycleProvider_interrupted() { + @Test + public void autoDispose_withLifecycleProvider_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); CompletableSubject source = CompletableSubject.create(); BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); @@ -195,7 +202,8 @@ public class AutoDisposeCompletableObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withLifecycleProvider_withoutStartingLifecycle_shouldFail() { + @Test + public void autoDispose_withLifecycleProvider_withoutStartingLifecycle_shouldFail() { BehaviorSubject lifecycle = BehaviorSubject.create(); RecordingObserver o = new RecordingObserver<>(LOGGER); LifecycleScopeProvider provider = makeLifecycleProvider(lifecycle); @@ -207,7 +215,8 @@ public class AutoDisposeCompletableObserverTest { assertThat(o.takeError()).isInstanceOf(LifecycleNotStartedException.class); } - @Test public void autoDispose_withLifecycleProvider_afterLifecycle_shouldFail() { + @Test + public void autoDispose_withLifecycleProvider_afterLifecycle_shouldFail() { BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); lifecycle.onNext(1); lifecycle.onNext(2); @@ -222,9 +231,11 @@ public class AutoDisposeCompletableObserverTest { assertThat(o.takeError()).isInstanceOf(LifecycleEndedException.class); } - @Test public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() { + @Test + public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { } + @Override + public void accept(OutsideLifecycleException e) throws Exception { } }); BehaviorSubject lifecycle = BehaviorSubject.create(); TestObserver o = new TestObserver<>(); @@ -239,9 +250,11 @@ public class AutoDisposeCompletableObserverTest { o.assertNoErrors(); } - @Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() { + @Test + public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { + @Override + public void accept(OutsideLifecycleException e) throws Exception { // Noop } }); @@ -261,9 +274,11 @@ public class AutoDisposeCompletableObserverTest { o.assertNoErrors(); } - @Test public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp() { + @Test + public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { + @Override + public void accept(OutsideLifecycleException e) throws Exception { // Wrap in an IllegalStateException so we can verify this is the exception we see on the // other side throw new IllegalStateException(e); @@ -278,19 +293,26 @@ public class AutoDisposeCompletableObserverTest { o.assertNoValues(); o.assertError(new Predicate() { - @Override public boolean test(Throwable throwable) throws Exception { + @Override + public boolean test(Throwable throwable) throws Exception { return throwable instanceof IllegalStateException && throwable.getCause() instanceof OutsideLifecycleException; } }); } - @Test public void verifyObserverDelegate() { + @Test + public void verifyObserverDelegate() { final AtomicReference atomicObserver = new AtomicReference<>(); - final AtomicReference atomicAutoDisposingObserver = new AtomicReference<>(); + final AtomicReference atomicAutoDisposingObserver + = new AtomicReference<>(); try { - RxJavaPlugins.setOnCompletableSubscribe(new BiFunction() { - @Override public CompletableObserver apply(Completable source, CompletableObserver observer) { + RxJavaPlugins.setOnCompletableSubscribe(new BiFunction() { + @Override public CompletableObserver apply( + Completable source, + CompletableObserver observer) { if (atomicObserver.get() == null) { atomicObserver.set(observer); } else if (atomicAutoDisposingObserver.get() == null) { @@ -303,22 +325,27 @@ public class AutoDisposeCompletableObserverTest { Completable.complete().to(new CompletableScoper(Maybe.never())).subscribe(); assertThat(atomicAutoDisposingObserver.get()).isNotNull(); - assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(AutoDisposingCompletableObserver.class); - assertThat(((AutoDisposingCompletableObserver)atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull(); - assertThat(((AutoDisposingCompletableObserver)atomicAutoDisposingObserver.get()).delegateObserver()) - .isSameAs(atomicObserver.get()); + assertThat(atomicAutoDisposingObserver.get()) + .isInstanceOf(AutoDisposingCompletableObserver.class); + assertThat(((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get()) + .delegateObserver()).isNotNull(); + assertThat(((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get()) + .delegateObserver()).isSameAs(atomicObserver.get()); } finally { RxJavaPlugins.reset(); } } - @Test public void verifyCancellation() throws Exception { + @Test + public void verifyCancellation() throws Exception { final AtomicInteger i = new AtomicInteger(); //noinspection unchecked because Java Completable source = Completable.create(new CompletableOnSubscribe() { - @Override public void subscribe(CompletableEmitter e) throws Exception { + @Override + public void subscribe(CompletableEmitter e) throws Exception { e.setCancellable(new Cancellable() { - @Override public void cancel() throws Exception { + @Override + public void cancel() throws Exception { i.incrementAndGet(); } }); diff --git a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeMaybeObserverTest.java b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeMaybeObserverTest.java index f66799f35..b9959b136 100755 --- a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeMaybeObserverTest.java +++ b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeMaybeObserverTest.java @@ -19,13 +19,10 @@ import com.uber.autodispose.test.RecordingObserver; import com.uber.autodispose.observers.AutoDisposingMaybeObserver; -import io.reactivex.CompletableObserver; import io.reactivex.Maybe; import io.reactivex.MaybeEmitter; import io.reactivex.MaybeObserver; import io.reactivex.MaybeOnSubscribe; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.functions.BiFunction; import io.reactivex.functions.Cancellable; import io.reactivex.functions.Consumer; @@ -34,6 +31,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.BehaviorSubject; import io.reactivex.subjects.MaybeSubject; + import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -47,16 +45,19 @@ public class AutoDisposeMaybeObserverTest { private static final RecordingObserver.Logger LOGGER = new RecordingObserver.Logger() { - @Override public void log(String message) { + @Override + public void log(String message) { System.out.println(AutoDisposeMaybeObserverTest.class.getSimpleName() + ": " + message); } }; - @After public void resetPlugins() { + @After + public void resetPlugins() { AutoDisposePlugins.reset(); } - @Test public void autoDispose_withMaybe_normal() { + @Test + public void autoDispose_withMaybe_normal() { RecordingObserver o = new RecordingObserver<>(LOGGER); MaybeSubject source = MaybeSubject.create(); MaybeSubject lifecycle = MaybeSubject.create(); @@ -77,23 +78,27 @@ public class AutoDisposeMaybeObserverTest { assertThat(lifecycle.hasObservers()).isFalse(); } - @Test public void autoDispose_withSuperClassGenerics_compilesFine() { + @Test + public void autoDispose_withSuperClassGenerics_compilesFine() { Maybe.just(new BClass()) .to(new MaybeScoper(Maybe.never())) .subscribe(new Consumer() { - @Override public void accept(AClass aClass) throws Exception { + @Override + public void accept(AClass aClass) throws Exception { } }); } - @Test public void autoDispose_noGenericsOnEmpty_isFine() { + @Test + public void autoDispose_noGenericsOnEmpty_isFine() { Maybe.just(new BClass()) .to(new MaybeScoper<>(Maybe.never())) .subscribe(); } - @Test public void autoDispose_withMaybe_interrupted() { + @Test + public void autoDispose_withMaybe_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); MaybeSubject source = MaybeSubject.create(); MaybeSubject lifecycle = MaybeSubject.create(); @@ -101,7 +106,8 @@ public class AutoDisposeMaybeObserverTest { .subscribe(o); source.to(new MaybeScoper(lifecycle)) .subscribe(new Consumer() { - @Override public void accept(Integer integer) throws Exception { + @Override + public void accept(Integer integer) throws Exception { } }); @@ -120,7 +126,8 @@ public class AutoDisposeMaybeObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withProvider_success() { + @Test + public void autoDispose_withProvider_success() { RecordingObserver o = new RecordingObserver<>(LOGGER); MaybeSubject source = MaybeSubject.create(); BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); @@ -145,7 +152,8 @@ public class AutoDisposeMaybeObserverTest { assertThat(lifecycle.hasObservers()).isFalse(); } - @Test public void autoDispose_withProvider_completion() { + @Test + public void autoDispose_withProvider_completion() { RecordingObserver o = new RecordingObserver<>(LOGGER); MaybeSubject source = MaybeSubject.create(); MaybeSubject scope = MaybeSubject.create(); @@ -165,7 +173,8 @@ public class AutoDisposeMaybeObserverTest { assertThat(scope.hasObservers()).isFalse(); } - @Test public void autoDispose_withProvider_interrupted() { + @Test + public void autoDispose_withProvider_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); MaybeSubject source = MaybeSubject.create(); MaybeSubject scope = MaybeSubject.create(); @@ -188,7 +197,8 @@ public class AutoDisposeMaybeObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withLifecycleProvider_completion() { + @Test + public void autoDispose_withLifecycleProvider_completion() { RecordingObserver o = new RecordingObserver<>(LOGGER); MaybeSubject source = MaybeSubject.create(); BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); @@ -213,7 +223,8 @@ public class AutoDisposeMaybeObserverTest { assertThat(lifecycle.hasObservers()).isFalse(); } - @Test public void autoDispose_withLifecycleProvider_interrupted() { + @Test + public void autoDispose_withLifecycleProvider_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); MaybeSubject source = MaybeSubject.create(); BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); @@ -241,7 +252,8 @@ public class AutoDisposeMaybeObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withLifecycleProvider_withoutStartingLifecycle_shouldFail() { + @Test + public void autoDispose_withLifecycleProvider_withoutStartingLifecycle_shouldFail() { BehaviorSubject lifecycle = BehaviorSubject.create(); RecordingObserver o = new RecordingObserver<>(LOGGER); LifecycleScopeProvider provider = makeLifecycleProvider(lifecycle); @@ -253,7 +265,8 @@ public class AutoDisposeMaybeObserverTest { assertThat(o.takeError()).isInstanceOf(LifecycleNotStartedException.class); } - @Test public void autoDispose_withLifecycleProvider_afterLifecycle_shouldFail() { + @Test + public void autoDispose_withLifecycleProvider_afterLifecycle_shouldFail() { BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); lifecycle.onNext(1); lifecycle.onNext(2); @@ -268,9 +281,11 @@ public class AutoDisposeMaybeObserverTest { assertThat(o.takeError()).isInstanceOf(LifecycleEndedException.class); } - @Test public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() { + @Test + public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { } + @Override + public void accept(OutsideLifecycleException e) throws Exception { } }); BehaviorSubject lifecycle = BehaviorSubject.create(); TestObserver o = new TestObserver<>(); @@ -285,9 +300,11 @@ public class AutoDisposeMaybeObserverTest { o.assertNoErrors(); } - @Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() { + @Test + public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { + @Override + public void accept(OutsideLifecycleException e) throws Exception { // Noop } }); @@ -307,9 +324,11 @@ public class AutoDisposeMaybeObserverTest { o.assertNoErrors(); } - @Test public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp() { + @Test + public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { + @Override + public void accept(OutsideLifecycleException e) throws Exception { // Wrap in an IllegalStateException so we can verify this is the exception we see on the // other side throw new IllegalStateException(e); @@ -324,14 +343,16 @@ public class AutoDisposeMaybeObserverTest { o.assertNoValues(); o.assertError(new Predicate() { - @Override public boolean test(Throwable throwable) throws Exception { + @Override + public boolean test(Throwable throwable) throws Exception { return throwable instanceof IllegalStateException && throwable.getCause() instanceof OutsideLifecycleException; } }); } - @Test public void verifyObserverDelegate() { + @Test + public void verifyObserverDelegate() { final AtomicReference atomicObserver = new AtomicReference<>(); final AtomicReference atomicAutoDisposingObserver = new AtomicReference<>(); try { @@ -350,21 +371,25 @@ public class AutoDisposeMaybeObserverTest { assertThat(atomicAutoDisposingObserver.get()).isNotNull(); assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(AutoDisposingMaybeObserver.class); - assertThat(((AutoDisposingMaybeObserver)atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull(); - assertThat(((AutoDisposingMaybeObserver)atomicAutoDisposingObserver.get()).delegateObserver()) - .isSameAs(atomicObserver.get()); + assertThat(((AutoDisposingMaybeObserver) atomicAutoDisposingObserver.get()) + .delegateObserver()).isNotNull(); + assertThat(((AutoDisposingMaybeObserver) atomicAutoDisposingObserver.get()) + .delegateObserver()).isSameAs(atomicObserver.get()); } finally { RxJavaPlugins.reset(); } } - @Test public void verifyCancellation() throws Exception { + @Test + public void verifyCancellation() throws Exception { final AtomicInteger i = new AtomicInteger(); //noinspection unchecked because Java Maybe source = Maybe.create(new MaybeOnSubscribe() { - @Override public void subscribe(MaybeEmitter e) throws Exception { + @Override + public void subscribe(MaybeEmitter e) throws Exception { e.setCancellable(new Cancellable() { - @Override public void cancel() throws Exception { + @Override + public void cancel() throws Exception { i.incrementAndGet(); } }); diff --git a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeObserverTest.java b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeObserverTest.java index a275d8d66..2871b10f4 100755 --- a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeObserverTest.java +++ b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeObserverTest.java @@ -280,8 +280,9 @@ public class AutoDisposeObserverTest { assertThat(atomicAutoDisposingObserver.get()).isNotNull(); assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(AutoDisposingObserver.class); - assertThat(((AutoDisposingObserver)atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull(); - assertThat(((AutoDisposingObserver)atomicAutoDisposingObserver.get()).delegateObserver()) + assertThat(((AutoDisposingObserver) atomicAutoDisposingObserver.get()).delegateObserver()) + .isNotNull(); + assertThat(((AutoDisposingObserver) atomicAutoDisposingObserver.get()).delegateObserver()) .isSameAs(atomicObserver.get()); } finally { RxJavaPlugins.reset(); diff --git a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSingleObserverTest.java b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSingleObserverTest.java index 1a7b3b18d..7f137fb61 100755 --- a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSingleObserverTest.java +++ b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSingleObserverTest.java @@ -18,6 +18,7 @@ import com.uber.autodispose.test.RecordingObserver; import com.uber.autodispose.observers.AutoDisposingSingleObserver; + import io.reactivex.Maybe; import io.reactivex.Single; import io.reactivex.SingleEmitter; @@ -32,6 +33,7 @@ import io.reactivex.subjects.BehaviorSubject; import io.reactivex.subjects.MaybeSubject; import io.reactivex.subjects.SingleSubject; + import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -45,16 +47,19 @@ public class AutoDisposeSingleObserverTest { private static final RecordingObserver.Logger LOGGER = new RecordingObserver.Logger() { - @Override public void log(String message) { + @Override + public void log(String message) { System.out.println(AutoDisposeSingleObserverTest.class.getSimpleName() + ": " + message); } }; - @After public void resetPlugins() { + @After + public void resetPlugins() { AutoDisposePlugins.reset(); } - @Test public void autoDispose_withMaybe_normal() { + @Test + public void autoDispose_withMaybe_normal() { RecordingObserver o = new RecordingObserver<>(LOGGER); SingleSubject source = SingleSubject.create(); MaybeSubject lifecycle = MaybeSubject.create(); @@ -75,23 +80,27 @@ public class AutoDisposeSingleObserverTest { assertThat(lifecycle.hasObservers()).isFalse(); } - @Test public void autoDispose_withSuperClassGenerics_compilesFine() { + @Test + public void autoDispose_withSuperClassGenerics_compilesFine() { Single.just(new BClass()) .to(new SingleScoper(Maybe.never())) .subscribe(new Consumer() { - @Override public void accept(AClass aClass) throws Exception { + @Override + public void accept(AClass aClass) throws Exception { } }); } - @Test public void autoDispose_noGenericsOnEmpty_isFine() { + @Test + public void autoDispose_noGenericsOnEmpty_isFine() { Single.just(new BClass()) .to(new SingleScoper<>(Maybe.never())) .subscribe(); } - @Test public void autoDispose_withMaybe_interrupted() { + @Test + public void autoDispose_withMaybe_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); SingleSubject source = SingleSubject.create(); MaybeSubject lifecycle = MaybeSubject.create(); @@ -112,7 +121,8 @@ public class AutoDisposeSingleObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withProvider() { + @Test + public void autoDispose_withProvider() { RecordingObserver o = new RecordingObserver<>(LOGGER); SingleSubject source = SingleSubject.create(); MaybeSubject scope = MaybeSubject.create(); @@ -133,7 +143,8 @@ public class AutoDisposeSingleObserverTest { assertThat(scope.hasObservers()).isFalse(); } - @Test public void autoDispose_withProvider_interrupted() { + @Test + public void autoDispose_withProvider_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); SingleSubject source = SingleSubject.create(); MaybeSubject scope = MaybeSubject.create(); @@ -155,7 +166,8 @@ public class AutoDisposeSingleObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withLifecycleProvider() { + @Test + public void autoDispose_withLifecycleProvider() { RecordingObserver o = new RecordingObserver<>(LOGGER); SingleSubject source = SingleSubject.create(); BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); @@ -181,7 +193,8 @@ public class AutoDisposeSingleObserverTest { assertThat(lifecycle.hasObservers()).isFalse(); } - @Test public void autoDispose_withLifecycleProvider_interrupted() { + @Test + public void autoDispose_withLifecycleProvider_interrupted() { RecordingObserver o = new RecordingObserver<>(LOGGER); SingleSubject source = SingleSubject.create(); BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); @@ -208,7 +221,8 @@ public class AutoDisposeSingleObserverTest { o.assertNoMoreEvents(); } - @Test public void autoDispose_withProvider_withoutStartingLifecycle_shouldFail() { + @Test + public void autoDispose_withProvider_withoutStartingLifecycle_shouldFail() { BehaviorSubject lifecycle = BehaviorSubject.create(); RecordingObserver o = new RecordingObserver<>(LOGGER); LifecycleScopeProvider provider = makeLifecycleProvider(lifecycle); @@ -220,7 +234,8 @@ public class AutoDisposeSingleObserverTest { assertThat(o.takeError()).isInstanceOf(LifecycleNotStartedException.class); } - @Test public void autoDispose_withProvider_afterLifecycle_shouldFail() { + @Test + public void autoDispose_withProvider_afterLifecycle_shouldFail() { BehaviorSubject lifecycle = BehaviorSubject.createDefault(0); lifecycle.onNext(1); lifecycle.onNext(2); @@ -235,9 +250,11 @@ public class AutoDisposeSingleObserverTest { assertThat(o.takeError()).isInstanceOf(LifecycleEndedException.class); } - @Test public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() { + @Test + public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { } + @Override + public void accept(OutsideLifecycleException e) throws Exception { } }); BehaviorSubject lifecycle = BehaviorSubject.create(); TestObserver o = new TestObserver<>(); @@ -252,9 +269,11 @@ public class AutoDisposeSingleObserverTest { o.assertNoErrors(); } - @Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() { + @Test + public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { + @Override + public void accept(OutsideLifecycleException e) throws Exception { // Noop } }); @@ -274,9 +293,11 @@ public class AutoDisposeSingleObserverTest { o.assertNoErrors(); } - @Test public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithExp() { + @Test + public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithExp() { AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer() { - @Override public void accept(OutsideLifecycleException e) throws Exception { + @Override + public void accept(OutsideLifecycleException e) throws Exception { // Wrap in an IllegalStateException so we can verify this is the exception we see on the // other side throw new IllegalStateException(e); @@ -291,14 +312,16 @@ public class AutoDisposeSingleObserverTest { o.assertNoValues(); o.assertError(new Predicate() { - @Override public boolean test(Throwable throwable) throws Exception { + @Override + public boolean test(Throwable throwable) throws Exception { return throwable instanceof IllegalStateException && throwable.getCause() instanceof OutsideLifecycleException; } }); } - @Test public void verifyObserverDelegate() { + @Test + public void verifyObserverDelegate() { final AtomicReference atomicObserver = new AtomicReference<>(); final AtomicReference atomicAutoDisposingObserver = new AtomicReference<>(); try { @@ -317,21 +340,25 @@ public class AutoDisposeSingleObserverTest { assertThat(atomicAutoDisposingObserver.get()).isNotNull(); assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(AutoDisposingSingleObserver.class); - assertThat(((AutoDisposingSingleObserver)atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull(); - assertThat(((AutoDisposingSingleObserver)atomicAutoDisposingObserver.get()).delegateObserver()) - .isSameAs(atomicObserver.get()); + assertThat(((AutoDisposingSingleObserver) atomicAutoDisposingObserver.get()) + .delegateObserver()).isNotNull(); + assertThat(((AutoDisposingSingleObserver) atomicAutoDisposingObserver.get()) + .delegateObserver()).isSameAs(atomicObserver.get()); } finally { RxJavaPlugins.reset(); } } - @Test public void verifyCancellation() throws Exception { + @Test + public void verifyCancellation() throws Exception { final AtomicInteger i = new AtomicInteger(); //noinspection unchecked because Java Single source = Single.create(new SingleOnSubscribe() { - @Override public void subscribe(SingleEmitter e) throws Exception { + @Override + public void subscribe(SingleEmitter e) throws Exception { e.setCancellable(new Cancellable() { - @Override public void cancel() throws Exception { + @Override + public void cancel() throws Exception { i.incrementAndGet(); } }); diff --git a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSubscriberTest.java b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSubscriberTest.java index f166ee48d..179ce0cbe 100755 --- a/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSubscriberTest.java +++ b/autodispose/src/test/java/com/uber/autodispose/AutoDisposeSubscriberTest.java @@ -23,9 +23,6 @@ import io.reactivex.FlowableEmitter; import io.reactivex.FlowableOnSubscribe; import io.reactivex.Maybe; -import io.reactivex.MaybeObserver; -import io.reactivex.Single; -import io.reactivex.SingleObserver; import io.reactivex.disposables.Disposable; import io.reactivex.functions.BiFunction; import io.reactivex.functions.Cancellable; @@ -294,9 +291,10 @@ public class AutoDisposeSubscriberTest { assertThat(atomicAutoDisposingSubscriber.get()).isNotNull(); assertThat(atomicAutoDisposingSubscriber.get()).isInstanceOf(AutoDisposingSubscriber.class); - assertThat(((AutoDisposingSubscriber)atomicAutoDisposingSubscriber.get()).delegateSubscriber()).isNotNull(); - assertThat(((AutoDisposingSubscriber)atomicAutoDisposingSubscriber.get()).delegateSubscriber()) - .isSameAs(atomicSubscriber.get()); + assertThat(((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get()) + .delegateSubscriber()).isNotNull(); + assertThat(((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get()) + .delegateSubscriber()).isSameAs(atomicSubscriber.get()); } finally { RxJavaPlugins.reset(); }