本文整理汇总了Java中io.reactivex.observers.TestObserver类的典型用法代码示例。如果您正苦于以下问题:Java TestObserver类的具体用法?Java TestObserver怎么用?Java TestObserver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TestObserver类属于io.reactivex.observers包,在下文中一共展示了TestObserver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ribActivity_onSaveInstanceStateAndCallbackFlagEnabled_shouldEmitToCallbacks
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void ribActivity_onSaveInstanceStateAndCallbackFlagEnabled_shouldEmitToCallbacks() {
ActivityController<EmptyActivity> activityController = buildActivity(EmptyActivity.class);
RibActivity activity = activityController.setup().get();
TestObserver<ActivityCallbackEvent.SaveInstanceState> testSub = new TestObserver<>();
activity.callbacks(ActivityCallbackEvent.SaveInstanceState.class).subscribe(testSub);
android.os.Bundle state = new android.os.Bundle();
state.putString("hello", "seattle");
activity.onSaveInstanceState(state);
testSub.assertValueCount(1);
ActivityCallbackEvent.SaveInstanceState receivedEvent = testSub.values().get(0);
assertThat(receivedEvent.getType()).isEqualTo(ActivityCallbackEvent.Type.SAVE_INSTANCE_STATE);
assertThat(receivedEvent.getOutState()).isNotNull();
assertThat(receivedEvent.getOutState().getString("hello")).isEqualTo("seattle");
}
示例2: oneEvent
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void oneEvent() {
TestObserver<String> testObserver = Single.just("1")
.delay(1, TimeUnit.MILLISECONDS, testScheduler)
.compose(RxLifecycle.<String, String>bind(lifecycle))
.test();
testObserver.assertNoValues();
testObserver.assertNoErrors();
lifecycle.onNext("stop");
testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
testObserver.assertNoValues();
testObserver.assertError(CancellationException.class);
}
示例3: start_user_shouldDisplayUser
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void start_user_shouldDisplayUser() {
// given
TestObserver<UserSelectedEvent> userSelected$ = TestObserver.create();
User user = mock(User.class);
given(view.userSelection$()).willReturn(noTriggers());
UserPresenter presenter = new UserPresenter(Sink.of(userSelected$));
// when
presenter.start(user, view);
// then
then(view).should().displayUser(user);
then(view).should().userSelection$();
then(view).shouldHaveNoMoreInteractions();
userSelected$.assertNoValues();
}
示例4: testSignInWithEmailAndPassword
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test public void testSignInWithEmailAndPassword() {
mockSuccessfulAuthResult();
when(mockFirebaseAuth.signInWithEmailAndPassword("email", "password")).thenReturn(
mockAuthResultTask);
TestObserver<FirebaseUser> obs = TestObserver.create();
RxFirebaseAuth.signInWithEmailAndPassword(mockFirebaseAuth, "email", "password").subscribe(obs);
callOnComplete(mockAuthResultTask);
obs.dispose();
// Ensure no more values are emitted after unsubscribe
callOnComplete(mockAuthResultTask);
obs.assertNoErrors();
obs.assertComplete();
obs.assertValueCount(1);
}
示例5: test_error
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void test_error() {
Observable<String> observable = Observable.error(new Exception("We got an Exception"));
TestObserver<String> testObserver = new TestObserver<>();
observable.subscribe(testObserver);
testObserver.assertError(Exception.class);
testObserver.assertNotComplete();
testObserver.assertErrorMessage("We got an Exception");
testObserver.assertFailure(exception -> {
return exception instanceof Exception;
});
testObserver.assertFailureAndMessage(Exception.class, "We got an Exception");
}
示例6: testPutStream
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test public void testPutStream() {
mockSuccessfulResultForTask(mockUploadTask, mockUploadTaskSnapshot);
when(mockStorageReference.putStream(mockInputStream)).thenReturn(mockUploadTask);
when(mockUploadTaskSnapshot.getBytesTransferred()).thenReturn(1000L);
when(mockUploadTaskSnapshot.getTotalByteCount()).thenReturn(1000L);
TestObserver<UploadTask.TaskSnapshot> obs = TestObserver.create();
RxFirebaseStorage.putStream(mockStorageReference, mockInputStream).subscribe(obs);
verifyAddOnCompleteListenerForTask(mockUploadTask);
callOnComplete(mockUploadTask);
obs.dispose();
callOnComplete(mockUploadTask);
obs.assertNoErrors();
obs.assertComplete();
obs.assertValue(new Predicate<UploadTask.TaskSnapshot>() {
@Override public boolean test(UploadTask.TaskSnapshot taskSnapshot) throws Exception {
return taskSnapshot.getBytesTransferred() == taskSnapshot.getTotalByteCount()
&& taskSnapshot.getTotalByteCount() == 1000L;
}
});
}
示例7: deleteSelectedArtists
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void deleteSelectedArtists() throws Exception {
when(repository.deleteArtists(any())).thenReturn(Completable.complete());
ArtistsPresenter presenter = presenterBuilder.uiModel(twoSelectedArtistsUiModel).build();
TestObserver<ArtistsUiModel> observer = presenter.getUiModels().skip(1).test();
presenter.sendUiEvent(DeleteArtistsEvent.create(twoSelectedArtistsUiModel));
verify(repository).deleteArtists(argThat(selected -> {
assertThat(selected).hasSize(2).containsOnly(artist1, artist2);
return true;
}));
observer
.awaitCount(2)
.assertNoErrors()
.assertValues(
twoSelectedArtistsUiModel.copy()
.deletion(true)
.build(),
withArtistsUiModel
);
}
示例8: testCompleteSuccessful
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void testCompleteSuccessful() {
final String hello = "Hello, world!";
when(mockHelloTask.getResult())
.thenReturn(hello);
when(mockHelloTask.isSuccessful())
.thenReturn(true);
when(mockHelloTask.addOnCompleteListener(onComplete.capture()))
.thenReturn(mockHelloTask);
TestObserver<String> obs = TestObserver.create();
RxTask.completes(mockHelloTask).subscribe(obs);
verify(mockHelloTask).addOnCompleteListener(onComplete.capture());
onComplete.getValue().onComplete(mockHelloTask);
obs.assertNoErrors()
.assertComplete();
verify(mockHelloTask).addOnCompleteListener(any(OnCompleteListener.class));
}
示例9: fromIterableShouldCreateAnObservableThatEmitsEachElementFromAnIterable
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
/**
* Observable.fromIterable() is another way to create an Observable. It's
* different than .just() - it is specifically designed to work with
* Collections. When just is given a collection, it converts it into an
* Observable that emits each item from the list. Let's understand how the
* two are different more clearly.
*/
@Test
public void fromIterableShouldCreateAnObservableThatEmitsEachElementFromAnIterable() {
List<String> sandwichIngredients = Arrays.asList("bread (one)", "bread (two)", "cheese", "mayo", "turkey",
"lettuce", "pickles", "jalapenos", "Sriracha sauce");
Observable<String> favoriteFoodsObservable = Observable.fromIterable(sandwichIngredients);
TestObserver<String> testObserverIteratable = null; // TODO create new TestObserver and subscribe to favoriteFoodsObservable
assertThat(testObserverIteratable.values()).hasSize(____);
assertThat(testObserverIteratable.values()).containsAll(null);
TestObserver<List<String>> testObserverForJust = new TestObserver<>();
// TODO create obseverable for sandwichIngredients with just operator and subscribe testObserverForJust to it
assertThat(testObserverForJust.values()).hasSize(1);
assertThat(testObserverForJust.values()).contains(sandwichIngredients);
/**
* ^^ As you can see here, fromIterable() & just() do very different things!
*/
}
开发者ID:vogellacompany,项目名称:code-examples-android-expert,代码行数:28,代码来源:lessonA_CreatingObservableStreams.java
示例10: testBindUntilEvent
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
private void testBindUntilEvent(LifecycleProvider<FragmentEvent> provider) {
Fragment fragment = (Fragment) provider;
startFragment(fragment);
TestObserver<Object> testObserver = observable.compose(provider.bindUntilEvent(STOP)).test();
fragment.onAttach(null);
testObserver.assertNotComplete();
fragment.onCreate(null);
testObserver.assertNotComplete();
fragment.onViewCreated(null, null);
testObserver.assertNotComplete();
fragment.onStart();
testObserver.assertNotComplete();
fragment.onResume();
testObserver.assertNotComplete();
fragment.onPause();
testObserver.assertNotComplete();
fragment.onStop();
testObserver.assertComplete();
}
示例11: testUnlink
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test public void testUnlink() {
mockSuccessfulAuthResult();
when(mockFirebaseUser.unlink("provider")).thenReturn(mockAuthTaskResult);
TestObserver<AuthResult> obs = TestObserver.create();
RxFirebaseUser.unlink(mockFirebaseUser, "provider").subscribe(obs);
callOnComplete(mockAuthTaskResult);
obs.dispose();
// Ensure no more values are emitted after unsubscribe
callOnComplete(mockAuthTaskResult);
obs.assertNoErrors();
obs.assertComplete();
obs.assertValueCount(1);
}
示例12: testDataChangesOfClazz
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test public void testDataChangesOfClazz() {
TestObserver<Optional<String>> sub = TestObserver.create();
RxFirebaseDatabase.dataChangesOf(mockDatabaseReference, String.class).subscribe(sub);
verifyAddValueEventListener();
callValueEventOnDataChange("Foo");
sub.assertNotComplete();
sub.assertValueCount(1);
sub.assertValue(new Predicate<Optional<String>>() {
@Override public boolean test(Optional<String> stringOptional) throws Exception {
return stringOptional.isPresent() && "Foo".equals(stringOptional.get());
}
});
sub.dispose();
callValueEventOnDataChange("Foo");
// Ensure no more values are emitted after unsubscribe
sub.assertValueCount(1);
}
示例13: states_should_stopObservingStateChanges
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void states_should_stopObservingStateChanges() {
//GIVEN
Store<Integer> store = new Store<>(0);
TestObserver<Integer> testSubscriber = new TestObserver<>();
states(store).subscribe(testSubscriber);
//WHEN
testSubscriber.dispose();
store.dispatch(integer -> integer + 1);
final Integer state = store.getState();
//THEN
testSubscriber.assertNotComplete();
testSubscriber.assertValue(0);
assertThat(testSubscriber.isDisposed(), is(true));
assertThat(state, is(1));
}
示例14: testUpdateMetadata
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test public void testUpdateMetadata() {
when(mockStorageMetadata.getName()).thenReturn("metadata");
mockSuccessfulResultForTask(mockStorageMetadataTask, mockStorageMetadata);
TestObserver<StorageMetadata> obs = TestObserver.create();
when(mockStorageReference.updateMetadata(mockStorageMetadata)).thenReturn(
mockStorageMetadataTask);
RxFirebaseStorage.updateMetadata(mockStorageReference, mockStorageMetadata).subscribe(obs);
verifyAddOnCompleteListenerForTask(mockStorageMetadataTask);
callOnComplete(mockStorageMetadataTask);
obs.dispose();
callOnComplete(mockStorageMetadataTask);
obs.assertNoErrors();
obs.assertComplete();
obs.assertValue(new Predicate<StorageMetadata>() {
@Override public boolean test(StorageMetadata metadata) throws Exception {
return "metadata".equals(metadata.getName());
}
});
}
示例15: loadConcerts
import io.reactivex.observers.TestObserver; //导入依赖的package包/类
@Test
public void loadConcerts() throws Exception {
when(repository.getConcerts()).thenReturn(Observable.just(concerts));
TestObserver<ConcertsUiModel> testObserver = presenter.getUiModels()
.skip(1)
.test();
presenter.sendUiEvent(LoadConcertsEvent.INSTANCE);
testObserver
.awaitCount(2)
.assertNoErrors()
.assertNotComplete()
.assertValueAt(0, model -> {
assertThat(model.isLoading()).isTrue();
return true;
})
.assertValueAt(1, model -> {
assertThat(model.isLoading()).isFalse();
assertThat(model.isLoadingError()).isFalse();
assertThat(model.getConcerts()).isEqualTo(sortedConcerts);
return true;
});
}