當前位置: 首頁>>代碼示例>>Java>>正文


Java TestObserver類代碼示例

本文整理匯總了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");
}
 
開發者ID:uber,項目名稱:RIBs,代碼行數:18,代碼來源:RibActivityTest.java

示例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);
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:17,代碼來源:UntilLifecycleTransformerSingleTest.java

示例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();
}
 
開發者ID:xemantic,項目名稱:github-users,代碼行數:18,代碼來源:UserPresenterTest.java

示例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);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:21,代碼來源:RxFirebaseAuthTest.java

示例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");
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Programming-With-Java-9,代碼行數:17,代碼來源:Modern_Testing.java

示例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;
    }
  });
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:27,代碼來源:RxFirebaseStorageTest.java

示例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
            );
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:24,代碼來源:ArtistsPresenterTest.java

示例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));
}
 
開發者ID:yongjhih,項目名稱:rxtasks,代碼行數:20,代碼來源:RxTaskTest.java

示例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();
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:22,代碼來源:RxSupportFragmentLifecycleTest.java

示例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);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:19,代碼來源:RxFirebaseUserTest.java

示例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);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:24,代碼來源:RxFirebaseDatabaseTest.java

示例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));
}
 
開發者ID:groupon,項目名稱:grox,代碼行數:19,代碼來源:RxStoresTest.java

示例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());
    }
  });
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:26,代碼來源:RxFirebaseStorageTest.java

示例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;
            });
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:27,代碼來源:ConcertsPresenterTest.java


注:本文中的io.reactivex.observers.TestObserver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。