use of com.amplifyframework.auth.AuthException in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignInWithWebUIFails.
/**
* Validates that a failed call to sign-in with web UI will propagate the failure
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignInWithWebUIFails() throws InterruptedException {
Activity activity = new Activity();
// Arrange a failure
AuthException failure = new AuthException("Sign in with web UI", " has failed");
doAnswer(invocation -> {
// 0 = activity, 1 = result consumer, 2 = failure consumer
int positionOfFailureConsumer = 2;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).signInWithWebUI(eq(activity), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignInResult> observer = auth.signInWithWebUI(activity).test();
// Assert: failure is furnished the via the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoValues().assertError(failure);
}
use of com.amplifyframework.auth.AuthException in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testConfirmResetPasswordFails.
/**
* Tests that a failed request to confirm password reset will propagate a failure
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testConfirmResetPasswordFails() throws InterruptedException {
String newPassword = RandomString.string();
String confirmationCode = RandomString.string();
// Arrange delegate to furnish a failure
AuthException failure = new AuthException("Confirm password reset ", " has failed.");
doAnswer(invocation -> {
// 0 = new pass, 1 = confirmation code, 2 = onComplete, 3 = onFailure
int positionOfFailureConsumer = 3;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).confirmResetPassword(eq(newPassword), eq(confirmationCode), anyAction(), anyConsumer());
// Act: call the binding
TestObserver<Void> observer = auth.confirmResetPassword(newPassword, confirmationCode).test();
// Assert: Completable terminated with failure
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNotComplete().assertError(failure);
}
use of com.amplifyframework.auth.AuthException in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testResendSignUpCodeFails.
/**
* Validates that a failed call to resend the sign-up code will propagate the failure
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testResendSignUpCodeFails() throws InterruptedException {
String username = RandomString.string();
// Arrange a failure on the failure consumer
AuthException failure = new AuthException("Reset sign up", " has failed.");
doAnswer(invocation -> {
// 0 = username, 1 = onResult, 2 = onFailure
int positionOfFailureConsumer = 2;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).resendSignUpCode(eq(username), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignUpResult> observer = auth.resendSignUpCode(username).test();
// Assert: the result was furnished to the Rx Single
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoValues().assertError(failure);
}
use of com.amplifyframework.auth.AuthException in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testDeleteUserFails.
/**
* Validate that a delete user failure is propagated up through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testDeleteUserFails() throws InterruptedException {
// Arrange a callback on the failure consumer
AuthException failure = new AuthException("Delete user", "has failed");
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
int positionOfFailureConsumer = 1;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).deleteUser(anyAction(), anyConsumer());
// Act: call the binding
TestObserver<Void> observer = auth.deleteUser().test();
// Assert: failure is furnished via Rx Completable.
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNotComplete().assertError(failure);
}
use of com.amplifyframework.auth.AuthException in project amplify-android by aws-amplify.
the class AuthComponentConfigureTest method testConfigureExceptionHandling.
/**
* If {@link AWSMobileClient} emits an error during initialization, the
* {@link com.amplifyframework.auth.AuthPlugin#configure(JSONObject, Context)} method should wrap that exception
* in an {@link AuthException} and throw it on its calling thread.
* @throws AmplifyException the exception expected to be thrown when configuration fails.
* @throws JSONException has to be declared as part of creating a test JSON object
*/
@Test(expected = AuthException.class)
public void testConfigureExceptionHandling() throws AmplifyException, JSONException {
JSONObject pluginConfig = new JSONObject().put("TestKey", "TestVal");
JSONObject json = new JSONObject().put("plugins", new JSONObject().put(PLUGIN_KEY, pluginConfig));
AuthCategoryConfiguration authConfig = new AuthCategoryConfiguration();
authConfig.populateFromJSON(json);
doAnswer(invocation -> {
Callback<UserStateDetails> callback = invocation.getArgument(2);
callback.onError(new Exception());
return null;
}).when(mobileClient).initialize(any(), any(), any());
authCategory.configure(authConfig, getApplicationContext());
}
Aggregations