Created
October 21, 2015 18:49
-
-
Save weefbellington/7f7e2a0a19ea80357f5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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