Java Code Examples for rx.observers.TestSubscriber#assertReceivedOnNext()

The following examples show how to use rx.observers.TestSubscriber#assertReceivedOnNext() . 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: RxFirebaseUserTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void updateEmail()  {

    TestSubscriber<Void> testSubscriber = new TestSubscriber<>();
    RxFirebaseUser.updateEmail(mockUser, "newemail")
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(mockRes);
    testOnCompleteListener.getValue().onComplete(mockTask);

    verify(mockUser).updateEmail("newemail");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockRes));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 2
Source File: RxFirebaseConfigTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void fetchWithExpiration() {

    TestSubscriber<Void> testSubscriber = new TestSubscriber<>();
    RxFirebaseConfig.fetch(mockConfig, 1)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(mockRes);
    testOnCompleteListener.getValue().onComplete(mockTask);

    verify(mockConfig).fetch(1);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockRes));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 3
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveChildEvent_Moved() {

    TestSubscriber<RxFirebaseChildEvent<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeChildEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<ChildEventListener> argument = ArgumentCaptor.forClass(ChildEventListener.class);
    verify(mockDatabase).addChildEventListener(argument.capture());
    argument.getValue().onChildMoved(mockFirebaseDataSnapshot, "root");

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testChildEventMoved));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 4
Source File: DatabaseHelperTest.java    From ribot-app-android with Apache License 2.0 6 votes vote down vote up
@Test
public void findRegisteredBeaconsUuids() {
    RegisteredBeacon beacon1 = MockModelFabric.newRegisteredBeacon();
    RegisteredBeacon beacon2 = MockModelFabric.newRegisteredBeacon();
    RegisteredBeacon beacon3 = MockModelFabric.newRegisteredBeacon();
    beacon3.uuid = beacon1.uuid;
    mDatabaseHelper.setRegisteredBeacons(Arrays.asList(beacon1, beacon2, beacon3)).subscribe();

    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    mDatabaseHelper.findRegisteredBeaconsUuids().subscribe(testSubscriber);

    testSubscriber.assertNoErrors();
    // beacon3 has the same uuid as beacon2 so it shouldn't be returned twice
    testSubscriber.assertReceivedOnNext(Arrays.asList(beacon1.uuid, beacon2.uuid));
    testSubscriber.assertCompleted();
}
 
Example 5
Source File: RxFirebaseStorageTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void delete() {

    TestSubscriber<Void> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.delete(mockStorageRef)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(voidData);
    testOnCompleteListener.getValue().onComplete(mockVoidTask);

    verify(mockStorageRef).delete();

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(voidData));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 6
Source File: RxFirebaseStorageTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void updateMetadata() {

    TestSubscriber<StorageMetadata> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.updateMetadata(mockStorageRef, metadata)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(metadata);

    verify(mockStorageRef).updateMetadata(metadata);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(metadata));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 7
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveValueEventList() {

    TestSubscriber<List<TestData>> testSubscriber = new TestSubscriber<>();
    RxFirebaseDatabase.observeSingleValueEvent(mockDatabase, TestData.class)
            .subscribeOn(Schedulers.immediate())
            .toList()
            .subscribe(testSubscriber);

    ArgumentCaptor<ValueEventListener> argument = ArgumentCaptor.forClass(ValueEventListener.class);
    verify(mockDatabase).addListenerForSingleValueEvent(argument.capture());
    argument.getValue().onDataChange(mockFirebaseDataSnapshot);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testDataList));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 8
Source File: RxFirebaseAuthTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void signInWithCustomToken()  {

    TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>();
    RxFirebaseAuth.signInWithCustomToken(mockAuth, "token")
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(mockAuthResult);
    testOnCompleteListener.getValue().onComplete(mockAuthTask);

    verify(mockAuth).signInWithCustomToken(eq("token"));

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockAuthResult));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 9
Source File: RxFirebaseStorageTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void putBytesMetadata() {

    TestSubscriber<UploadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.putBytes(mockStorageRef, bytes, metadata)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(uploadSnapshot);

    verify(mockStorageRef).putBytes(bytes, metadata);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(uploadSnapshot));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 10
Source File: RxFirebaseStorageTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void putBytes() {

    TestSubscriber<UploadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.putBytes(mockStorageRef, bytes)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(uploadSnapshot);

    verify(mockStorageRef).putBytes(bytes);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(uploadSnapshot));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 11
Source File: RxFirebaseAuthTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void signInWithCredential()  {

    TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>();
    RxFirebaseAuth.signInWithCredential(mockAuth, mockCredentials)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(mockAuthResult);
    testOnCompleteListener.getValue().onComplete(mockAuthTask);

    verify(mockAuth).signInWithCredential(mockCredentials);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockAuthResult));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 12
Source File: RxFirebaseUserTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void delete()  {

    TestSubscriber<Void> testSubscriber = new TestSubscriber<>();
    RxFirebaseUser.delete(mockUser)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(mockRes);
    testOnCompleteListener.getValue().onComplete(mockTask);

    verify(mockUser).delete();

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockRes));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 13
Source File: RxTiPresenterUtilsTest.java    From ThirtyInch with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliverLatestCacheToViewViewNotReady() throws Exception {
    mPresenter.create();

    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(1, 2, 3)
            .compose(RxTiPresenterUtils.<Integer>deliverLatestCacheToView(mPresenter))
            .subscribe(testSubscriber);

    mPresenter.attachView(mView);

    testSubscriber.assertNotCompleted();
    testSubscriber.assertNoErrors();
    testSubscriber.assertReceivedOnNext(Collections.singletonList(3));
}
 
Example 14
Source File: PreferencesHelperTest.java    From ribot-app-android with Apache License 2.0 5 votes vote down vote up
@Test
public void getLatestCheckInAsObservable() {
    CheckIn checkIn = MockModelFabric.newCheckInWithVenue();
    mPreferencesHelper.putLatestCheckIn(checkIn);

    TestSubscriber<CheckIn> testSubscriber = new TestSubscriber<>();
    mPreferencesHelper.getLatestCheckInAsObservable().subscribe(testSubscriber);
    testSubscriber.assertCompleted();
    testSubscriber.assertReceivedOnNext(Collections.singletonList(checkIn));
}
 
Example 15
Source File: RxTiPresenterUtilsTest.java    From ThirtyInch with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliverToViewViewNotReady() throws Exception {
    mPresenter.create();
    mPresenter.attachView(mView);

    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(1, 2, 3)
            .compose(RxTiPresenterUtils.<Integer>deliverToView(mPresenter))
            .subscribe(testSubscriber);

    testSubscriber.assertCompleted();
    testSubscriber.assertNoErrors();
    testSubscriber.assertReceivedOnNext(Arrays.asList(1, 2, 3));
}
 
Example 16
Source File: DataManagerTest.java    From ribot-app-android with Apache License 2.0 5 votes vote down vote up
@Test
public void getVenuesWhenDataCachedDifferentToApi() {
    List<Venue> venuesApi = MockModelFabric.newVenueList(10);
    List<Venue> venuesCache = MockModelFabric.newVenueList(4);
    stubRibotServiceGetVenues(Observable.just(venuesApi));
    stubPreferencesHelperGetVenues(Observable.just(venuesCache));

    TestSubscriber<List<Venue>> testSubscriber = new TestSubscriber<>();
    mDataManager.getVenues().subscribe(testSubscriber);
    testSubscriber.assertCompleted();
    testSubscriber.assertValueCount(2);
    testSubscriber.assertReceivedOnNext(Arrays.asList(venuesCache, venuesApi));
    // Check that the new API result is cached
    verify(mMockPreferencesHelper).putVenues(venuesApi);
}
 
Example 17
Source File: ResultSetToRowsTransformerTest.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void testSinglePage() throws Exception {
    int rowCount = 763;
    MockResultSet resultSet = MockResultSet.createSinglePage(rowCount);

    Observable<Row> rows = transformer.call(Observable.just(resultSet));

    TestSubscriber<Row> subscriber = new TestSubscriber<>();
    rows.subscribe(subscriber);

    subscriber.awaitTerminalEvent();
    subscriber.assertNoErrors();
    subscriber.assertValueCount(rowCount);
    subscriber.assertReceivedOnNext(LongStream.range(0, rowCount).mapToObj(MockRow::new).collect(toList()));
}
 
Example 18
Source File: PreferencesHelperTest.java    From ribot-app-android with Apache License 2.0 5 votes vote down vote up
@Test
public void getVenuesAsObservable() {
    List<Venue> venues = MockModelFabric.newVenueList(10);
    mPreferencesHelper.putVenues(venues);
    TestSubscriber<List<Venue>> testSubscriber = new TestSubscriber<>();
    mPreferencesHelper.getVenuesAsObservable().subscribe(testSubscriber);
    testSubscriber.assertCompleted();
    testSubscriber.assertReceivedOnNext(Collections.singletonList(venues));
}
 
Example 19
Source File: RxTiPresenterUtilsTest.java    From ThirtyInch with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliverLatestToViewViewNotReady() throws Exception {
    mPresenter.create();

    TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
    Observable.just(1, 2, 3)
            .compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter))
            .subscribe(testSubscriber);

    mPresenter.attachView(mView);

    testSubscriber.assertCompleted();
    testSubscriber.assertNoErrors();
    testSubscriber.assertReceivedOnNext(Collections.singletonList(3));
}
 
Example 20
Source File: Example16Test.java    From AnDevCon-RxPatterns with Apache License 2.0 4 votes vote down vote up
@Test
public void using_testscheduler_to_simulate_network_events() {

    // TestScheduler lets you advance time by hand
    TestScheduler scheduler = Schedulers.test();
    TestSubscriber<NetworkResponse> subscriber = new TestSubscriber<>();

    // Scheduler.Worker lets you schedule events in time
    Scheduler.Worker worker = scheduler.createWorker();

    // Subjects allow both input and output, so they can be swapped in for
    // Retrofit calls to unit test your code.
    final PublishSubject<NetworkResponse> networkSubject = PublishSubject.create();

    // schedule a first observable event to occur at 1000 ms
    worker.schedule(new Action0() {
        @Override
        public void call() {
            // explicitly calling onNext in a worker allows one to
            // create a very specific test of timed events
            networkSubject.onNext(new NetworkResponse(401));
        }
    }, 1000, TimeUnit.MILLISECONDS);

    // schedule a second observable event to occur at 2000 ms
    worker.schedule(new Action0() {
        @Override
        public void call() {
            networkSubject.onNext(new NetworkResponse(200));
            networkSubject.onCompleted();
        }
    }, 2000, TimeUnit.MILLISECONDS);

    // we must subscribe before anticipating results
    networkSubject
            .subscribeOn(scheduler)
            .subscribe(subscriber);

    // we can manually advance time using the scheduler and check assertions
    scheduler.advanceTimeBy(1500, TimeUnit.MILLISECONDS);
    subscriber.assertReceivedOnNext(Arrays.asList(
            new NetworkResponse(401)));

    // awaitTerminalEvent will wait forever if we don't advance time enough
    scheduler.advanceTimeBy(500, TimeUnit.MILLISECONDS);
    subscriber.awaitTerminalEvent();
    subscriber.assertReceivedOnNext(Arrays.asList(
            new NetworkResponse(401),
            new NetworkResponse(200)));

    // TestSubscriber provides many useful methods
    subscriber.assertNoErrors();
    subscriber.assertValueCount(2);
    subscriber.assertUnsubscribed();
}