rx.observers.TestSubscriber Java Examples
The following examples show how to use
rx.observers.TestSubscriber.
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: AwsLoadBalancerConnectorTest.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Test public void validateExceptionsAreUnmodifiedWithMockClientTest() { Class defaultExceptionClass = TargetGroupAssociationLimitException.class; TestSubscriber testSubscriber = new TestSubscriber(); AmazonElasticLoadBalancingAsync albClient = mock(AmazonElasticLoadBalancingAsync.class); when(albClient.describeTargetHealthAsync(any(), any())).thenThrow(defaultExceptionClass); awsLoadBalancerConnector = getAwsLoadBalancerConnector(albClient); awsLoadBalancerConnector.getLoadBalancer(targetGroupWithTargets).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); List<Throwable> errors = testSubscriber.getOnErrorEvents(); assertEquals(1, errors.size()); Throwable throwable = errors.get(0); assertFalse(throwable instanceof LoadBalancerException); assertTrue(throwable instanceof TargetGroupAssociationLimitException); }
Example #2
Source File: EnvironmentServiceTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void environmentService_findById() { Integer ENVIRONMENT_ID = 110; EnvironmentModel environment = new EnvironmentModel(); environment.setId(ENVIRONMENT_ID); when(environmentRepository.findById(ENVIRONMENT_ID)).thenReturn(Observable.just(environment)); TestSubscriber<EnvironmentModel> tester = new TestSubscriber<>(); environmentService.findById(ENVIRONMENT_ID).subscribe(tester); verify(environmentRepository).findById(ENVIRONMENT_ID); tester.assertValue(environment); tester.assertCompleted(); tester.assertNoErrors(); }
Example #3
Source File: AbstractEndpointTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldForceTimeoutOfSocketConnectDoesNotReturn() { BootstrapAdapter bootstrap = mock(BootstrapAdapter.class); when(bootstrap.connect()).thenReturn(channel.newPromise()); // this promise never completes Endpoint endpoint = new DummyEndpoint(bootstrap, ctx); Observable<LifecycleState> observable = endpoint.connect(); TestSubscriber<LifecycleState> testSubscriber = new TestSubscriber<LifecycleState>(); observable.subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); List<Throwable> errors = testSubscriber.getOnErrorEvents(); assertEquals(1, errors.size()); assertEquals(ConnectTimeoutException.class, errors.get(0).getClass()); endpoint.disconnect().subscribe(); }
Example #4
Source File: KeyValueHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldPropagateErrorOnEncode() { String id = "key"; ByteBuf content = Unpooled.buffer(); content.release(); // provoke a IllegalReferenceCountException UpsertRequest request = new UpsertRequest(id, content, BUCKET); request.partition((short) 1); TestSubscriber<CouchbaseResponse> ts = TestSubscriber.create(); request.observable().subscribe(ts); try { channel.writeOutbound(request); fail("Expected exception, none thrown."); } catch (EncoderException ex) { assertTrue(ex.getCause() instanceof IllegalReferenceCountException); } List<Throwable> onErrorEvents = ts.getOnErrorEvents(); assertTrue(onErrorEvents.get(0) instanceof RequestCancelledException); assertTrue(onErrorEvents.get(0).getCause() instanceof IllegalReferenceCountException); }
Example #5
Source File: EnergyServiceTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void energyService_findByEnvironment() { Integer ENVIRONMENT = 108; List<EnergyModel> energies = new ArrayList<>(); when(energyRepository.findByEnvironment(ENVIRONMENT)).thenReturn(Observable.just(energies)); TestSubscriber<List<EnergyModel>> tester = new TestSubscriber<>(); energyService.findByEnvironment(ENVIRONMENT).subscribe(tester); verify(energyRepository).findByEnvironment(ENVIRONMENT); tester.assertValue(energies); tester.assertCompleted(); tester.assertNoErrors(); }
Example #6
Source File: OperatorBufferPredicateBoundaryTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void bufferUntilSomeNull() { 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 != null && v == 20; } })) .subscribe(ts); ts.assertValues( Arrays.asList(1, 2, 3, null, 4, 5) ); ts.assertNoErrors(); ts.assertCompleted(); }
Example #7
Source File: HystrixBuilderTest.java From feign with Apache License 2.0 | 6 votes |
@Test public void rxObservableInt() { server.enqueue(new MockResponse().setBody("1")); final TestInterface api = target(); final Observable<Integer> observable = api.intObservable(); assertThat(observable).isNotNull(); assertThat(server.getRequestCount()).isEqualTo(0); final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>(); observable.subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); Assertions.assertThat(testSubscriber.getOnNextEvents().get(0)).isEqualTo(new Integer(1)); }
Example #8
Source File: RxFirebaseAuthTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@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 #9
Source File: LightServiceTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void lightService_add() { String LIGHT_UUID = "myUuid"; LightModel lightModel = new LightModel(); when(lightRepository.add(lightModel)).thenReturn(Observable.just(LIGHT_UUID)); TestSubscriber<String> tester = new TestSubscriber<>(); lightService.add(lightModel).subscribe(tester); verify(lightRepository).add(lightModel); tester.assertValue(LIGHT_UUID); tester.assertCompleted(); tester.assertNoErrors(); }
Example #10
Source File: ScenarioServiceTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void scenarioService_findByEnvironment() { Integer ENVIRONMENT = 108; List<ScenarioModel> scenarios = new ArrayList<>(); when(scenarioRepository.findByEnvironment(ENVIRONMENT)).thenReturn(Observable.just(scenarios)); TestSubscriber<List<ScenarioModel>> tester = new TestSubscriber<>(); scenarioService.findByEnvironment(ENVIRONMENT).subscribe(tester); verify(scenarioRepository).findByEnvironment(ENVIRONMENT); tester.assertValue(scenarios); tester.assertCompleted(); tester.assertNoErrors(); }
Example #11
Source File: UploaderTest.java From RxUploader with Apache License 2.0 | 6 votes |
@Test public void testUploadFailedUnhandledException() throws Exception { final File file = getFile(TEST_FILE); final String jobId = "job-id"; final Job job = Job.builder() .setId(jobId) .setStatus(Status.createQueued(jobId)) .setMetadata(Collections.emptyMap()) .setFilepath(file.getPath()) .setMimeType("text/plain") .build(); final UploadService service = mock(UploadService.class); when(service.upload(anyMap(), any(MultipartBody.Part.class))) .thenThrow(new RuntimeException("")); final Uploader uploader = new Uploader(service, Schedulers.io()); final TestSubscriber<Status> ts = TestSubscriber.create(); uploader.upload(job, file).subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); ts.assertError(RuntimeException.class); ts.assertNoValues(); }
Example #12
Source File: OperatorBufferPredicateBoundaryTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void bufferUntilWith5() { TestSubscriber<List<Integer>> ts = new TestSubscriber<List<Integer>>(); Observable.range(1, 10) .compose(Transformers.bufferUntil(new Func1<Integer, Boolean>() { @Override public Boolean call(Integer v) { return v == 5; } })) .subscribe(ts); ts.assertValues( Arrays.asList(1, 2, 3, 4, 5), Arrays.asList(6, 7, 8, 9, 10) ); ts.assertNoErrors(); ts.assertCompleted(); }
Example #13
Source File: RxStringOperatorsUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenStringObservable_whenEncodingString_ThenSuccessfullObtainingByteStream() { //given Observable<String> sourceObservable = Observable.just("Lorem ipsum loream"); TestSubscriber<byte[]> subscriber = TestSubscriber.create(); // when StringObservable.encode(sourceObservable, StandardCharsets.UTF_8) .subscribe(subscriber); // then subscriber.assertCompleted(); subscriber.assertNoErrors(); subscriber.assertValueCount(1); subscriber.getOnNextEvents() .stream() .forEach(bytes -> Assert.assertTrue(Arrays.equals(bytes, "Lorem ipsum loream".getBytes(StandardCharsets.UTF_8)))); }
Example #14
Source File: HystrixBuilderTest.java From feign with Apache License 2.0 | 6 votes |
@Test public void rxObservableFallback() { server.enqueue(new MockResponse().setResponseCode(500)); final TestInterface api = target(); final Observable<String> observable = api.observable(); assertThat(observable).isNotNull(); assertThat(server.getRequestCount()).isEqualTo(0); final TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); observable.subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); Assertions.assertThat(testSubscriber.getOnNextEvents().get(0)).isEqualTo("fallback"); }
Example #15
Source File: DataManagerTest.java From ribot-app-android with Apache License 2.0 | 6 votes |
@Test public void performBeaconEncounter() { String beaconId = MockModelFabric.randomString(); Encounter encounter = MockModelFabric.newEncounter(); doReturn(Observable.just(encounter)) .when(mMockRibotsService) .performBeaconEncounter(anyString(), eq(beaconId)); TestSubscriber<Encounter> testSubscriber = new TestSubscriber<>(); mDataManager.performBeaconEncounter(beaconId).subscribe(testSubscriber); testSubscriber.assertCompleted(); testSubscriber.assertValue(encounter); verify(mMockPreferencesHelper).putLatestEncounter(encounter); }
Example #16
Source File: EnvironmentRepositoryTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void environmentRepository_findById() { Integer ENVIRONMENT_ID = 100; EnvironmentModel environment = newEnvironmentModel(ENVIRONMENT_ID, "myName"); List<EnvironmentModel> environments = Arrays.asList(environment); when(databaseRealm.findCopyWhere(EnvironmentModel.class, EnvironmentModel.FIELD_ID, ENVIRONMENT_ID, null)) .thenReturn(environments); TestSubscriber<EnvironmentModel> tester = new TestSubscriber<>(); environmentRepository.findById(ENVIRONMENT_ID).subscribe(tester); verify(databaseRealm).findCopyWhere(EnvironmentModel.class, EnvironmentModel.FIELD_ID, ENVIRONMENT_ID, null); tester.assertValue(environment); tester.assertCompleted(); tester.assertNoErrors(); }
Example #17
Source File: DomoticRepositoryTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void lightRepository_findFavourites() { SampleModel model = new SampleModel(); model.setUuid("uuid1"); model.setEnvironmentId(108); model.setFavourite(true); List<SampleModel> lights = Arrays.asList(model); when(databaseRealm.findCopyWhere(SampleModel.class, DomoticModel.FIELD_FAVOURITE, true, DomoticModel.FIELD_NAME)).thenReturn(lights); TestSubscriber<List<SampleModel>> tester = new TestSubscriber<>(); sampleRepository.findFavourites().subscribe(tester); verify(databaseRealm).findCopyWhere(SampleModel.class, DomoticModel.FIELD_FAVOURITE, true, DomoticModel.FIELD_NAME); tester.assertValue(lights); tester.assertCompleted(); tester.assertNoErrors(); }
Example #18
Source File: AwaitableEventSubscriberDecoratorTest.java From mesos-rxjava with Apache License 2.0 | 6 votes |
@Test public void awaitEventWorks() 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.onNext("hello"); subject.onNext("world"); subject.onNext("!"); subject.onCompleted(); }); sub.awaitEvent(Integer.MAX_VALUE); testSubscriber.assertValues("hello", "world", "!"); testSubscriber.assertCompleted(); testSubscriber.assertNoErrors(); subscription.unsubscribe(); }
Example #19
Source File: RxAggregateOperatorsUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenObservable_whenUsingToSortedListWithComparator_thenObtainedAnInverseSortedList() { // given Observable<Integer> sourceObservable = Observable.range(10, 5); TestSubscriber<List> subscriber = TestSubscriber.create(); // when Observable<List<Integer>> listObservable = sourceObservable.toSortedList((int1, int2) -> int2 - int1); listObservable.subscribe(subscriber); // then subscriber.assertCompleted(); subscriber.assertNoErrors(); subscriber.assertValueCount(1); subscriber.assertValue(Arrays.asList(14, 13, 12, 11, 10)); }
Example #20
Source File: SoundServiceTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void soundService_findById() { String SOUND_UUID = "myUuid"; SoundModel soundModel = new SoundModel(); soundModel.setUuid(SOUND_UUID); when(soundRepository.findById(SOUND_UUID)).thenReturn(Observable.just(soundModel)); TestSubscriber<SoundModel> tester = new TestSubscriber<>(); soundService.findById(SOUND_UUID).subscribe(tester); verify(soundRepository).findById(SOUND_UUID); tester.assertValue(soundModel); tester.assertCompleted(); tester.assertNoErrors(); }
Example #21
Source File: ObservableServerSocketTest.java From rxjava-extras with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws InterruptedException { reset(); TestSubscriber<Object> ts = TestSubscriber.create(); IO.serverSocket(12345).readTimeoutMs(10000).bufferSize(8).create() .flatMap(new Func1<Observable<byte[]>, Observable<byte[]>>() { @Override public Observable<byte[]> call(Observable<byte[]> g) { return g // .compose(Bytes.collect()) // .doOnNext(new Action1<byte[]>() { @Override public void call(byte[] bytes) { System.out.println(Thread.currentThread().getName() + ": " + new String(bytes).trim()); } }) // .onErrorResumeNext(Observable.<byte[]> empty()) // .subscribeOn(scheduler); } }).subscribeOn(scheduler) // .subscribe(ts); Thread.sleep(10000000); }
Example #22
Source File: RxFirebaseAuthTests.java From RxFirebase with Apache License 2.0 | 6 votes |
@Test public void fetchProvidersForEmail() { TestSubscriber<ProviderQueryResult> testSubscriber = new TestSubscriber<>(); RxFirebaseAuth.fetchProvidersForEmail(mockAuth, "email") .subscribeOn(Schedulers.immediate()) .subscribe(testSubscriber); testOnSuccessListener.getValue().onSuccess(mockProviderQueryResult); testOnCompleteListener.getValue().onComplete(mockProviderQueryResultTask); verify(mockAuth).fetchProvidersForEmail(eq("email")); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertReceivedOnNext(Collections.singletonList(mockProviderQueryResult)); testSubscriber.assertCompleted(); testSubscriber.unsubscribe(); }
Example #23
Source File: PooledServiceTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void selectionStrategyShouldNotBeCalledWithEmptyEndpoints() { EndpointFactoryMock ef = EndpointFactoryMock.simple(envCtx); ef.onConnectTransition(new Func1<Endpoint, LifecycleState>() { @Override public LifecycleState call(Endpoint endpoint) { return LifecycleState.DISCONNECTING; } }); SelectionStrategy ss = mock(SelectionStrategy.class); MockedService ms = new MockedService(ServiceType.QUERY, ef, ssc(0, 2), ss); ms.connect().toBlocking().single(); Tuple2<CouchbaseRequest, TestSubscriber<CouchbaseResponse>> mr1 = mockRequest(); ms.send(mr1.value1()); verify(ss, never()).select(any(CouchbaseRequest.class), any(List.class)); }
Example #24
Source File: IpcamServiceTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void ipcamService_findByEnvironment() { Integer ENVIRONMENT = 108; List<IpcamModel> ipcams = new ArrayList<>(); when(ipcamRepository.findByEnvironment(ENVIRONMENT)).thenReturn(Observable.just(ipcams)); TestSubscriber<List<IpcamModel>> tester = new TestSubscriber<>(); ipcamService.findByEnvironment(ENVIRONMENT).subscribe(tester); verify(ipcamRepository).findByEnvironment(ENVIRONMENT); tester.assertValue(ipcams); tester.assertCompleted(); tester.assertNoErrors(); }
Example #25
Source File: RxJavaTimeFilteringOperatorsIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenTimedObservable_whenThrottlingLast_thenThrottleLastItemsAreEmitted() { TestScheduler testScheduler = new TestScheduler(); Observable<Integer> timedObservable = Observable.just(1, 2, 3, 4, 5, 6) .zipWith( Observable.interval(0, 1, TimeUnit.SECONDS, testScheduler), (item, time) -> item ); TestSubscriber<Integer> subscriber = new TestSubscriber(); Observable<Integer> filteredObservable = timedObservable.throttleLast(3100L, TimeUnit.MILLISECONDS, testScheduler); filteredObservable.subscribe(subscriber); testScheduler.advanceTimeBy(7, TimeUnit.SECONDS); subscriber.assertCompleted(); subscriber.assertNoErrors(); subscriber.assertValues(4, 6); }
Example #26
Source File: LightServiceTest.java From openwebnet-android with MIT License | 5 votes |
@Test public void lightService_requestFavourites() { List<LightModel> lights = new ArrayList<>(); mockClient(); when(lightRepository.findFavourites()).thenReturn(Observable.just(lights)); TestSubscriber<List<LightModel>> tester = new TestSubscriber<>(); lightService.requestFavourites().subscribe(tester); tester.assertValue(lights); tester.assertCompleted(); tester.assertNoErrors(); }
Example #27
Source File: RxEventBusTest.java From Stock-Hawk with Apache License 2.0 | 5 votes |
@Test public void filteredObservableOnlyReceivesSomeObjects() { TestSubscriber<String> testSubscriber = new TestSubscriber<>(); mEventBus.filteredObservable(String.class).subscribe(testSubscriber); String stringEvent = "Event"; Integer intEvent = 20; mEventBus.post(stringEvent); mEventBus.post(intEvent); testSubscriber.assertValueCount(1); testSubscriber.assertValue(stringEvent); }
Example #28
Source File: PooledServiceTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldNotCreateNewEndpointOrAcceptRequestIfNodeIsDown() { EndpointFactoryMock ef = EndpointFactoryMock.simple(envCtx); ef.onCreate(new Action2<Endpoint, BehaviorSubject<LifecycleState>>() { @Override public void call(final Endpoint endpoint, final BehaviorSubject<LifecycleState> states) { when(endpoint.connect()).then(new Answer<Observable<LifecycleState>>() { @Override public Observable<LifecycleState> answer(InvocationOnMock invocation) throws Throwable { states.onNext(LifecycleState.DISCONNECTING); return Observable.error(new ConnectException("could not connect to remote")); } }); } }); SelectionStrategy ss = new RoundRobinSelectionStrategy(); MockedService ms = new MockedService(ServiceType.QUERY, ef, ssc(0, 1), ss); ms.connect().toBlocking().single(); Tuple2<CouchbaseRequest, TestSubscriber<CouchbaseResponse>> mr1 = mockRequest(); ms.send(mr1.value1()); ef.advanceAll(LifecycleState.CONNECTED); assertEquals(1, ef.endpointCount()); mr1.value2().assertError(RequestCancelledException.class); Tuple2<CouchbaseRequest, TestSubscriber<CouchbaseResponse>> mr2 = mockRequest(); ms.send(mr2.value1()); // Second request should not create another endpoint assertEquals(1, ef.endpointCount()); assertEquals(0, ef.endpointSendCalled()); mr1.value2().assertError(RequestCancelledException.class); }
Example #29
Source File: FontDownloaderTest.java From fontster with Apache License 2.0 | 5 votes |
@Test public void testDownloadAllFonts_filesExist() throws Exception { TestSubscriber<File> testSubscriber = new TestSubscriber<>(); FontDownloader fontDownloader = new FontDownloader(new MockFontPackage(MOCK_FONT_PACK_NAME)); fontDownloader.downloadAllFonts().subscribe(testSubscriber); testSubscriber.assertNoErrors(); File downloadedFontPack = new File(MockFontPackage.TEST_FOLDER, MOCK_FONT_PACK_NAME + "FontPack"); assertTrue(downloadedFontPack.exists()); assertTrue(downloadedFontPack.isDirectory()); assertEquals(Style.values().length, downloadedFontPack.listFiles().length); }
Example #30
Source File: SnapshotFuncTest.java From RxGoogleMaps with Apache License 2.0 | 5 votes |
@Test public void shouldProvideBitmap() throws Exception { TestSubscriber<Bitmap> testSubscriber = new TestSubscriber<>(); new SnapshotFunc().call(googleMap) .subscribe(testSubscriber); verify(googleMap).snapshot(argumentCaptor.capture()); argumentCaptor.getValue().onSnapshotReady(null); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); testSubscriber.assertValue(null); }