Skip to content

Commit

Permalink
Fix checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Wysocki committed Sep 22, 2017
1 parent 7270758 commit 71f0154
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.uber.autodispose.observers;

import io.reactivex.CompletableObserver;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
Expand All @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.uber.autodispose.observers;

import io.reactivex.MaybeObserver;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
Expand All @@ -26,8 +25,9 @@
*/
public interface AutoDisposingMaybeObserver<T> extends MaybeObserver<T>, Disposable {

/**
* @return The delegate {@link MayberObserver} that is used under the hood for introspection purposes.
*/
MaybeObserver<? super T> delegateObserver();
/**
* @return The delegate {@link MayberObserver} that is used under the hood for introspection
* purposes.
*/
MaybeObserver<? super T> delegateObserver();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
public interface AutoDisposingObserver<T> extends Observer<T>, Disposable {

/**
* @return The delegate {@link Observer} that is used under the hood for introspection purposes.
*/
Observer<? super T> delegateObserver();
/**
* @return The delegate {@link Observer} that is used under the hood for introspection purposes.
*/
Observer<? super T> delegateObserver();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.uber.autodispose.observers;

import io.reactivex.Observer;
import io.reactivex.SingleObserver;
import io.reactivex.disposables.Disposable;

Expand All @@ -26,8 +25,9 @@
*/
public interface AutoDisposingSingleObserver<T> extends SingleObserver<T>, Disposable {

/**
* @return The delegate {@link SingleObserver} that is used under the hood for introspection purposes.
*/
SingleObserver<? super T> delegateObserver();
/**
* @return The delegate {@link SingleObserver} that is used under the hood for introspection
* purposes.
*/
SingleObserver<? super T> delegateObserver();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> extends FlowableSubscriber<T>, Subscription, Disposable {
public interface AutoDisposingSubscriber<T>
extends FlowableSubscriber<T>, Subscription, Disposable {

/**
* @return The delegate {@link Subscriber} that is used under the hood for introspection purposes.
*/
Subscriber<? super T> delegateSubscriber();
/**
* @return The delegate {@link Subscriber} that is used under the hood for introspection
* purposes.
*/
Subscriber<? super T> delegateSubscriber();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<Integer> o = new RecordingObserver<>(LOGGER);
CompletableSubject source = CompletableSubject.create();
MaybeSubject<Integer> lifecycle = MaybeSubject.create();
Expand All @@ -78,7 +80,8 @@ public class AutoDisposeCompletableObserverTest {
assertThat(lifecycle.hasObservers()).isFalse();
}

@Test public void autoDispose_withMaybe_interrupted() {
@Test
public void autoDispose_withMaybe_interrupted() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
CompletableSubject source = CompletableSubject.create();
MaybeSubject<Integer> lifecycle = MaybeSubject.create();
Expand All @@ -99,7 +102,8 @@ public class AutoDisposeCompletableObserverTest {
o.assertNoMoreEvents();
}

@Test public void autoDispose_withProvider_completion() {
@Test
public void autoDispose_withProvider_completion() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
CompletableSubject source = CompletableSubject.create();
MaybeSubject<Integer> scope = MaybeSubject.create();
Expand All @@ -119,7 +123,8 @@ public class AutoDisposeCompletableObserverTest {
assertThat(scope.hasObservers()).isFalse();
}

@Test public void autoDispose_withProvider_interrupted() {
@Test
public void autoDispose_withProvider_interrupted() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
CompletableSubject source = CompletableSubject.create();
MaybeSubject<Integer> scope = MaybeSubject.create();
Expand All @@ -142,7 +147,8 @@ public class AutoDisposeCompletableObserverTest {
o.assertNoMoreEvents();
}

@Test public void autoDispose_withLifecycleProvider_completion() {
@Test
public void autoDispose_withLifecycleProvider_completion() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
CompletableSubject source = CompletableSubject.create();
BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
Expand All @@ -167,7 +173,8 @@ public class AutoDisposeCompletableObserverTest {
assertThat(lifecycle.hasObservers()).isFalse();
}

@Test public void autoDispose_withLifecycleProvider_interrupted() {
@Test
public void autoDispose_withLifecycleProvider_interrupted() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
CompletableSubject source = CompletableSubject.create();
BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
Expand Down Expand Up @@ -195,7 +202,8 @@ public class AutoDisposeCompletableObserverTest {
o.assertNoMoreEvents();
}

@Test public void autoDispose_withLifecycleProvider_withoutStartingLifecycle_shouldFail() {
@Test
public void autoDispose_withLifecycleProvider_withoutStartingLifecycle_shouldFail() {
BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
Expand All @@ -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<Integer> lifecycle = BehaviorSubject.createDefault(0);
lifecycle.onNext(1);
lifecycle.onNext(2);
Expand All @@ -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<OutsideLifecycleException>() {
@Override public void accept(OutsideLifecycleException e) throws Exception { }
@Override
public void accept(OutsideLifecycleException e) throws Exception { }
});
BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
TestObserver<Integer> o = new TestObserver<>();
Expand All @@ -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<OutsideLifecycleException>() {
@Override public void accept(OutsideLifecycleException e) throws Exception {
@Override
public void accept(OutsideLifecycleException e) throws Exception {
// Noop
}
});
Expand All @@ -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<OutsideLifecycleException>() {
@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);
Expand All @@ -278,19 +293,26 @@ public class AutoDisposeCompletableObserverTest {

o.assertNoValues();
o.assertError(new Predicate<Throwable>() {
@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<CompletableObserver> atomicObserver = new AtomicReference<>();
final AtomicReference<CompletableObserver> atomicAutoDisposingObserver = new AtomicReference<>();
final AtomicReference<CompletableObserver> atomicAutoDisposingObserver
= new AtomicReference<>();
try {
RxJavaPlugins.setOnCompletableSubscribe(new BiFunction<Completable, CompletableObserver, CompletableObserver>() {
@Override public CompletableObserver apply(Completable source, CompletableObserver observer) {
RxJavaPlugins.setOnCompletableSubscribe(new BiFunction<Completable,
CompletableObserver,
CompletableObserver>() {
@Override public CompletableObserver apply(
Completable source,
CompletableObserver observer) {
if (atomicObserver.get() == null) {
atomicObserver.set(observer);
} else if (atomicAutoDisposingObserver.get() == null) {
Expand All @@ -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();
}
});
Expand Down
Loading

0 comments on commit 71f0154

Please sign in to comment.