ContactController extends AbstractController { @RequestMapping(value = "sendContactEmail.html", method = RequestMethod.POST) public String sendEmail(@Valid ContactDto contactDto,BindingResult result, Model model){ fieldValidatorRequestMoreInformation.validate(contactDto, result); if (result.hasErrors()) { return "views/contact"; } contactService.sendEmail(contactDto); return "redirect:/contactSuccess.html"; } @Autowired  ContactController(ContactService contactService, FieldValidatorRequestMoreInformation fieldValidatorRequestMoreInformation); @RequestMapping(value = "contact.html", method = RequestMethod.GET) String contactpage(Model model); @RequestMapping(value = "sendContactEmail.html", method = RequestMethod.POST) String sendEmail(@Valid ContactDto contactDto,BindingResult result, Model model); @RequestMapping(value = "contactSuccess.html") String contactSuccessPage(Model model);  }
@Test public void testSendContactEmailRedirect() throws Exception { ContactDto contactDto = mock(ContactDto.class); doNothing().when(contactService).sendEmail(contactDto); mockMvc.perform(post("/sendContactEmail.html") .param("fistName", "test") .param("lastName", "test") .param("email", "test@test.com") .param("emailConfirmation", "test@test.com") .param("messageCode", "1")) .andExpect(status().is3xxRedirection()) .andExpect(view().name("redirect:/contactSuccess.html")); }