use of com.amplifyframework.auth.AuthSession in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testFetchAuthSessionSucceeds.
/**
* Tests that a successful call to fetch the auth session will propagate the session object
* back up through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testFetchAuthSessionSucceeds() throws InterruptedException {
// Arrange an auth session object to return when delegate is called
AuthSession expected = new AuthSession(false);
doAnswer(invocation -> {
// 0 = onResult, 1 = onFailure
int positionOfResultConsumer = 0;
Consumer<AuthSession> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(expected);
return null;
}).when(delegate).fetchAuthSession(anyConsumer(), anyConsumer());
// Act: call the Rx binding
TestObserver<AuthSession> observer = auth.fetchAuthSession().test();
// Assert: AuthSession is furnished to the Rx Single.
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
use of com.amplifyframework.auth.AuthSession in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testFetchAuthSessionFails.
/**
* Tests that a failed call to fetch the auth session will propagate the failure
* back up through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testFetchAuthSessionFails() throws InterruptedException {
// Arrange a failure when the delegate is called
AuthException failure = new AuthException("Fetch session", " has failed.");
doAnswer(invocation -> {
// 0 = onResult, 1 = onFailure
int positionOfFailureConsumer = 1;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).fetchAuthSession(anyConsumer(), anyConsumer());
// Act: call the Rx binding
TestObserver<AuthSession> observer = auth.fetchAuthSession().test();
// Assert: AuthException is furnished to the Rx Single.
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoValues().assertError(failure);
}
Aggregations