Java Code Examples for io.reactivex.observers.TestObserver

The following examples show how to use io.reactivex.observers.TestObserver. These examples are extracted from open source projects. 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
@Test
public void shouldResetPassword_externalIdEmpty() {
    final String domain = "domain";
    final String password = "password";

    User user = mock(User.class);
    when(user.getId()).thenReturn("user-id");
    when(user.getUsername()).thenReturn("username");
    when(user.getSource()).thenReturn("default-idp");

    io.gravitee.am.identityprovider.api.User idpUser = mock(io.gravitee.am.identityprovider.api.DefaultUser.class);
    when(idpUser.getId()).thenReturn("idp-id");

    UserProvider userProvider = mock(UserProvider.class);
    when(userProvider.findByUsername(user.getUsername())).thenReturn(Maybe.just(idpUser));
    when(userProvider.update(anyString(), any())).thenReturn(Single.just(idpUser));

    when(commonUserService.findById(eq(ReferenceType.DOMAIN), eq(domain), eq("user-id"))).thenReturn(Single.just(user));
    when(identityProviderManager.getUserProvider(user.getSource())).thenReturn(Maybe.just(userProvider));
    when(commonUserService.update(any())).thenReturn(Single.just(user));
    when(loginAttemptService.reset(any())).thenReturn(Completable.complete());

    TestObserver testObserver = userService.resetPassword(domain, user.getId(), password).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
}
 
Example 2
@Test
public void testSearch_strict() {
    final String domain = "domain";
    // create app
    Application app = new Application();
    app.setDomain(domain);
    app.setName("clientId");
    applicationRepository.create(app).blockingGet();

    Application app2 = new Application();
    app2.setDomain(domain);
    app2.setName("clientId2");
    applicationRepository.create(app2).blockingGet();

    // fetch user
    TestObserver<Page<Application>> testObserver = applicationRepository.search(domain, "clientId", 0, Integer.MAX_VALUE).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(apps -> apps.getData().size() == 1);
    testObserver.assertValue(apps -> apps.getData().iterator().next().getName().equals(app.getName()));

}
 
Example 3
Source Project: sqlbrite   Source File: QueryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void mapToOneOrDefaultReturnsDefaultWhenNullCursor() {
  Employee defaultEmployee = new Employee("bob", "Bob Bobberson");
  Query nully = new Query() {
    @Nullable @Override public Cursor run() {
      return null;
    }
  };

  TestObserver<Employee> observer = new TestObserver<>();
  Observable.just(nully)
      .lift(Query.mapToOneOrDefault(MAPPER, defaultEmployee))
      .subscribe(observer);

  observer.assertValues(defaultEmployee);
  observer.assertComplete();
}
 
Example 4
@Test
public void shouldRevokeRoles_roleNotFound() {
    List<String> rolesIds = Arrays.asList("role-1", "role-2");

    Group group = mock(Group.class);
    when(group.getId()).thenReturn("group-id");

    Set<Role> roles = new HashSet<>();
    Role role1 = new Role();
    role1.setId("role-1");
    Role role2 = new Role();
    role2.setId("role-2");
    roles.add(role1);
    roles.add(role2);

    when(groupRepository.findById(eq(ReferenceType.DOMAIN), eq(DOMAIN), eq("group-id"))).thenReturn(Maybe.just(group));
    when(roleService.findByIdIn(rolesIds)).thenReturn(Single.just(Collections.emptySet()));

    TestObserver testObserver = groupService.revokeRoles(ReferenceType.DOMAIN, DOMAIN, group.getId(), rolesIds).test();
    testObserver.assertNotComplete();
    testObserver.assertError(RoleNotFoundException.class);
    verify(groupRepository, never()).update(any());
}
 
Example 5
Source Project: RxGroups   Source File: ObservableGroupTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void shouldAutoResubscribeAfterUnlock() throws InterruptedException {
  ObservableGroup group = observableManager.newGroup();
  TestObserver<String> testObserver = new TestObserver<>();
  PublishSubject<String> sourceObservable = PublishSubject.create();

  group.lock();
  sourceObservable.compose(group.transform(testObserver)).subscribe(testObserver);

  sourceObservable.onNext("Chespirito");
  sourceObservable.onComplete();

  group.unlock();

  testObserver.assertComplete();
  testObserver.assertNoErrors();
  testObserver.assertValue("Chespirito");
  assertThat(group.hasObservables(fooObserver)).isEqualTo(false);
}
 
Example 6
@Test
public void shouldGenerateAnAccessToken() {
    LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set(Parameters.USERNAME, "my-username");
    parameters.set(Parameters.PASSWORD, "my-password");

    Client client = new Client();
    client.setClientId("my-client-id");
    client.setAuthorizedGrantTypes(Arrays.asList(new String[]{"password"}));

    Token accessToken = new AccessToken("test-token");

    when(tokenRequest.parameters()).thenReturn(parameters);
    when(tokenRequest.createOAuth2Request()).thenReturn(new OAuth2Request());

    when(tokenRequestResolver.resolve(any(), any(), any())).thenReturn(Single.just(tokenRequest));
    when(tokenService.create(any(), any(), any())).thenReturn(Single.just(accessToken));
    when(userAuthenticationManager.authenticate(any(Client.class), any(Authentication.class))).thenReturn(Single.just(new User()));

    TestObserver<Token> testObserver = granter.grant(tokenRequest, client).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(token -> token.getValue().equals("test-token"));

}
 
Example 7
@Test
public void shouldEnhanceToken_withoutIDToken() {
    OAuth2Request oAuth2Request = new OAuth2Request();
    oAuth2Request.setClientId("client-id");
    // no openid scope for the request

    Client client = new Client();

    Token accessToken = new AccessToken("token-id");

    TestObserver<Token> testObserver = tokenEnhancer.enhance(accessToken, oAuth2Request, client, null, null).test();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(accessToken1 -> accessToken1.getAdditionalInformation().isEmpty());
}
 
Example 8
@Test
public void shouldCreate_whiteSpaces() {
    NewScope newScope = Mockito.mock(NewScope.class);
    when(newScope.getKey()).thenReturn("MY scope");
    when(scopeRepository.findByDomainAndKey(DOMAIN, "MY_scope")).thenReturn(Maybe.empty());
    when(scopeRepository.create(any(Scope.class))).thenReturn(Single.just(new Scope()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));

    TestObserver testObserver = scopeService.create(DOMAIN, newScope).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();

    verify(scopeRepository, times(1)).create(any(Scope.class));
    verify(scopeRepository, times(1)).create(argThat(new ArgumentMatcher<Scope>() {
        @Override
        public boolean matches(Scope scope) {
            return scope.getKey().equals("MY_scope");
        }
    }));
    verify(eventService, times(1)).create(any());
}
 
Example 9
@Test
public void testWithWrongAudience() {
    String assertion = new PlainJWT(
            new JWTClaimsSet.Builder()
                    .issuer(ISSUER)
                    .subject(CLIENT_ID)
                    .audience("wrongAudience")
                    .expirationTime(Date.from(Instant.now().plus(1, ChronoUnit.DAYS)))
                    .build()
    ).serialize();

    OpenIDProviderMetadata openIDProviderMetadata = Mockito.mock(OpenIDProviderMetadata.class);
    String basePath="/";

    when(openIDProviderMetadata.getTokenEndpoint()).thenReturn(AUDIENCE);
    when(openIDDiscoveryService.getConfiguration(basePath)).thenReturn(openIDProviderMetadata);

    TestObserver testObserver = clientAssertionService.assertClient(JWT_BEARER_TYPE,assertion,basePath).test();

    testObserver.assertError(InvalidClientException.class);
    testObserver.assertNotComplete();
}
 
Example 10
Source Project: AndroidGodEye   Source File: ThreadDumpTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void work2() {
    ((TestScheduler) ThreadUtil.computationScheduler()).advanceTimeBy(5, TimeUnit.SECONDS);
    try {
        TestObserver<List<ThreadInfo>> subscriber = new TestObserver<>();
        GodEye.instance().<ThreadDump, List<ThreadInfo>>moduleObservable(GodEye.ModuleName.THREAD).subscribe(subscriber);
        subscriber.assertValue(new Predicate<List<ThreadInfo>>() {
            @Override
            public boolean test(List<ThreadInfo> threadInfos) throws Exception {
                return threadInfos != null && !threadInfos.isEmpty();
            }
        });
    } catch (UninstallException e) {
        Assert.fail();
    }
}
 
Example 11
Source Project: rxfirebase   Source File: RxFirebaseDatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testChildEvents_Query_notSuccessful() {
    TestObserver<ChildEvent> sub = TestObserver.create();

    RxFirebaseDatabase.childEvents(mockQuery)
            .subscribe(sub);

    verifyQueryAddChildEventListener();
    callChildOnCancelled();

    sub.assertNoValues();
    assertThat(sub.errorCount())
            .isEqualTo(1);

    sub.dispose();

    callChildOnCancelled();

    // Ensure no more values are emitted after unsubscribe
    assertThat(sub.errorCount())
            .isEqualTo(1);
}
 
Example 12
@Test
public void shouldCreateUser_invalid_identity_provider() {
    final String domain = "domain";

    Domain domain1 = mock(Domain.class);
    when(domain1.getId()).thenReturn(domain);

    NewUser newUser = mock(NewUser.class);
    when(newUser.getUsername()).thenReturn("username");
    when(newUser.getSource()).thenReturn("unknown-idp");

    when(domainService.findById(domain)).thenReturn(Maybe.just(domain1));
    when(commonUserService.findByDomainAndUsernameAndSource(anyString(), anyString(), anyString())).thenReturn(Maybe.empty());
    when(identityProviderManager.getUserProvider(anyString())).thenReturn(Maybe.empty());

    TestObserver<User> testObserver = userService.create(domain, newUser).test();
    testObserver.assertNotComplete();
    testObserver.assertError(UserProviderNotFoundException.class);
    verify(commonUserService, never()).create(any());
}
 
Example 13
@Test
public void shouldRevoke_accessToken() {
    final RevocationTokenRequest revocationTokenRequest = new RevocationTokenRequest("token");

    Client client = new Client();
    client.setClientId("client-id");

    AccessToken accessToken = new AccessToken("token");
    accessToken.setClientId("client-id");

    when(tokenService.getAccessToken("token", client)).thenReturn(Maybe.just(accessToken));
    when(tokenService.deleteAccessToken("token")).thenReturn(Completable.complete());

    TestObserver testObserver = revocationTokenService.revoke(revocationTokenRequest, client).test();

    testObserver.assertComplete();
    testObserver.assertNoErrors();

    verify(tokenService, times(1)).getAccessToken("token", client);
    verify(tokenService, times(1)).deleteAccessToken("token");
    verify(tokenService, never()).getRefreshToken(anyString(), any());
    verify(tokenService, never()).deleteRefreshToken(anyString());

}
 
Example 14
Source Project: rxfirebase   Source File: RxFirebaseUserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLinkWithCredential() {
    mockSuccessfulAuthResult();
    when(mockFirebaseUser.linkWithCredential(mockAuthCredential))
            .thenReturn(mockAuthTaskResult);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseUser.linkWithCredential(mockFirebaseUser, mockAuthCredential)
            .subscribe(obs);

    callOnComplete(mockAuthTaskResult);
    obs.dispose();

    // Ensure no more values are emitted after unsubscribe
    callOnComplete(mockAuthTaskResult);

    obs.assertComplete();
    obs.assertValueCount(1);
}
 
Example 15
Source Project: rxfirebase   Source File: RxFirebaseAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInWithCredential() {
    mockSuccessfulAuthResult();

    when(mockFirebaseAuth.signInWithCredential(mockAuthCredential))
            .thenReturn(mockAuthResultTask);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseAuth
            .signInWithCredential(mockFirebaseAuth, mockAuthCredential)
            .subscribe(obs);

    callOnComplete(mockAuthResultTask);
    obs.dispose();

    // Ensure no more values are emitted after unsubscribe
    callOnComplete(mockAuthResultTask);

    obs.assertComplete();
    obs.assertValueCount(1);
}
 
Example 16
@Test
public void shouldCreate() {
    NewTag newTag = Mockito.mock(NewTag.class);
    when(newTag.getName()).thenReturn("my-tag");
    when(tagRepository.findById("my-tag", Organization.DEFAULT)).thenReturn(Maybe.empty());
    when(tagRepository.create(any(Tag.class))).thenReturn(Single.just(new Tag()));

    TestObserver testObserver = tagService.create(newTag, Organization.DEFAULT, null).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();

    verify(tagRepository, times(1)).findById(eq("my-tag"), eq(Organization.DEFAULT));
    verify(tagRepository, times(1)).create(any(Tag.class));
}
 
Example 17
@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 18
Source Project: rxfirebase   Source File: RxFirebaseStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void testGetMetaData_notSuccessful() {
  mockNotSuccessfulResultForTask(mockStorageMetadataTask, new IllegalStateException());
  when(mockStorageReference.getMetadata()).thenReturn(mockStorageMetadataTask);

  TestObserver<StorageMetadata> obs = TestObserver.create();

  RxFirebaseStorage.getMetadata(mockStorageReference).subscribe(obs);
  verifyAddOnCompleteListenerForTask(mockStorageMetadataTask);

  callOnComplete(mockStorageMetadataTask);
  obs.dispose();

  callOnComplete(mockStorageMetadataTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
Example 19
@Test
public void shouldUpdate() {
    UpdateDomain updateDomain = Mockito.mock(UpdateDomain.class);
    when(domainRepository.findById("my-domain")).thenReturn(Maybe.just(new Domain()));
    when(domainRepository.update(any(Domain.class))).thenReturn(Single.just(new Domain()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));

    TestObserver testObserver = domainService.update("my-domain", updateDomain).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();

    verify(domainRepository, times(1)).findById(anyString());
    verify(domainRepository, times(1)).update(any(Domain.class));
    verify(eventService, times(1)).create(any());
}
 
Example 20
Source Project: rxfirebase   Source File: RxFirebaseStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test public void testUpdateMetadata_notSuccessful() {
  mockNotSuccessfulResultForTask(mockStorageMetadataTask, new IllegalStateException());

  TestObserver<StorageMetadata> obs = TestObserver.create();
  when(mockStorageReference.updateMetadata(mockStorageMetadata)).thenReturn(
      mockStorageMetadataTask);
  RxFirebaseStorage.updateMetadata(mockStorageReference, mockStorageMetadata).subscribe(obs);

  verifyAddOnCompleteListenerForTask(mockStorageMetadataTask);

  callOnComplete(mockStorageMetadataTask);
  obs.dispose();

  callOnComplete(mockStorageMetadataTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
Example 21
Source Project: alpha-wallet-android   Source File: GetKeystoreWalletRepoTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testImportStore() {
	TestObserver<Wallet> subscriber = accountKeystoreService
			.importKeystore(STORE_1, PASS_1, PASS_1)
			.toObservable()
			.test();
	subscriber.awaitTerminalEvent();
	subscriber.assertComplete();
	subscriber.assertNoErrors();

	subscriber.assertOf(accountTestObserver -> {
		assertEquals(accountTestObserver.valueCount(), 1);
		assertEquals(accountTestObserver.values().get(0).address, ADDRESS_1);
		assertTrue(accountTestObserver.values().get(0).sameAddress(ADDRESS_1));
	});
	deleteAccountStore(ADDRESS_1, PASS_1);
}
 
Example 22
@Test
public void shouldCreateDefault() {

    when(entrypointRepository.create(any(Entrypoint.class))).thenAnswer(i -> Single.just(i.getArgument(0)));

    TestObserver<Entrypoint> obs = cut.createDefault(ORGANIZATION_ID).test();

    obs.awaitTerminalEvent();
    obs.assertValue(entrypoint -> entrypoint.getId() != null
            && entrypoint.isDefaultEntrypoint() && entrypoint.getOrganizationId().equals(ORGANIZATION_ID));

    verify(auditService, times(1)).report(argThat(builder -> {
        Audit audit = builder.build(new ObjectMapper());
        assertEquals(EventType.ENTRYPOINT_CREATED, audit.getType());
        assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
        assertEquals(ORGANIZATION_ID, audit.getReferenceId());
        assertEquals("system", audit.getActor().getId());

        return true;
    }));
}
 
Example 23
@Test
public void shouldFindUserConsent() {
    final ScopeApproval scopeApproval = new ScopeApproval();
    scopeApproval.setId("consentId");

    when(scopeApprovalService.findById("consentId")).thenReturn(Maybe.just(scopeApproval));

    TestObserver<ScopeApproval> testObserver = userService.consent("consentId").test();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(scopeApproval1 -> scopeApproval1.getId().equals("consentId"));
}
 
Example 24
@Test
public void grant_client_additionalCase() {
    parameters.remove(CLAIM_TOKEN);
    parameters.remove(CLAIM_TOKEN_FORMAT);
    tokenRequest.setScopes(new HashSet<>(Arrays.asList("scopeB", "scopeC")));
    TestObserver<Token> testObserver = umaTokenGranter.grant(tokenRequest, client).test();
    testObserver.assertComplete().assertNoErrors().assertValue(token -> "success".equals(token.getValue()));
    OAuth2Request result = oauth2RequestCaptor.getValue();
    assertNull(result.getSubject());
    assertTrue(assertAdditionalScopePermissions(result.getPermissions()));
    assertFalse(result.isSupportRefreshToken());
}
 
Example 25
@Test
public void shouldUpdate_implicit_invalidRedirectUri() {
    Application client = new Application();
    ApplicationSettings clientSettings = new ApplicationSettings();
    ApplicationOAuthSettings clientOAuthSettings = new ApplicationOAuthSettings();
    clientOAuthSettings.setClientType(ClientType.PUBLIC);
    clientSettings.setOauth(clientOAuthSettings);
    client.setDomain(DOMAIN);
    client.setSettings(clientSettings);

    PatchApplication patchClient = new PatchApplication();
    PatchApplicationSettings patchApplicationSettings = new PatchApplicationSettings();
    PatchApplicationOAuthSettings patchApplicationOAuthSettings = new PatchApplicationOAuthSettings();
    patchApplicationOAuthSettings.setGrantTypes(Optional.of(Arrays.asList("implicit")));
    patchApplicationOAuthSettings.setResponseTypes(Optional.of(Arrays.asList("token")));
    patchApplicationSettings.setOauth(Optional.of(patchApplicationOAuthSettings));
    patchClient.setSettings(Optional.of(patchApplicationSettings));

    when(applicationRepository.findById("my-client")).thenReturn(Maybe.just(client));
    when(domainService.findById(DOMAIN)).thenReturn(Maybe.just(new Domain()));

    TestObserver testObserver = applicationService.patch(DOMAIN, "my-client", patchClient).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertNotComplete();
    testObserver.assertError(InvalidRedirectUriException.class);

    verify(applicationRepository, times(1)).findById(anyString());
}
 
Example 26
@Test
public void shouldUpdate_technicalException() {
    PatchApplication patchClient = Mockito.mock(PatchApplication.class);
    when(applicationRepository.findById("my-client")).thenReturn(Maybe.error(TechnicalException::new));

    TestObserver testObserver = applicationService.patch(DOMAIN, "my-client", patchClient).test();
    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();

    verify(applicationRepository, times(1)).findById(anyString());
    verify(applicationRepository, never()).update(any(Application.class));
}
 
Example 27
@Test
public void shouldFindByDomain_technicalException() {
    when(applicationRepository.findByDomain(DOMAIN, 0, Integer.MAX_VALUE)).thenReturn(Single.error(TechnicalException::new));

    TestObserver testObserver = new TestObserver<>();
    applicationService.findByDomain(DOMAIN).subscribe(testObserver);

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}
 
Example 28
@Test
public void shouldFindTotalTokensByDomain() {
    Application app1 = new Application();
    app1.setId("app1");
    ApplicationSettings app1Settings = new ApplicationSettings();
    ApplicationOAuthSettings app1oAuthSettings = new ApplicationOAuthSettings();
    app1oAuthSettings.setClientId(app1.getId());
    app1Settings.setOauth(app1oAuthSettings);
    app1.setSettings(app1Settings);

    Application app2 = new Application();
    app2.setId("app2");
    ApplicationSettings app2Settings = new ApplicationSettings();
    ApplicationOAuthSettings app2oAuthSettings = new ApplicationOAuthSettings();
    app2oAuthSettings.setClientId(app2.getId());
    app2Settings.setOauth(app2oAuthSettings);
    app2.setSettings(app2Settings);

    Set<Application> applications = new HashSet<>(Arrays.asList(app1, app2));

    when(applicationService.findByDomain(DOMAIN)).thenReturn(Single.just(applications));
    when(accessTokenRepository.countByClientId("app1")).thenReturn(Single.just(2l));
    when(accessTokenRepository.countByClientId("app2")).thenReturn(Single.just(1l));

    TestObserver<TotalToken> testObserver = tokenService.findTotalTokensByDomain(DOMAIN).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValue(totalToken -> totalToken.getTotalAccessTokens() == 3l);
}
 
Example 29
@Test
public void shouldFindById() {
    when(domainRepository.findById("my-domain")).thenReturn(Maybe.just(new Domain()));
    TestObserver testObserver = domainService.findById("my-domain").test();

    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValueCount(1);
}
 
Example 30
@Test
public void manyToOne() {
    RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
    Flowable<HelloRequest> req = Flowable.just(
            HelloRequest.newBuilder().setName("a").build(),
            HelloRequest.newBuilder().setName("b").build(),
            HelloRequest.newBuilder().setName("c").build());

    Single<HelloResponse> resp = req.as(stub::sayHelloReqStream);

    TestObserver<String> testObserver = resp.map(HelloResponse::getMessage).test();
    testObserver.awaitTerminalEvent(3, TimeUnit.SECONDS);
    testObserver.assertValue("Hello a and b and c");
}