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


Java TestObserver.create方法代碼示例

本文整理匯總了Java中io.reactivex.observers.TestObserver.create方法的典型用法代碼示例。如果您正苦於以下問題:Java TestObserver.create方法的具體用法?Java TestObserver.create怎麽用?Java TestObserver.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.observers.TestObserver的用法示例。


在下文中一共展示了TestObserver.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGetStreamWithProcessor_notSuccessful

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testGetStreamWithProcessor_notSuccessful() {
  mockNotSuccessfulResultForTask(mockStreamDownloadTask, new IllegalStateException());
  when(mockStorageReference.getStream(mockStreamProcessor)).thenReturn(mockStreamDownloadTask);

  TestObserver<StreamDownloadTask.TaskSnapshot> obs = TestObserver.create();

  RxFirebaseStorage.getStream(mockStorageReference, mockStreamProcessor).subscribe(obs);
  verifyAddOnCompleteListenerForTask(mockStreamDownloadTask);

  callOnComplete(mockStreamDownloadTask);
  obs.dispose();

  callOnComplete(mockStreamDownloadTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:18,代碼來源:RxFirebaseStorageTest.java

示例2: shouldCompleteBlocking

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test
public void shouldCompleteBlocking() {
    TestObserver<String> testObserver = TestObserver.create();

    wordService
            .enumerate(Observable.fromArray(STRINGS))
            .subscribeOn(Schedulers.computation())
            .blockingSubscribe(testObserver);

    testObserver
            .assertSubscribed()
            .assertComplete()
            .assertNoErrors()
            .assertValueCount(9)
            .assertValues(
                    " 1. the",
                    " 2. quick",
                    " 3. brown",
                    " 4. fox",
                    " 5. jumped",
                    " 6. over",
                    " 7. the",
                    " 8. lazy",
                    " 9. dog"
            );
}
 
開發者ID:OlegDokuka,項目名稱:reactive-playing,代碼行數:27,代碼來源:WordServiceTest.java

示例3: testChildEvents_remove

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testChildEvents_remove() {
  TestObserver<ChildEvent> sub = TestObserver.create();

  RxFirebaseDatabase.childEvents(mockDatabaseReference).subscribe(sub);

  verifyAddChildEventListener();
  callOnChildRemoved();
  callOnChildRemoved();

  sub.assertNotComplete();
  sub.assertNoErrors();
  sub.assertValueCount(2);

  List events = sub.getEvents().get(0);
  for (Object event : events) {
    assertThat(event).isInstanceOf(ChildEvent.class);
    assertThat(event).isInstanceOf(ChildRemoveEvent.class);
  }

  sub.dispose();

  callOnChildRemoved();

  // Ensure no more values are emitted after unsubscrube
  sub.assertValueCount(2);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:27,代碼來源:RxFirebaseDatabaseTest.java

示例4: testGetStream_notSuccessful

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testGetStream_notSuccessful() {
  mockNotSuccessfulResultForTask(mockStreamDownloadTask, new IllegalStateException());
  when(mockStorageReference.getStream()).thenReturn(mockStreamDownloadTask);

  TestObserver<StreamDownloadTask.TaskSnapshot> obs = TestObserver.create();

  RxFirebaseStorage.getStream(mockStorageReference).subscribe(obs);
  verifyAddOnCompleteListenerForTask(mockStreamDownloadTask);

  callOnComplete(mockStreamDownloadTask);
  obs.dispose();

  callOnComplete(mockStreamDownloadTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:18,代碼來源:RxFirebaseStorageTest.java

示例5: testPutStream_notSuccessful

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testPutStream_notSuccessful() {
  mockNotSuccessfulResultForTask(mockUploadTask, new IllegalStateException());
  when(mockStorageReference.putStream(mockInputStream)).thenReturn(mockUploadTask);

  TestObserver<UploadTask.TaskSnapshot> obs = TestObserver.create();

  RxFirebaseStorage.putStream(mockStorageReference, mockInputStream).subscribe(obs);
  verifyAddOnCompleteListenerForTask(mockUploadTask);

  callOnComplete(mockUploadTask);
  obs.dispose();

  callOnComplete(mockUploadTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:18,代碼來源:RxFirebaseStorageTest.java

示例6: 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

示例7: testReauthenticate

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testReauthenticate() {
  mockVoidResult(true);
  when(mockFirebaseUser.reauthenticate(mockAuthCredential)).thenReturn(mockVoidTaskResult);

  TestObserver obs = TestObserver.create();

  RxFirebaseUser.reauthenticate(mockFirebaseUser, mockAuthCredential).subscribe(obs);

  callOnComplete(mockVoidTaskResult);
  obs.dispose();

  // Ensure no more values are emitted after unsubscribe
  callOnComplete(mockVoidTaskResult);

  obs.assertNoErrors();
  obs.assertComplete();
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:18,代碼來源:RxFirebaseUserTest.java

示例8: testSingleSuccessful

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test
public void testSingleSuccessful() {
    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.single(mockHelloTask).subscribe(obs);
    verify(mockHelloTask).addOnCompleteListener(onComplete.capture());
    onComplete.getValue().onComplete(mockHelloTask);

    obs.assertValue(hello)
       .assertNoErrors()
       .assertComplete();

    verify(mockHelloTask).addOnCompleteListener(any(OnCompleteListener.class));
    verify(mockHelloTask).getResult();
}
 
開發者ID:yongjhih,項目名稱:rxtasks,代碼行數:23,代碼來源:RxTaskTest.java

示例9: testChildEvents_change

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testChildEvents_change() {
  TestObserver<ChildEvent> sub = TestObserver.create();

  RxFirebaseDatabase.childEvents(mockDatabaseReference).subscribe(sub);

  verifyAddChildEventListener();
  callOnChildChanged("foo");
  callOnChildChanged("foo");

  sub.assertNotComplete();
  sub.assertNoErrors();
  sub.assertValueCount(2);

  List events = sub.getEvents().get(0);
  for (Object event : events) {
    assertThat(event).isInstanceOf(ChildEvent.class);
    assertThat(event).isInstanceOf(ChildChangeEvent.class);
    assertThat(((ChildChangeEvent) event).previousChildName()).isEqualTo("foo");
  }

  sub.dispose();

  callOnChildChanged("foo");

  // Ensure no more values are emitted after unsubscrube
  sub.assertValueCount(2);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:28,代碼來源:RxFirebaseDatabaseTest.java

示例10: shouldCompleteAndReplaceComputationOnTrampoline

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test
public void shouldCompleteAndReplaceComputationOnTrampoline() {
    TestObserver<String> testObserver = TestObserver.create();
    RxJavaPlugins.setComputationSchedulerHandler(old -> Schedulers.trampoline());

    try {
        wordService
                .enumerate(Observable.fromArray(STRINGS))
                .subscribeOn(Schedulers.computation())
                .subscribe(testObserver);

        testObserver
                .assertSubscribed()
                .assertComplete()
                .assertNoErrors()
                .assertValueCount(9)
                .assertValues(
                        " 1. the",
                        " 2. quick",
                        " 3. brown",
                        " 4. fox",
                        " 5. jumped",
                        " 6. over",
                        " 7. the",
                        " 8. lazy",
                        " 9. dog"
                );
    } finally {
        RxJavaPlugins.reset();
    }
}
 
開發者ID:OlegDokuka,項目名稱:reactive-playing,代碼行數:32,代碼來源:WordServiceTest.java

示例11: testCreateUserWithEmailAndPassword

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testCreateUserWithEmailAndPassword() {
  when(mockFirebaseUser.getEmail()).thenReturn("[email protected]");

  mockSuccessfulAuthResult();

  when(mockFirebaseAuth.createUserWithEmailAndPassword("[email protected]", "password")).thenReturn(
      mockAuthResultTask);

  TestObserver<FirebaseUser> obs = TestObserver.create();

  RxFirebaseAuth.createUserWithEmailAndPassword(mockFirebaseAuth, "[email protected]", "password")
      .subscribe(obs);

  callOnComplete(mockAuthResultTask);
  obs.dispose();

  // Ensure no more values are emitted after unsubscribe
  callOnComplete(mockAuthResultTask);

  obs.assertNoErrors();
  obs.assertComplete();

  obs.assertValue(new Predicate<FirebaseUser>() {
    @Override public boolean test(FirebaseUser firebaseUser) throws Exception {
      return "[email protected]".equals(firebaseUser.getEmail());
    }
  });
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:29,代碼來源:RxFirebaseAuthTest.java

示例12: fetchUsers_noErros_sucess

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test
public void fetchUsers_noErros_sucess() {
    TestObserver<UserResponse> subscriber = TestObserver.create();
    mApiEndPointHelper.fetchUsers(2).subscribe(subscriber);
    subscriber.onNext(new UserResponse());
    subscriber.assertNoErrors();
    subscriber.assertComplete();
}
 
開發者ID:rudsonlive,項目名稱:liveomvp,代碼行數:9,代碼來源:HomeInteractorTest.java

示例13: testSendPasswordResetEmail_NotSuccessful

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testSendPasswordResetEmail_NotSuccessful() {
  when(mockFirebaseAuth.sendPasswordResetEmail("email")).thenReturn(
      mockSendPasswordResetEmailTask);

  mockNotSuccessfulSendPasswordResetEmailResult(new IllegalStateException());

  TestObserver obs = TestObserver.create();

  RxFirebaseAuth.sendPasswordResetEmail(mockFirebaseAuth, "email").subscribe(obs);

  callOnComplete(mockSendPasswordResetEmailTask);
  obs.dispose();

  // Ensure no more values are emitted after unsubscribe
  callOnComplete(mockSendPasswordResetEmailTask);

  verify(mockFirebaseAuth).sendPasswordResetEmail("email");

  obs.assertError(IllegalStateException.class);
  obs.assertNotComplete();
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:22,代碼來源:RxFirebaseAuthTest.java

示例14: testDataChanges_onCancelled

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testDataChanges_onCancelled() {
  TestObserver<DataSnapshot> sub = TestObserver.create();

  RxFirebaseDatabase.dataChanges(mockDatabaseReference).subscribe(sub);

  verifyAddValueEventListener();
  callValueEventOnCancelled(new DatabaseException("foo"));

  sub.assertError(DatabaseException.class);
  sub.assertNoValues();

  sub.dispose();

  callValueEventOnCancelled(new DatabaseException("foo"));

  // Ensure no more values are emitted after unsubscribe
  assertThat(sub.errorCount()).isEqualTo(1);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:19,代碼來源:RxFirebaseDatabaseTest.java

示例15: testGetCurrentUser_signedIn

import io.reactivex.observers.TestObserver; //導入方法依賴的package包/類
@Test public void testGetCurrentUser_signedIn() {
  when(mockFirebaseUser.getDisplayName()).thenReturn("John Doe");

  when(mockFirebaseAuth.getCurrentUser()).thenReturn(mockFirebaseUser);

  TestObserver<FirebaseUser> obs = TestObserver.create();

  RxFirebaseAuth.getCurrentUser(mockFirebaseAuth).subscribe(obs);

  verify(mockFirebaseAuth).getCurrentUser();

  obs.dispose();

  obs.assertNoErrors();
  obs.assertComplete();

  obs.assertValue(new Predicate<FirebaseUser>() {
    @Override public boolean test(FirebaseUser firebaseUser) throws Exception {
      return "John Doe".equals(firebaseUser.getDisplayName());
    }
  });
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:23,代碼來源:RxFirebaseAuthTest.java


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