Java Code Examples for io.reactivex.observers.TestObserver#dispose()

The following examples show how to use io.reactivex.observers.TestObserver#dispose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxFirebaseDatabaseTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testChildEvents_DataReference_notSuccessful() {
    TestObserver<ChildEvent> sub = TestObserver.create();

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

    verifyDataReferenceAddChildEventListener();
    callChildOnCancelled();

    sub.assertNoValues();
    assertThat(sub.errorCount())
            .isEqualTo(1);

    sub.dispose();

    callChildOnCancelled();

    // Ensure no more values are emitted after unsubscribe
    assertThat(sub.errorCount())
            .isEqualTo(1);
}
 
Example 2
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendEmailVerification_notSuccessful() {
    mockNotSuccessfulVoidResult(new IllegalStateException());
    when(mockFirebaseUser.sendEmailVerification())
            .thenReturn(mockVoidTaskResult);

    TestObserver obs = TestObserver.create();

    RxFirebaseUser.sendEmailVerification(mockFirebaseUser)
            .subscribe(obs);

    callOnComplete(mockVoidTaskResult);
    obs.dispose();

    obs.assertError(IllegalStateException.class);
}
 
Example 3
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdatePassword() {
    mockSuccessfulVoidResult();
    when(mockFirebaseUser.updatePassword("password"))
            .thenReturn(mockVoidTaskResult);

    TestObserver obs = TestObserver.create();

    RxFirebaseUser.updatePassword(mockFirebaseUser, "password")
            .subscribe(obs);

    callOnComplete(mockVoidTaskResult);
    obs.dispose();

    obs.assertComplete();
}
 
Example 4
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendEmailVerification() {
    mockSuccessfulVoidResult();
    when(mockFirebaseUser.sendEmailVerification())
            .thenReturn(mockVoidTaskResult);

    TestObserver obs = TestObserver.create();

    RxFirebaseUser.sendEmailVerification(mockFirebaseUser)
            .subscribe(obs);

    callOnComplete(mockVoidTaskResult);
    obs.dispose();

    obs.assertComplete();
}
 
Example 5
Source File: RxFirebaseAuthTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateUserWithEmailAndPassword_NotSuccessful() {
    when(mockFirebaseUser.getEmail())
            .thenReturn("[email protected]");

    mockNotSuccessfulResult(new IllegalStateException());

    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.assertError(IllegalStateException.class);
    obs.assertNoValues();
}
 
Example 6
Source File: RxFirebaseDatabaseTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetValue() {
    when(mockDatabaseReference.setValue(1))
            .thenReturn(mockTask);

    TestObserver sub = TestObserver.create();

    RxFirebaseDatabase.setValue(mockDatabaseReference, 1)
            .subscribe(sub);

    verifyAddOnCompleteListenerForTask();
    callTaskOnComplete();

    sub.assertComplete();
    sub.assertNoErrors();
    sub.dispose();
}
 
Example 7
Source File: RxFirebaseStorageTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test public void testPutFileWithMetadataAndUri_notSuccessful() {
  mockNotSuccessfulResultForTask(mockUploadTask, new IllegalStateException());
  when(mockStorageReference.putFile(mockUri, mockStorageMetadata, mockUri)).thenReturn(
      mockUploadTask);

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

  RxFirebaseStorage.putFile(mockStorageReference, mockUri, mockStorageMetadata, mockUri)
      .subscribe(obs);
  verifyAddOnCompleteListenerForTask(mockUploadTask);

  callOnComplete(mockUploadTask);
  obs.dispose();

  callOnComplete(mockUploadTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
Example 8
Source File: RxFirebaseAuthTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testFetchProvidersForEmail_NotSuccessful() {
    when(mockFirebaseAuth.fetchProvidersForEmail("[email protected]"))
            .thenReturn(mockFetchProvidersTask);

    mockNotSuccessfulFetchProvidersResult(new IllegalStateException());

    when(mockFirebaseAuth.fetchProvidersForEmail("[email protected]"))
            .thenReturn(mockFetchProvidersTask);

    TestObserver<List<String>> obs = TestObserver.create();

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

    callOnComplete(mockFetchProvidersTask);
    obs.dispose();

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

    obs.assertError(IllegalStateException.class);
    obs.assertNoValues();
}
 
Example 9
Source File: RxFirebaseStorageTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test public void testPutFile() {
  mockSuccessfulResultForTask(mockUploadTask, mockUploadTaskSnapshot);
  when(mockStorageReference.putFile(mockUri)).thenReturn(mockUploadTask);
  when(mockUploadTaskSnapshot.getBytesTransferred()).thenReturn(1000L);
  when(mockUploadTaskSnapshot.getTotalByteCount()).thenReturn(1000L);

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

  RxFirebaseStorage.putFile(mockStorageReference, mockUri).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;
    }
  });
}
 
Example 10
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testLinkWithCredential_notSuccessful() {
    mockNotSuccessfulAuthResult(new IllegalStateException());
    when(mockFirebaseUser.linkWithCredential(mockAuthCredential))
            .thenReturn(mockAuthTaskResult);

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

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

    callOnComplete(mockAuthTaskResult);
    obs.dispose();

    obs.assertError(IllegalStateException.class);
}
 
Example 11
Source File: UserAuthenticateCallUnitShould.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void not_invoke_stores_on_exception_on_call() throws D2Error {
    whenAPICall().thenThrow(d2Error);
    when(d2Error.errorCode()).thenReturn(D2ErrorCode.UNEXPECTED);

    TestObserver<User> testObserver = logInSingle.test();
    testObserver.awaitTerminalEvent();

    assertThat(testObserver.errorCount()).isEqualTo(1);
    testObserver.dispose();

    verifyNoTransactionCompleted();

    // stores must not be invoked
    verify(authenticatedUserStore, never()).updateOrInsertWhere(any(AuthenticatedUser.class));
    verifyNoMoreInteractions(userHandler);
}
 
Example 12
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdatePassword_notSuccessful() {
    mockNotSuccessfulVoidResult(new IllegalStateException());
    when(mockFirebaseUser.updatePassword("password"))
            .thenReturn(mockVoidTaskResult);

    TestObserver obs = TestObserver.create();

    RxFirebaseUser.updatePassword(mockFirebaseUser, "password")
            .subscribe(obs);

    callOnComplete(mockVoidTaskResult);
    obs.dispose();

    obs.assertError(IllegalStateException.class);
}
 
Example 13
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testReauthenticate_notSuccessful() {
    mockNotSuccessfulVoidResult(new IllegalStateException());
    when(mockFirebaseUser.reauthenticate(mockAuthCredential))
            .thenReturn(mockVoidTaskResult);

    TestObserver obs = TestObserver.create();

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

    callOnComplete(mockVoidTaskResult);
    obs.dispose();

    obs.assertError(IllegalStateException.class);
}
 
Example 14
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnlink_notSuccessful() {
    mockNotSuccessfulAuthResult(new IllegalStateException());
    when(mockFirebaseUser.unlink("provider"))
            .thenReturn(mockAuthTaskResult);

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

    RxFirebaseUser.unlink(mockFirebaseUser, "provider")
            .subscribe(obs);

    callOnComplete(mockAuthTaskResult);
    obs.dispose();

    obs.assertError(IllegalStateException.class);
}
 
Example 15
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testReauthenticate() {
    mockSuccessfulVoidResult();
    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.assertComplete();
}
 
Example 16
Source File: RxOkukiTest.java    From okuki with Apache License 2.0 5 votes vote down vote up
@Test
public void testBranchSubscription() throws Exception {
    TestObserver<Place> testObserver = TestObserver.create();
    RxOkuki.onBranch(okuki, TestPlace.class).subscribe(testObserver);
    verify(okuki).addBranchListener(isA(BranchListener.class));
    testObserver.dispose();
    verify(okuki).removeBranchListener(isA(BranchListener.class));
}
 
Example 17
Source File: RxFirebaseAuthTest.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignInAnonymous() {
    when(mockFirebaseUser.isAnonymous())
            .thenReturn(true);

    mockSuccessfulAuthResult();

    when(mockFirebaseAuth.signInAnonymously())
            .thenReturn(mockAuthResultTask);

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

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

    callOnComplete(mockAuthResultTask);
    obs.dispose();

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

    obs.assertNoErrors();

    obs.assertValue(new Predicate<FirebaseUser>() {
        @Override
        public boolean test(FirebaseUser firebaseUser) throws Exception {
            return firebaseUser.isAnonymous();
        }
    });
}
 
Example 18
Source File: RxFirebaseAuthTest.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
@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.assertComplete();
    obs.assertValueCount(1);

    obs.assertValue(new Predicate<FirebaseUser>() {
        @Override
        public boolean test(FirebaseUser user) throws Exception {
            return "John Doe".equals(user.getDisplayName());

        }
    });
}
 
Example 19
Source File: RxFirebaseDatabaseTest.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
@Test
public void testChildEvents_Query_move() {
    TestObserver<ChildEvent> sub = TestObserver.create();

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

    verifyQueryAddChildEventListener();
    callOnChildMoved("foo");
    callOnChildMoved("foo");

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

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

    sub.dispose();

    callOnChildMoved("foo");

    // Ensure no more values are emitted after unsubscribe
    sub.assertValueCount(2);
}
 
Example 20
Source File: RxFirebaseDatabaseTest.java    From rxfirebase with Apache License 2.0 4 votes vote down vote up
@Test
public void testDataOfClazz_DataReference() {
    TestObserver<String> sub = TestObserver.create();

    RxFirebaseDatabase.dataOf(mockDatabaseReference, String.class)
            .subscribe(sub);

    verifyDataReferenceAddListenerForSingleValueEvent();
    callValueEventOnDataChange("Foo");

    sub.assertComplete();
    sub.assertNoErrors();

    sub.assertValue("Foo");

    sub.dispose();

    callValueEventOnDataChange("Foo");

    // Ensure no more values are emitted after unsubscribe
    sub.assertValueCount(1);
}