Java Code Examples for io.reactivex.observers.TestObserver#assertError()
The following examples show how to use
io.reactivex.observers.TestObserver#assertError() .
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: RxMobiusLoopTest.java From mobius with Apache License 2.0 | 6 votes |
@Test public void shouldPropagateIncomingErrorsAsUnrecoverable() throws Exception { final RxMobiusLoop<Integer, String, Boolean> loop = new RxMobiusLoop<>(builder, "", Collections.emptySet()); PublishSubject<Integer> input = PublishSubject.create(); TestObserver<String> subscriber = input.compose(loop).test(); Exception expected = new RuntimeException("expected"); input.onError(expected); subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS); subscriber.assertError(new UnrecoverableIncomingException(expected)); assertEquals(0, connection.valueCount()); }
Example 2
Source File: DynamicClientRegistrationServiceTest.java From graviteeio-access-management with Apache License 2.0 | 6 votes |
@Test public void create_sectorIdentifierUriBadRequest() { final String sectorUri = "https://sector/uri"; DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest(); request.setRedirectUris(Optional.empty()); request.setSectorIdentifierUri(Optional.of(sectorUri));//fail due to invalid url HttpRequest<Buffer> httpRequest = Mockito.mock(HttpRequest.class); HttpResponse httpResponse = Mockito.mock(HttpResponse.class); when(webClient.getAbs(sectorUri)).thenReturn(httpRequest); when(httpRequest.rxSend()).thenReturn(Single.just(httpResponse)); TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test(); testObserver.assertError(InvalidClientMetadataException.class); testObserver.assertNotComplete(); assertTrue("Should have only one exception", testObserver.errorCount()==1); assertTrue("Unexpected start of error message", testObserver.errors().get(0).getMessage().startsWith("Unable to parse sector_identifier_uri")); }
Example 3
Source File: RxJavaUnitTest.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Test public void test(){ Observable<Todo> todoObservable = Observable.create(new ObservableOnSubscribe<Todo>() { @Override public void subscribe(ObservableEmitter<Todo> emitter) throws Exception { try { List<Todo> todos = RxJavaUnitTest.this.getTodos(); if (todos!=null){ throw new NullPointerException("todos was null"); } for (Todo todo : todos) { emitter.onNext(todo); } emitter.onComplete(); } catch (Exception e) { emitter.onError(e); } } }); TestObserver<Object> testObserver = new TestObserver<>(); todoObservable.subscribeWith(testObserver); testObserver.assertError(NullPointerException.class); }
Example 4
Source File: UserServiceTest.java From graviteeio-access-management with Apache License 2.0 | 6 votes |
@Test public void shouldNotCreate_invalidUserException() { User user = new User(); user.setReferenceType(ReferenceType.DOMAIN); user.setReferenceId(DOMAIN); NewUser newUser = new NewUser(); newUser.setUsername("#####"); when(userRepository.findByUsernameAndSource(ReferenceType.DOMAIN, DOMAIN, newUser.getUsername(), newUser.getSource())).thenReturn(Maybe.empty()); when(userRepository.create(any(User.class))).thenReturn(Single.just(user)); TestObserver<User> testObserver = userService.create(DOMAIN, newUser).test(); testObserver.awaitTerminalEvent(); testObserver.assertError(InvalidUserException.class); verifyZeroInteractions(eventService); }
Example 5
Source File: RxFirebaseStorageTest.java From rxfirebase with Apache License 2.0 | 6 votes |
@Test public void testPutFileWithMetadata_notSuccessful() { mockNotSuccessfulResultForTask(mockUploadTask, new IllegalStateException()); when(mockStorageReference.putFile(mockUri, mockStorageMetadata)).thenReturn(mockUploadTask); TestObserver<UploadTask.TaskSnapshot> obs = TestObserver.create(); RxFirebaseStorage.putFile(mockStorageReference, mockUri, mockStorageMetadata).subscribe(obs); verifyAddOnCompleteListenerForTask(mockUploadTask); callOnComplete(mockUploadTask); obs.dispose(); callOnComplete(mockUploadTask); obs.assertError(IllegalStateException.class); obs.assertNoValues(); }
Example 6
Source File: CoreConnectionManagerTest.java From RxCentralBle with Apache License 2.0 | 6 votes |
@Test public void connect_failed_connectionInProgress() { prepareConnect(false); TestObserver<Peripheral> secondConnect = coreConnectionManager .connect( scanMatcher2, DEFAULT_SCAN_TIMEOUT, ConnectionManager.DEFAULT_CONNECTION_TIMEOUT) .test(); secondConnect.assertError( throwable -> { ConnectionError error = (ConnectionError) throwable; return error != null && error.getCode() == ConnectionError.Code.CONNECTION_IN_PROGRESS; }); }
Example 7
Source File: ApplicationServiceTest.java From graviteeio-access-management with Apache License 2.0 | 6 votes |
@Test public void update_implicitGrant_invalidRedirectUri() { when(applicationRepository.findById(any())).thenReturn(Maybe.just(new Application())); when(domainService.findById(any())).thenReturn(Maybe.just(new Domain())); Application toPatch = new Application(); toPatch.setDomain(DOMAIN); ApplicationSettings settings = new ApplicationSettings(); ApplicationOAuthSettings oAuthSettings = new ApplicationOAuthSettings(); oAuthSettings.setGrantTypes(Arrays.asList("implicit")); oAuthSettings.setResponseTypes(Arrays.asList("token")); oAuthSettings.setClientType(ClientType.PUBLIC); settings.setOauth(oAuthSettings); toPatch.setSettings(settings); TestObserver testObserver = applicationService.update(toPatch).test(); testObserver.awaitTerminalEvent(); testObserver.assertNotComplete(); testObserver.assertError(InvalidRedirectUriException.class); verify(applicationRepository, times(1)).findById(any()); }
Example 8
Source File: RxFirebaseDatabaseTest.java From rxfirebase with Apache License 2.0 | 6 votes |
@Test public void testUpdateChildren_notSuccessful() { Map<String, Object> map = new HashMap<>(); when(mockDatabaseReference.updateChildren(map)) .thenReturn(mockTask); TestObserver sub = TestObserver.create(); RxFirebaseDatabase.updateChildren(mockDatabaseReference, map) .subscribe(sub); verifyAddOnCompleteListenerForTask(); callTaskOnCompleteWithError(new IllegalStateException()); sub.assertNotComplete(); sub.assertError(IllegalStateException.class); sub.dispose(); }
Example 9
Source File: TokenServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldNotRefresh_notTheSameClient() { String clientId = "client-id"; TokenRequest tokenRequest = new TokenRequest(); tokenRequest.setClientId("wrong-client-id"); String token = "refresh-token"; RefreshToken refreshToken = new RefreshToken(); refreshToken.setId(token); refreshToken.setToken(token); refreshToken.setExpireAt(new Date(System.currentTimeMillis() + 10000)); Client client = new Client(); client.setClientId(clientId); JWT jwt = new JWT(); jwt.setJti(token); jwt.setAud(clientId); jwt.setExp(refreshToken.getExpireAt().getTime() / 1000l); when(jwtService.decodeAndVerify(any(), any())).thenReturn(Single.just(jwt)); when(refreshTokenRepository.findByToken(any())).thenReturn(Maybe.just(refreshToken)); TestObserver<Token> testObserver = tokenService.refresh(refreshToken.getToken(), tokenRequest, client).test(); testObserver.assertNotComplete(); testObserver.assertError(InvalidGrantException.class); verify(refreshTokenRepository, times(1)).findByToken(any()); verify(refreshTokenRepository, never()).delete(anyString()); verify(accessTokenRepository, never()).create(any()); }
Example 10
Source File: DomainServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldPatch_domainNotFound() { PatchDomain patchDomain = Mockito.mock(PatchDomain.class); when(domainRepository.findById("my-domain")).thenReturn(Maybe.empty()); TestObserver testObserver = domainService.patch("my-domain", patchDomain).test(); testObserver.assertError(DomainNotFoundException.class); testObserver.assertNotComplete(); verify(domainRepository, times(1)).findById(anyString()); verify(domainRepository, never()).update(any(Domain.class)); }
Example 11
Source File: PreparedPutObjectTest.java From storio with Apache License 2.0 | 5 votes |
@Test public void shouldThrowExceptionIfNoTypeMappingWasFoundWithoutAffectingDbCompletable() { final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class); final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class); when(storIOSQLite.lowLevel()).thenReturn(lowLevel); final Object object = new Object(); final TestObserver<PutResult> testObserver = new TestObserver<PutResult>(); new PreparedPutObject.Builder<Object>(storIOSQLite, object) .prepare() .asRxCompletable() .subscribe(testObserver); testObserver.awaitTerminalEvent(); testObserver.assertNoValues(); testObserver.assertError(StorIOException.class); //noinspection ThrowableResultOfMethodCallIgnored StorIOException expected = (StorIOException) testObserver.errors().get(0); IllegalStateException cause = (IllegalStateException) expected.getCause(); assertThat(cause).hasMessage("Object does not have type mapping: " + "object = " + object + ", object.class = " + object.getClass() + ", " + "db was not affected by this operation, please add type mapping for this type"); verify(storIOSQLite).lowLevel(); verify(storIOSQLite).defaultRxScheduler(); verify(storIOSQLite).interceptors(); verify(lowLevel).typeMapping(Object.class); verifyNoMoreInteractions(storIOSQLite, lowLevel); }
Example 12
Source File: ScopeServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldDelete_notExistingScope() { when(scopeRepository.findById("my-scope")).thenReturn(Maybe.empty()); TestObserver testObserver = new TestObserver(); scopeService.delete("my-scope", false).subscribe(testObserver); testObserver.assertError(ScopeNotFoundException.class); testObserver.assertNotComplete(); }
Example 13
Source File: DynamicClientRegistrationServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void create_unsupportedIdTokenResponseEncPayload() { DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest(); request.setRedirectUris(Optional.empty()); request.setIdTokenEncryptedResponseAlg(Optional.of("RSA-OAEP-256")); request.setIdTokenEncryptedResponseEnc(Optional.of("unknownEncryptionAlg")); TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test(); testObserver.assertError(InvalidClientMetadataException.class); testObserver.assertErrorMessage("Unsupported id_token_encrypted_response_enc value"); testObserver.assertNotComplete(); }
Example 14
Source File: UserServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldNotResetPassword_userInactive() { Client client = mock(Client.class); User user = mock(User.class); when(user.isInactive()).thenReturn(true); TestObserver testObserver = userService.resetPassword(client, user).test(); testObserver.assertNotComplete(); testObserver.assertError(AccountInactiveException.class); }
Example 15
Source File: DomainServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldUpdate_technicalException() { UpdateDomain updateDomain = Mockito.mock(UpdateDomain.class); when(domainRepository.findById("my-domain")).thenReturn(Maybe.error(TechnicalException::new)); TestObserver testObserver = domainService.update("my-domain", updateDomain).test(); testObserver.assertError(TechnicalManagementException.class); testObserver.assertNotComplete(); verify(domainRepository, times(1)).findById(anyString()); verify(domainRepository, never()).update(any(Domain.class)); }
Example 16
Source File: GroupServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldCreate_technicalException() { NewGroup newGroup = Mockito.mock(NewGroup.class); when(newGroup.getName()).thenReturn("name"); when(groupRepository.findByName(ReferenceType.DOMAIN, DOMAIN, newGroup.getName())).thenReturn(Maybe.empty()); when(groupRepository.create(any(Group.class))).thenReturn(Single.error(TechnicalException::new)); TestObserver testObserver = new TestObserver(); groupService.create(DOMAIN, newGroup).subscribe(testObserver); testObserver.assertError(TechnicalManagementException.class); testObserver.assertNotComplete(); }
Example 17
Source File: AsyncTest.java From retrocache with Apache License 2.0 | 5 votes |
@Test public void failure() throws InterruptedException { TestObserver<Void> observer = new TestObserver<>(); service.completable().subscribe(observer); assertFalse(observer.await(1, SECONDS)); server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST)); observer.awaitTerminalEvent(1, SECONDS); observer.assertError(IOException.class); }
Example 18
Source File: ScopeServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldNotUpdateSystemScope() { Scope toUpdate = new Scope(); toUpdate.setId("toUpdateId"); when(scopeRepository.findById("toUpdateId")).thenReturn(Maybe.error(TechnicalException::new)); TestObserver testObserver = scopeService.update(DOMAIN,"toUpdateId", new UpdateSystemScope()).test(); testObserver.assertError(TechnicalManagementException.class); testObserver.assertNotComplete(); }
Example 19
Source File: GroupServiceTest.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Test public void shouldDelete_groupNotFound() { when(groupRepository.findById(ReferenceType.DOMAIN, DOMAIN, "my-group")).thenReturn(Maybe.empty()); TestObserver testObserver = new TestObserver(); groupService.delete(ReferenceType.DOMAIN, DOMAIN, "my-group").subscribe(testObserver); testObserver.assertError(GroupNotFoundException.class); testObserver.assertNotComplete(); verify(groupRepository, never()).delete("my-group"); }
Example 20
Source File: ApplicationServiceTest.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
@Test public void create_failWithNoDomain() { TestObserver testObserver = applicationService.create(new Application()).test(); testObserver.assertNotComplete(); testObserver.assertError(InvalidClientMetadataException.class); }