@Test public void shouldReturnInvalidEmailAddressIfUserEmailAddressDoesEqualSuppliedEmailAddress() { when(mpm.getUserByUserIdOrEmail(any(String.class))).thenReturn(Optional.of(user)); when(user.getEmail()).thenReturn("other.address"); ResetPasswordResult result = handler.execute(action, context); assertThat(result.getResultCode(), is(ResetPasswordResultCode.INVALID_EMAIL_ADDRESS)); }
@Test public void shouldReturnSuccessIfEmailAddressComparesEqualIgnoreCase() { when(mpm.getUserByUserIdOrEmail(any(String.class))).thenReturn(Optional.of(user)); when(user.getEmail()).thenReturn("email.address"); ResetPasswordResult result = handler.execute(action, context); assertThat(result.getResultCode(), is(ResetPasswordResultCode.SUCCESS)); }
@Test public void shouldReturnErrorOnException() { when(mpm.getUserByUserIdOrEmail(any(String.class))).thenReturn(Optional.of(user)); when(user.getEmail()).thenReturn(EMAIL_ADDRESS); doThrow(new RuntimeException()).when(user).setPassword(any(String.class)); ResetPasswordResult result = handler.execute(action, context); assertThat(result.getResultCode(), is(ResetPasswordResultCode.INTERNAL_ERROR)); }
@Test public void shouldReturnInvalidEmailAddressIfCannotFindAnyUser() { when(mpm.getUserByUserIdOrEmail(any(String.class))).thenReturn(Optional.<User>absent()); ResetPasswordResult result = handler.execute(action, context); assertThat(result.getResultCode(), is(ResetPasswordResultCode.INVALID_EMAIL_ADDRESS)); }