Java Code Examples for rx.observers.TestSubscriber#assertNoValues()
The following examples show how to use
rx.observers.TestSubscriber#assertNoValues() .
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: OperatorBufferPredicateBoundaryTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
@Test public void bufferWhileBackpressureFullBuffer() { TestSubscriber<List<Integer>> ts = TestSubscriber.create(0); int count = RxRingBuffer.SIZE * 4; Observable.range(1, count) .compose(Transformers.bufferWhile(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 2
Source File: AwaitableEventSubscriberDecoratorTest.java From mesos-rxjava with Apache License 2.0 | 6 votes |
@Test public void awaitEventWorks_onError() throws Exception { final TestSubscriber<String> testSubscriber = new TestSubscriber<>(); final AwaitableEventSubscriberDecorator<String> sub = new AwaitableEventSubscriberDecorator<>(testSubscriber); final BehaviorSubject<String> subject = BehaviorSubject.create(); final Subscription subscription = subject.subscribe(sub); final RuntimeException e = new RuntimeException("doesn't matter"); async.run(() -> subject.onError(e)); sub.awaitEvent(); testSubscriber.assertNoValues(); testSubscriber.assertError(e); subscription.unsubscribe(); }
Example 3
Source File: UploadInteractorImplTest.java From RxUploader with Apache License 2.0 | 6 votes |
@Test public void testUploadFileNotFound() throws Exception { final String jobId = "job-id"; final Job job = Job.builder() .setId(jobId) .setFilepath("invalid") .setMetadata(Collections.emptyMap()) .setMimeType("text/plain") .setStatus(Status.createQueued(jobId)) .build(); when(dataStore.get(jobId)).thenReturn(Observable.just(job)); final TestSubscriber<Status> ts = TestSubscriber.create(); uploadInteractor.upload(jobId).subscribe(ts); testScheduler.triggerActions(); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); ts.assertError(FileNotFoundException.class); ts.assertNoValues(); verify(uploader, times(0)).upload(any(Job.class), any(File.class)); }
Example 4
Source File: DatabaseHelperTest.java From ribot-app-android with Apache License 2.0 | 6 votes |
@Test public void setRegisteredBeaconsWithEmptyListClearsData() { List<RegisteredBeacon> existingBeacons = MockModelFabric.newRegisteredBeaconList(10); mDatabaseHelper.setRegisteredBeacons(existingBeacons).subscribe(); TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); mDatabaseHelper.setRegisteredBeacons(new ArrayList<RegisteredBeacon>()) .subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); Cursor cursor = mDatabaseHelper.getBriteDb() .query("SELECT * FROM " + Db.BeaconTable.TABLE_NAME); assertEquals(0, cursor.getCount()); }
Example 5
Source File: AwaitableEventSubscriberDecoratorTest.java From mesos-rxjava with Apache License 2.0 | 6 votes |
@Test public void awaitEventWorks_onCompleted() throws Exception { final TestSubscriber<String> testSubscriber = new TestSubscriber<>(); final AwaitableEventSubscriberDecorator<String> sub = new AwaitableEventSubscriberDecorator<>(testSubscriber); final BehaviorSubject<String> subject = BehaviorSubject.create(); final Subscription subscription = subject.subscribe(sub); async.run(subject::onCompleted); sub.awaitEvent(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); subscription.unsubscribe(); }
Example 6
Source File: RxGcmTest.java From RxGcm with Apache License 2.0 | 6 votes |
@Test public void When_Saved_Token_No_Call_GcmServer_And_Not_Emit_Items() throws Exception { when(getGcmServerTokenMock.retrieve(applicationMock)).thenReturn(MOCK_TOKEN); when(persistenceMock.getToken(applicationMock)).thenReturn(MOCK_TOKEN); TestSubscriber<String> subscriberMock = new TestSubscriber<>(); RxGcm.Notifications .register(applicationMock, GcmReceiverDataMock.class, GcmReceiverMockUIBackground.class) .subscribe(subscriberMock); subscriberMock.awaitTerminalEvent(); subscriberMock.assertNoValues(); subscriberMock.assertNoErrors(); subscriberMock.assertCompleted(); verify(getGcmServerTokenMock, times(0)).retrieve(applicationMock); }
Example 7
Source File: DatabaseHelperTest.java From ribot-app-android with Apache License 2.0 | 5 votes |
@Test public void setRegisteredBeacons() { List<RegisteredBeacon> beacons = MockModelFabric.newRegisteredBeaconList(3); TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); mDatabaseHelper.setRegisteredBeacons(beacons).subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); checkBeaconsSavedSuccessfully(beacons); }
Example 8
Source File: OnSubscribeDoOnEmptyTest.java From rxjava-extras with Apache License 2.0 | 5 votes |
@Test public void ifSourceEmitsErrorThenDoOnEmptyIsNotRun() { TestSubscriber<Object> ts = TestSubscriber.create(); AtomicBoolean set = new AtomicBoolean(false); Exception ex = new Exception("boo"); Observable.error(ex) // .compose(Transformers.doOnEmpty(Actions.setToTrue0(set))) // .subscribe(ts); assertFalse(set.get()); ts.assertError(ex); ts.assertNoValues(); }
Example 9
Source File: ObservableServerSocketTest.java From rxjava-extras with Apache License 2.0 | 5 votes |
@Test public void testAcceptSocketRejectsAlways() throws UnknownHostException, IOException, InterruptedException { reset(); TestSubscriber<Object> ts = TestSubscriber.create(); try { int bufferSize = 4; AtomicInteger port = new AtomicInteger(); IO.serverSocketAutoAllocatePort(Actions.setAtomic(port)) // .readTimeoutMs(10000) // .acceptTimeoutMs(200) // .bufferSize(bufferSize) // .acceptSocketIf(Functions.alwaysFalse()) // .create() // .subscribeOn(scheduler) // .subscribe(ts); Thread.sleep(300); Socket socket = new Socket("localhost", port.get()); OutputStream out = socket.getOutputStream(); out.write("12345678901234567890".getBytes()); out.close(); socket.close(); Thread.sleep(1000); ts.assertNoValues(); } finally { // will close server socket ts.unsubscribe(); } }
Example 10
Source File: RxGcmTest.java From RxGcm with Apache License 2.0 | 5 votes |
@Test public void When_Call_On_Token_Refresh_Emit_Properly_Item() throws Exception { TestSubscriber<TokenUpdate> subscriberMock = GcmRefreshTokenReceiverMock.initSubscriber(); when(persistenceMock.getClassNameGcmRefreshTokenReceiver(applicationMock)).thenReturn(GcmRefreshTokenReceiverMock.class.getName()); when(getGcmServerTokenMock.retrieve(applicationMock)).thenReturn(MOCK_TOKEN); RxGcm.Notifications.onTokenRefreshed(); subscriberMock.awaitTerminalEvent(); subscriberMock.assertNoErrors(); TokenUpdate token1 = subscriberMock.getOnNextEvents().get(0); assertThat(token1.getToken(), is(MOCK_TOKEN)); subscriberMock = GcmRefreshTokenReceiverMock.initSubscriber(); reset(getGcmServerTokenMock); String errorMessage = "GCM not available"; when(getGcmServerTokenMock.retrieve(applicationMock)).thenThrow(new RuntimeException(errorMessage)); RxGcm.Notifications.onTokenRefreshed(); subscriberMock.awaitTerminalEvent(); subscriberMock.assertNoValues(); assertThat(subscriberMock.getOnErrorEvents().get(0).getMessage(), is(errorMessage)); subscriberMock = GcmRefreshTokenReceiverMock.initSubscriber(); reset(getGcmServerTokenMock); when(getGcmServerTokenMock.retrieve(applicationMock)).thenReturn(MOCK_TOKEN + 1); RxGcm.Notifications.onTokenRefreshed(); subscriberMock.awaitTerminalEvent(); subscriberMock.assertNoErrors(); TokenUpdate token2 = subscriberMock.getOnNextEvents().get(0); assertThat(token2.getToken(), is(MOCK_TOKEN + 1)); reset(getGcmServerTokenMock); when(persistenceMock.getClassNameGcmRefreshTokenReceiver(applicationMock)).thenReturn(null); try { RxGcm.Notifications.onTokenRefreshed(); subscriberMock.awaitTerminalEvent(); } catch (Exception ignore) { assertThat(subscriberMock.getOnErrorEvents().size(), is(1)); subscriberMock.assertValueCount(2); } }
Example 11
Source File: DataManagerTest.java From ribot-app-android with Apache License 2.0 | 5 votes |
@Test public void getTodayLatestCheckInWhenLatestWasBeforeToday() { CheckIn checkIn = MockModelFabric.newCheckInWithVenue(); checkIn.checkedInDate.setTime(System.currentTimeMillis() - DateUtils.DAY_IN_MILLIS); doReturn(Observable.just(checkIn)) .when(mMockPreferencesHelper) .getLatestCheckInAsObservable(); TestSubscriber<CheckIn> testSubscriber = new TestSubscriber<>(); mDataManager.getTodayLatestCheckIn().subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertNoValues(); }
Example 12
Source File: DataManagerTest.java From ribot-app-android with Apache License 2.0 | 5 votes |
@Test public void checkInFail() { CheckInRequest request = CheckInRequest.fromLabel(MockModelFabric.randomString()); doReturn(Observable.error(new RuntimeException())) .when(mMockRibotsService) .checkIn(anyString(), eq(request)); TestSubscriber<CheckIn> testSubscriber = new TestSubscriber<>(); mDataManager.checkIn(request).subscribe(testSubscriber); testSubscriber.assertError(RuntimeException.class); testSubscriber.assertNoValues(); verify(mMockPreferencesHelper, never()).putLatestCheckIn(any(CheckIn.class)); }
Example 13
Source File: PresenterSubscriptionsTest.java From base_app_android with Apache License 2.0 | 5 votes |
@Test public void When_Unsubscribe_Subscription_With_Several_Subscriptions_Do_Not_Get_Response() { TestSubscriber<Object> subscriberMock1 = new TestSubscriber(); presenterUT.safetyReportError(getExpensiveObservable()) .disposable(observable -> observable.subscribe(subscriberMock1)); TestSubscriber<Object> subscriberMock2 = new TestSubscriber(); presenterUT.safetyReportError(getExpensiveObservable()) .disposable(observable -> observable.subscribe(subscriberMock1)); presenterUT.dispose(); waitForIt(); subscriberMock1.assertNoValues(); subscriberMock2.assertNoValues(); }
Example 14
Source File: DatabaseHelperTest.java From ribot-app-android with Apache License 2.0 | 5 votes |
@Test public void setRegisteredBeaconsDeletesPreviousData() { List<RegisteredBeacon> existingBeacons = MockModelFabric.newRegisteredBeaconList(10); mDatabaseHelper.setRegisteredBeacons(existingBeacons).subscribe(); List<RegisteredBeacon> newBeacons = MockModelFabric.newRegisteredBeaconList(5); TestSubscriber<Void> testSubscriber = new TestSubscriber<>(); mDatabaseHelper.setRegisteredBeacons(newBeacons).subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertNoValues(); testSubscriber.assertCompleted(); checkBeaconsSavedSuccessfully(newBeacons); }
Example 15
Source File: RxJavaSkipOperatorsIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void givenRangeObservable_whenIgnoringElements_thenOnlyDistinctConsecutiveItemsAreEmitted() { Observable<Integer> sourceObservable = Observable.range(1, 10); TestSubscriber<Integer> subscriber = new TestSubscriber(); Observable<Integer> ignoredObservable = sourceObservable.ignoreElements(); ignoredObservable.subscribe(subscriber); subscriber.assertCompleted(); subscriber.assertNoErrors(); subscriber.assertValueCount(0); subscriber.assertNoValues(); }
Example 16
Source File: OnSubscribeDoOnEmptyTest.java From rxjava-extras with Apache License 2.0 | 5 votes |
@Test public void ifOnEmptyActionThrowsNonFatalRuntimeExceptionThenErrorEmitted() { TestSubscriber<Object> ts = TestSubscriber.create(); Observable.empty() // .compose(Transformers.doOnEmpty(Actions.throw0(new NumberFormatException()))) // .subscribe(ts); ts.assertNoValues(); ts.assertTerminalEvent(); ts.assertError(NumberFormatException.class); }
Example 17
Source File: OrderedMergeTest.java From rxjava-extras with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testErrorImmediately() { Observable<Integer> o1 = Observable.just(1, 3, 5, 7); Observable<Integer> o2 = Observable.<Integer> error(new TestException()); TestSubscriber<Integer> ts = TestSubscriber.create(); OrderedMerge.create(Arrays.asList(o1, o2)).subscribe(ts); ts.assertError(TestException.class); ts.assertNotCompleted(); ts.assertNoValues(); }
Example 18
Source File: TransformersTest.java From rxjava-extras with Apache License 2.0 | 5 votes |
@Test // @org.junit.Ignore public void testDelayFinalUnsubscribeForRefCount() { TestScheduler s = new TestScheduler(); final AtomicInteger count = new AtomicInteger(); Observable<Long> o = Observable // .interval(1, TimeUnit.SECONDS, s) // .doOnSubscribe(Actions.increment0(count)) // .publish() // .refCount() // .compose(Transformers.<Long> delayFinalUnsubscribe(2500, TimeUnit.MILLISECONDS, s)); { TestSubscriber<Long> ts1 = TestSubscriber.create(); o.subscribe(ts1); assertEquals(1, count.get()); s.advanceTimeBy(1, TimeUnit.SECONDS); ts1.assertValues(0L); ts1.unsubscribe(); } s.advanceTimeBy(1, TimeUnit.SECONDS); { TestSubscriber<Long> ts2 = TestSubscriber.create(); o.subscribe(ts2); ts2.assertNoValues(); s.advanceTimeBy(1, TimeUnit.SECONDS); ts2.assertValues(2L); ts2.unsubscribe(); } assertEquals(1, count.get()); s.advanceTimeBy(2500, TimeUnit.MILLISECONDS); { TestSubscriber<Long> ts3 = TestSubscriber.create(); s.advanceTimeBy(1, TimeUnit.SECONDS); o.subscribe(ts3); assertEquals(2, count.get()); s.advanceTimeBy(1, TimeUnit.SECONDS); ts3.assertValues(0L); } }
Example 19
Source File: TransformerOnTerminateResumeTest.java From rxjava-extras with Apache License 2.0 | 3 votes |
@Test public void mainCompletesBackpressure() { Transformer<Integer, Integer> op = new TransformerOnTerminateResume<Integer>(new Func1<Throwable, Observable<Integer>>() { @Override public Observable<Integer> call(Throwable e) { return Observable.just(11); } }, Observable.just(12)); TestSubscriber<Integer> ts = TestSubscriber.create(0); Observable.range(1, 10) .compose(op) .subscribe(ts); ts.assertNoValues(); ts.requestMore(2); ts.assertValues(1, 2); ts.requestMore(5); ts.assertValues(1, 2, 3, 4, 5, 6, 7); ts.requestMore(3); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); ts.requestMore(1); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12); ts.assertNoErrors(); ts.assertCompleted(); }
Example 20
Source File: TransformerOnTerminateResumeTest.java From rxjava-extras with Apache License 2.0 | 3 votes |
@Test public void mainErrorsBackpressure() { Transformer<Integer, Integer> op = new TransformerOnTerminateResume<Integer>(new Func1<Throwable, Observable<Integer>>() { @Override public Observable<Integer> call(Throwable e) { return Observable.just(11); } }, Observable.just(12)); TestSubscriber<Integer> ts = TestSubscriber.create(0); Observable.range(1, 10).concatWith(Observable.<Integer>error(new IOException())) .compose(op) .subscribe(ts); ts.assertNoValues(); ts.requestMore(2); ts.assertValues(1, 2); ts.requestMore(5); ts.assertValues(1, 2, 3, 4, 5, 6, 7); ts.requestMore(3); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); ts.requestMore(1); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); ts.assertNoErrors(); ts.assertCompleted(); }