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

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

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

    testOnSuccessListener.getValue().onSuccess(metadata);
    testOnCompleteListener.getValue().onComplete(mockMetadataTask);

    verify(mockStorageRef).getMetadata();

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

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

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

    verify(mockUser).reauthenticate(credential);

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

    TestSubscriber<FileDownloadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.getFile(mockStorageRef, uri)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(fileSnapshot);

    verify(mockStorageRef).getFile(uri);

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

    TestSubscriber<byte[]> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.getBytes(mockStorageRef, 20)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(bytes);
    testOnCompleteListener.getValue().onComplete(mockBytesTask);

    verify(mockStorageRef).getBytes(20);

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

    TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>();
    RxFirebaseUser.linkWithCredential(mockUser, credential)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(authResult);
    testOnCompleteListener.getValue().onComplete(mockAuthResultTask);

    verify(mockUser).linkWithCredential(credential);

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

    TestSubscriber<Void> testSubscriber = new TestSubscriber<>();
    RxFirebaseAuth.sendPasswordResetEmail(mockAuth, "email")
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

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

    verify(mockAuth).sendPasswordResetEmail(eq("email"));

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockRes));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 7
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 8
Source File: RxFirebaseStorageTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void putFile() {

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

    testOnSuccessListener.getValue().onSuccess(uploadSnapshot);

    verify(mockStorageRef).putFile(uri);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(uploadSnapshot));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 9
Source File: RxAggregateOperatorsUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenObservable_whenUsingToSortedList_thenObtainedASortedList() {
    // given
    Observable<Integer> sourceObservable = Observable.range(10, 5);
    TestSubscriber<List> subscriber = TestSubscriber.create();

    // when
    Observable<List<Integer>> listObservable = sourceObservable.toSortedList();
    listObservable.subscribe(subscriber);

    // then
    subscriber.assertCompleted();
    subscriber.assertNoErrors();
    subscriber.assertValueCount(1);
    subscriber.assertValue(Arrays.asList(10, 11, 12, 13, 14));
}
 
Example 10
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveSingleNoData() {

    DataSnapshot mockFirebaseDataSnapshotNoData = mock(DataSnapshot.class);
    when(mockFirebaseDataSnapshotNoData.exists()).thenReturn(false);

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

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

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example 11
Source File: RxMathematicalOperatorsUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenRangeNumericObservable_whenCalculatingMin_ThenSuccessfullObtainingMinValue() {
    // given
    Observable<Integer> sourceObservable = Observable.range(1, 20);
    TestSubscriber<Integer> subscriber = TestSubscriber.create();

    // when
    MathObservable.min(sourceObservable)
        .subscribe(subscriber);

    // then
    subscriber.assertCompleted();
    subscriber.assertNoErrors();
    subscriber.assertValueCount(1);
    subscriber.assertValue(1);
}
 
Example 12
Source File: PolygonClickFuncTest.java    From RxGoogleMaps with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEmmitPolygon() throws Exception {
    TestSubscriber<Polygon> testSubscriber = new TestSubscriber<>();
    new PolygonClickFunc().call(googleMap)
            .subscribe(testSubscriber);
    verify(googleMap).setOnPolygonClickListener(argumentCaptor.capture());
    argumentCaptor.getValue().onPolygonClick(null);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    argumentCaptor.getValue().onPolygonClick(null);
    testSubscriber.assertValueCount(2);
}
 
Example 13
Source File: UsecaseTest.java    From ZhihuDaily with Apache License 2.0 5 votes vote down vote up
@Test
public void testFetchStoryDetailUsecase() {
    FetchLatestDailyStoriesUsecase fetchLatestDailyStoriesUsecase = new FetchLatestDailyStoriesUsecase(TestUtils.getRepository());
    TestSubscriber<DailyStories> dailyStoriesTestSubscriber = new TestSubscriber<>();
    fetchLatestDailyStoriesUsecase.execute().subscribe(dailyStoriesTestSubscriber);
    String storyId = dailyStoriesTestSubscriber.getOnNextEvents().get(0).getStories().get(0).getId();
    FetchStoryDetailUsecase fetchStoryDetailUsecase = new FetchStoryDetailUsecase(TestUtils.getRepository());
    fetchStoryDetailUsecase.setStoryId(storyId);
    TestSubscriber<Story> storyTestSubscriber = new TestSubscriber<>();
    fetchStoryDetailUsecase.execute().subscribe(storyTestSubscriber);
    storyTestSubscriber.assertNoErrors();
    storyTestSubscriber.assertValueCount(1);
}
 
Example 14
Source File: GroundOverlayClickFuncTest.java    From RxGoogleMaps with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEmmitGroundOverlay() throws Exception {
    TestSubscriber<GroundOverlay> testSubscriber = new TestSubscriber<>();
    new GroundOverlayClickFunc().call(googleMap)
            .subscribe(testSubscriber);
    verify(googleMap).setOnGroundOverlayClickListener(argumentCaptor.capture());
    argumentCaptor.getValue().onGroundOverlayClick(null);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue(null);
}
 
Example 15
Source File: BitmapSnapshotFuncTest.java    From RxGoogleMaps with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldProvideBitmap() throws Exception {
    TestSubscriber<Bitmap> testSubscriber = new TestSubscriber<>();
    new BitmapSnapshotFunc(null).call(googleMap)
            .subscribe(testSubscriber);
    verify(googleMap).snapshot(argumentCaptor.capture(), bitmapArgumentCaptor.capture());
    argumentCaptor.getValue().onSnapshotReady(null);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue(null);
}
 
Example 16
Source File: InfoWindowCloseFuncTest.java    From RxGoogleMaps with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEmmitMarker() throws Exception {
    TestSubscriber<Marker> testSubscriber = new TestSubscriber<>();
    new InfoWindowCloseFunc().call(googleMap)
            .subscribe(testSubscriber);
    verify(googleMap).setOnInfoWindowCloseListener(argumentCaptor.capture());
    argumentCaptor.getValue().onInfoWindowClose(null);
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    argumentCaptor.getValue().onInfoWindowClose(null);
    testSubscriber.assertValueCount(2);
}
 
Example 17
Source File: ObservableCombineUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenAStream_whenZippedWithInterval_shouldDelayStreamEmmission() {
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();

    Observable<String> data = Observable.just("one", "two", "three", "four", "five");
    Observable<Long> interval = Observable.interval(1L, TimeUnit.SECONDS);

    Observable
      .zip(data, interval, (strData, tick) -> String.format("[%d]=%s", tick, strData))
      .toBlocking().subscribe(testSubscriber);

    testSubscriber.assertCompleted();
    testSubscriber.assertValueCount(5);
    testSubscriber.assertValues("[0]=one", "[1]=two", "[2]=three", "[3]=four", "[4]=five");
}
 
Example 18
Source File: RxJavaFilterOperatorsIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenObservable_whenTakingElementAt_thenItemAtSpecifiedIndexIsEmitted() {

    Observable<Integer> sourceObservable = Observable.just(1, 2, 3, 5, 7, 11);
    TestSubscriber<Integer> subscriber = new TestSubscriber();

    Observable<Integer> filteredObservable = sourceObservable.elementAt(4);

    filteredObservable.subscribe(subscriber);

    subscriber.assertCompleted();
    subscriber.assertNoErrors();
    subscriber.assertValueCount(1);
    subscriber.assertValue(7);
}
 
Example 19
Source File: RxJavaFilterOperatorsIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenMixedTypeObservable_whenFilteringByType_thenOnlyNumbersAreEmitted() {

    Observable sourceObservable = Observable.just(1, "two", 3, "five", 7, 11);
    TestSubscriber subscriber = new TestSubscriber();

    Observable filteredObservable = sourceObservable.ofType(String.class);

    filteredObservable.subscribe(subscriber);

    subscriber.assertCompleted();
    subscriber.assertNoErrors();
    subscriber.assertValueCount(2);
    subscriber.assertValues("two", "five");

}
 
Example 20
Source File: ObserveOnTest.java    From akarnokd-misc with Apache License 2.0 4 votes vote down vote up
@Test
public void completeExactRequest() {
    TestSubscriber<Integer> ts = TestSubscriber.create(0);

    TestScheduler test = Schedulers.test();

    Observable.range(1, 10).observeOn(test).subscribe(ts);

    test.advanceTimeBy(1, TimeUnit.SECONDS);

    ts.assertNoValues();
    ts.assertNoErrors();
    ts.assertNotCompleted();

    ts.requestMore(10);

    test.advanceTimeBy(1, TimeUnit.SECONDS);

    ts.assertValueCount(10);
    ts.assertNoErrors();
    ts.assertCompleted();
}