@Test
public void getAmazonS3WhenInitiallyAbsent() {

    final BehaviorSubject<Optional<CognitoCachingCredentialsProvider>> subject = BehaviorSubject.create();
    when(cognitoManager.getCognitoCachingCredentialsProvider()).thenReturn(subject);
    subject.onNext(Optional.<CognitoCachingCredentialsProvider>absent());
    TestObserver<Optional<AmazonS3Client>> testObserver = s3ClientFactory.getAmazonS3().test();
    testObserver
            .assertValueCount(1)
            .assertNotComplete()
            .assertNoErrors();
    final Optional<AmazonS3Client> s3Client1 = s3ClientFactory.getAmazonS3().blockingFirst();
    assertFalse(s3Client1.isPresent());
    // Now re-drive with an actual value:
    subject.onNext(Optional.of(cognitoCachingCredentialsProvider));
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    final Optional<AmazonS3Client> s3Client2 = s3ClientFactory.getAmazonS3().blockingFirst();
    assertTrue(s3Client2.isPresent());
}