@Test public void shouldReturnTwoFieldErrors() throws Exception { givenThatFieldErrorsArePresent(); ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult); assertThat(contactResult.getErrors()).hasSize(2); }
@Test public void shouldHaveErrorsWhenBindingResultHasFieldErrors() throws Exception { givenThatFieldErrorsArePresent(); ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult); assertThat(contactResult.isHasErrors()).isTrue(); }
@Test public void shouldHaveNoErrorsWhenBindingResultHasNoFieldErrors() throws Exception { given(bindingResult.hasFieldErrors()).willReturn(false); ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult); assertThat(contactResult.isHasErrors()).isFalse(); }
@Test public void shouldReturnFailureResult() throws Exception { givenThatFieldErrorsArePresent(); ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult); assertThat(contactResult.isSuccess()).isFalse(); }
@Test public void shouldReturnSuccessfulResult() throws Exception { given(bindingResult.hasFieldErrors()).willReturn(false); ContactResult contactResult = contactService.processContactForm(contactForm(), bindingResult); assertThat(contactResult.isSuccess()).isTrue(); }
@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."); }