use of com.amplifyframework.auth.AuthProvider in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInWithSocialWebUISucceeds.
/**
* Validates that a successful call to sign-in with social web UI will propagate the result
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInWithSocialWebUISucceeds() throws InterruptedException {
AuthProvider provider = AuthProvider.amazon();
Activity activity = new Activity();
// Arrange a successful result
AuthSignInStep step = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE;
AuthCodeDeliveryDetails details = new AuthCodeDeliveryDetails(RandomString.string(), DeliveryMedium.PHONE);
AuthNextSignInStep nextStep = new AuthNextSignInStep(step, Collections.emptyMap(), details);
AuthSignInResult result = new AuthSignInResult(false, nextStep);
doAnswer(invocation -> {
// 0 = provider, 1 = activity, 2 = result consumer, 3 = failure consumer
int positionOfResultConsumer = 2;
Consumer<AuthSignInResult> onResult = invocation.getArgument(positionOfResultConsumer);
onResult.accept(result);
return null;
}).when(delegate).signInWithSocialWebUI(eq(provider), eq(activity), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signInWithSocialWebUI(provider, activity).test();
// Assert: result is furnished the via the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(result);
}
use of com.amplifyframework.auth.AuthProvider in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInWithSocialWebUIFails.
/**
* Validates that a failed call to sign-in with social web UI will propagate the failure
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInWithSocialWebUIFails() throws InterruptedException {
AuthProvider provider = AuthProvider.amazon();
Activity activity = new Activity();
// Arrange a failure
AuthException failure = new AuthException("Sign in with social provider", " has failed");
doAnswer(invocation -> {
// 0 = provider, 1 = activity, 2 = result consumer, 3 = failure consumer
int positionOfFailureConsumer = 3;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).signInWithSocialWebUI(eq(provider), eq(activity), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signInWithSocialWebUI(provider, activity).test();
// Assert: failure is furnished the via the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoValues().assertError(failure);
}
Aggregations