Skip to content

Instantly share code, notes, and snippets.

@weefbellington
Created October 21, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weefbellington/7f7e2a0a19ea80357f5f to your computer and use it in GitHub Desktop.
Save weefbellington/7f7e2a0a19ea80357f5f to your computer and use it in GitHub Desktop.
package com.dramafever.android.lib.rxjava;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import rx.Subscriber;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.observers.Subscribers;
import rx.observers.TestSubscriber;
import rx.subjects.PublishSubject;
import static org.mockito.Mockito.verify;
/**
* Created by weefbellington on 10/21/15.
*/
@RunWith(MockitoJUnitRunner.class)
public class ObservableTests {
@Mock Action0 onTerminate;
@Mock Action1<Throwable> onError;
private final NullPointerException expectedException = new NullPointerException();
@Test
public void testOnTerminateCalledWithSubscriberException() {
Subscriber<Object> delegate = Subscribers.create(throwsException, onError);
TestSubscriber<Object> testSubscriber = new TestSubscriber<>(delegate);
PublishSubject<Object> testSource = PublishSubject.create();
testSource.doOnTerminate(onTerminate).subscribe(testSubscriber);
testSource.onNext(null);
testSubscriber.awaitTerminalEvent();
verify(onError).call(expectedException);
verify(onTerminate).call();
}
private final Action1<Object> throwsException = new Action1() {
@Override
public void call(Object o) {
throw expectedException;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment