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

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

    TestSubscriber<FirebaseUser> testSubscriber = new TestSubscriber<>();
    RxFirebaseAuth.observeAuthState(mockAuth)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    ArgumentCaptor<FirebaseAuth.AuthStateListener> argument = ArgumentCaptor.forClass(FirebaseAuth.AuthStateListener.class);
    verify(mockAuth).addAuthStateListener(argument.capture());
    argument.getValue().onAuthStateChanged(mockAuth);

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

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

    testOnSuccessListener.getValue().onSuccess(uploadSnapshot);

    verify(mockStorageRef).putFile(uri, metadata);

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

    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().onCancelled(DatabaseError.fromCode(DatabaseError.DISCONNECTED));

    testSubscriber.assertError(RxFirebaseDataException.class);
    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 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 5
Source File: RecordIOOperatorTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@NotNull
static List<Event> runTestOnChunks(@NotNull final List<ByteBuf> chunks) {
    final TestSubscriber<byte[]> child = new TestSubscriber<>();
    final Subscriber<ByteBuf> call = new RecordIOOperator().call(child);

    assertThat(call).isInstanceOf(RecordIOOperator.RecordIOSubscriber.class);

    final RecordIOOperator.RecordIOSubscriber subscriber = (RecordIOOperator.RecordIOSubscriber) call;
    chunks.stream().forEach(subscriber::onNext);
    child.assertNoErrors();
    child.assertNotCompleted();
    child.assertNoTerminalEvent();
    assertThat(subscriber.messageSizeBytesBuffer).isEmpty();
    assertThat(subscriber.messageBytes).isNull();
    assertThat(subscriber.remainingBytesForMessage).isEqualTo(0);

    return CollectionUtils.listMap(child.getOnNextEvents(), (bs) -> {
        try {
            return Event.parseFrom(bs);
        } catch (InvalidProtocolBufferException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example 6
Source File: OperatorBufferPredicateBoundaryTest.java    From rxjava-extras with Apache License 2.0 6 votes vote down vote up
@Test
public void bufferUntilPredicateThrows() {
    TestSubscriber<List<Integer>> ts = new TestSubscriber<List<Integer>>();
    
    Observable.just(1, 2, 3, null, 4, 5)
    .compose(Transformers.bufferUntil(new Func1<Integer, Boolean>() {
        @Override
        public Boolean call(Integer v) {
            return v == 20;
        }
    }))
    .subscribe(ts);
    
    ts.assertNoValues();
    ts.assertError(NullPointerException.class);
    ts.assertNotCompleted();
}
 
Example 7
Source File: OperatorBufferPredicateBoundaryTest.java    From rxjava-extras with Apache License 2.0 6 votes vote down vote up
@Test
public void bufferUntilBackpressureFullBuffer() {
    TestSubscriber<List<Integer>> ts = TestSubscriber.create(0);
    
    int count = RxRingBuffer.SIZE * 4;
    
    Observable.range(1, count)
    .compose(Transformers.bufferUntil(UtilityFunctions.<Integer>alwaysFalse()))
    .subscribe(ts);
    
    ts.assertNoValues();
    ts.assertNoErrors();
    ts.assertNotCompleted();
    
    ts.requestMore(1);
    
    ts.assertValueCount(1);
    ts.assertNoErrors();
    ts.assertCompleted();
    
    Assert.assertEquals(count, ts.getOnNextEvents().get(0).size());
}
 
Example 8
Source File: RxFirebaseDatabaseTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testObserveChildEvent_Changed() {

    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().onChildChanged(mockFirebaseDataSnapshot, "root");

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

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

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

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(testData));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 10
Source File: RetryUtilsTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
private void validateFailure(Single<StoreResponse> single, long timeout, Class<? extends Throwable> class1) {

        TestSubscriber<StoreResponse> testSubscriber = new TestSubscriber<>();
        single.toObservable().subscribe(testSubscriber);
        testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS);
        testSubscriber.assertNotCompleted();
        testSubscriber.assertTerminalEvent();
        assertThat(testSubscriber.getOnErrorEvents()).hasSize(1);
        if (!(testSubscriber.getOnErrorEvents().get(0).getClass().equals(class1))) {
            fail("Not expecting " + testSubscriber.getOnErrorEvents().get(0));
        }
    }
 
Example 11
Source File: OperatorBufferPredicateBoundaryTest.java    From rxjava-extras with Apache License 2.0 5 votes vote down vote up
@Test
public void errorSourceBufferUntil() {
    TestSubscriber<List<Integer>> ts = new TestSubscriber<List<Integer>>();

    Observable.<Integer>error(new IOException())
    .compose(Transformers.bufferUntil(UtilityFunctions.<Integer>alwaysTrue()))
    .subscribe(ts);
    
    ts.assertNoValues();
    ts.assertError(IOException.class);
    ts.assertNotCompleted();
}
 
Example 12
Source File: QueryHandlerTest.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHavePipeliningDisabled() {
    Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create();
    RawQueryRequest requestMock1 = mock(RawQueryRequest.class);
    when(requestMock1.query()).thenReturn("SELECT * FROM `foo`");
    when(requestMock1.bucket()).thenReturn("foo");
    when(requestMock1.username()).thenReturn("foo");
    when(requestMock1.password()).thenReturn("");
    when(requestMock1.observable()).thenReturn(obs1);
    when(requestMock1.isActive()).thenReturn(true);

    Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create();
    RawQueryRequest requestMock2 = mock(RawQueryRequest.class);
    when(requestMock2.query()).thenReturn("SELECT * FROM `foo`");
    when(requestMock2.bucket()).thenReturn("foo");
    when(requestMock2.username()).thenReturn("foo");
    when(requestMock2.password()).thenReturn("");
    when(requestMock2.observable()).thenReturn(obs2);
    when(requestMock2.isActive()).thenReturn(true);

    TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create();
    TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create();

    obs1.subscribe(t1);
    obs2.subscribe(t2);

    channel.writeOutbound(requestMock1, requestMock2);

    t1.assertNotCompleted();
    t2.assertError(RequestCancelledException.class);
}
 
Example 13
Source File: RxPermissionsTest.java    From rx-android-permissions with Apache License 2.0 5 votes vote down vote up
public void testObserveAndRequestPermissions() {

        TestSubscriber<Boolean> observeSubscriber = new TestSubscriber<>();
        TestSubscriber<Boolean> requestSubscriber = new TestSubscriber<>();

        RxPermissionsUnderTest permissions = new RxPermissionsUnderTest(getContext(), false);
        MockPermissionsRequester requester = new MockPermissionsRequester(false);

        permissions.observe(
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(observeSubscriber);

        permissions.request(requester,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(requestSubscriber);

        requester.granted = true;
        requester.request();

        observeSubscriber.assertValues(false, false, false, false, true);
        observeSubscriber.assertNoErrors();
        observeSubscriber.assertNotCompleted();

        requestSubscriber.assertValues(false, false, true);
        requestSubscriber.assertNoErrors();
        requestSubscriber.assertCompleted();
    }
 
Example 14
Source File: SchedulersLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenLetters_whenTestScheduling_thenReturnValuesControllingAdvanceTime() throws InterruptedException {
    List<String> letters = Arrays.asList("A", "B", "C");
    TestScheduler scheduler = Schedulers.test();
    TestSubscriber<String> subscriber = new TestSubscriber<>();

    Observable<Long> tick = Observable.interval(1, TimeUnit.SECONDS, scheduler);

    Observable.from(letters)
      .zipWith(tick, (string, index) -> index + "-" + string)
      .subscribeOn(scheduler)
      .subscribe(subscriber);

    subscriber.assertNoValues();
    subscriber.assertNotCompleted();

    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    subscriber.assertNoErrors();
    subscriber.assertValueCount(1);
    subscriber.assertValues("0-A");

    scheduler.advanceTimeTo(3, TimeUnit.SECONDS);
    subscriber.assertCompleted();
    subscriber.assertNoErrors();
    subscriber.assertValueCount(3);
    assertThat(subscriber.getOnNextEvents(), hasItems("0-A", "1-B", "2-C"));
}
 
Example 15
Source File: SortedMergeTest.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void testErrorImmediately() {
    Observable<Integer> o1 = Observable.just(1, 3, 5, 7);
    Observable<Integer> o2 = Observable.<Integer>error(new RuntimeException());

    TestSubscriber<Integer> ts = new TestSubscriber<>();
    SortedMerge.create(Arrays.asList(o1, o2)).subscribe(ts);

    ts.assertError(RuntimeException.class);
    ts.assertNotCompleted();
    ts.assertNoValues();
}
 
Example 16
Source File: RxGoroTest.java    From goro with Apache License 2.0 5 votes vote down vote up
@Test
public void unsubscribe() {
  TestSubscriber<String> subscriber = new TestSubscriber<>();
  Observable.just("ok")
      .subscribeOn(rxGoro.scheduler())
      .subscribe(subscriber)
      .unsubscribe();

  queues.executeAll();
  subscriber.assertNoErrors();
  subscriber.assertNoValues();
  subscriber.assertNotCompleted();
}
 
Example 17
Source File: KeyValueHandlerTest.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHavePipeliningEnabled() {
    Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create();
    GetRequest requestMock1 = mock(GetRequest.class);
    when(requestMock1.keyBytes()).thenReturn("hello".getBytes());
    when(requestMock1.bucket()).thenReturn("foo");
    when(requestMock1.observable()).thenReturn(obs1);

    Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create();
    GetRequest requestMock2 = mock(GetRequest.class);
    when(requestMock2.keyBytes()).thenReturn("hello".getBytes());

    when(requestMock2.bucket()).thenReturn("foo");
    when(requestMock2.observable()).thenReturn(obs2);


    TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create();
    TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create();

    obs1.subscribe(t1);
    obs2.subscribe(t2);

    channel.writeOutbound(requestMock1, requestMock2);

    t1.assertNotCompleted();
    t2.assertNotCompleted();
}
 
Example 18
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 19
Source File: OnSubscribeDoOnEmptyTest.java    From rxjava-extras with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsubscribeAfterActionButBeforeCompletionMeansStreamDoesNotComplete() {
    final TestSubscriber<Object> ts = TestSubscriber.create();
    Observable.empty() //
     .compose(Transformers.doOnEmpty(new Action0() {
        @Override
        public void call() {
            ts.unsubscribe();
        }})).subscribe(ts);
   ts.assertNoValues();
   ts.assertNotCompleted();
}
 
Example 20
Source File: OperatorBufferPredicateBoundaryTest.java    From rxjava-extras with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void bufferWhileBackpressure() {
    TestSubscriber<List<Integer>> ts = TestSubscriber.create(0);
    
    Observable.range(1, RxRingBuffer.SIZE * 4)
    .compose(Transformers.bufferWhile(new Func1<Integer, Boolean>() {
        @Override
        public Boolean call(Integer v) {
            return (v % 3) == 0;
        }
    })).subscribe(ts);
    
    ts.assertNoValues();
    ts.assertNoErrors();
    ts.assertNotCompleted();
    
    ts.requestMore(1);
    
    ts.assertValue(Arrays.asList(1, 2));

    ts.requestMore(1);
    ts.assertValues(
            Arrays.asList(1, 2),
            Arrays.asList(3, 4, 5)
    );
    ts.assertNoErrors();
    ts.assertNotCompleted();
    
    ts.requestMore(1);
    ts.assertValues(
            Arrays.asList(1, 2),
            Arrays.asList(3, 4, 5),
            Arrays.asList(6, 7, 8)
    );
    ts.assertNoErrors();
    ts.assertNotCompleted();
    
    ts.requestMore(Long.MAX_VALUE);
    
    ts.assertValueCount((RxRingBuffer.SIZE * 4) / 3 + 1);
    ts.assertNoErrors();
    ts.assertCompleted();
}