コード例 #1
0
  @Test
  public void shouldReturnTwoFieldErrors() throws Exception {
    givenThatFieldErrorsArePresent();

    ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult);

    assertThat(contactResult.getErrors()).hasSize(2);
  }
コード例 #2
0
  @Test
  public void shouldReturnAppropriateMessagesForValidationErrors() throws Exception {
    givenThatFieldErrorsArePresent();

    ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult);

    assertThat(contactResult.getErrors())
        .contains("In your face.", "You gone did something wrong.");
  }
コード例 #3
0
  @Test
  public void shouldHandleMailServerExceptionAndReturnUnsuccessfulWithErrorMessage()
      throws Exception {
    doThrow(new RuntimeException()).when(contactMailService).sendEmail(any(ContactForm.class));

    ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult);

    assertThat(contactResult.isHasErrors()).isTrue();
    assertThat(contactResult.isSuccess()).isFalse();
    assertThat(contactResult.getErrors())
        .containsOnly("Uh oh! Something went wrong, please try again.");
  }