@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 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 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 shouldNotSendEmailOnException() {
   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));
   handler.execute(action, context);
   verify(mailer, never()).sendEmail(any(String.class), any(String.class));
 }
 @Test
 public void shouldSendEmailOnSuccess() {
   when(mpm.getUserByUserIdOrEmail(any(String.class))).thenReturn(Optional.of(user));
   when(user.getEmail()).thenReturn(EMAIL_ADDRESS);
   handler.execute(action, context);
   ArgumentCaptor<String> emailCaptor = ArgumentCaptor.forClass(String.class);
   verify(mailer, times(1)).sendEmail(emailCaptor.capture(), any(String.class));
   assertThat(emailCaptor.getValue(), is(EMAIL_ADDRESS));
 }
 @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));
 }