@Test public void shouldReturnTwoFieldErrors() throws Exception { givenThatFieldErrorsArePresent(); ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult); assertThat(contactResult.getErrors()).hasSize(2); }
@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."); }
@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."); }