@Test public void shouldGetPageWithEmailError() throws Exception { // when MvcResult mvcResult = mockMvc .perform( post("/register") .secure(true) .session(session) .contentType(MediaType.APPLICATION_FORM_URLENCODED) .param("name", expectedUser.getName()) .param("email", "incorrect_email") .param( (csrfToken != null ? csrfToken.getParameterName() : "_csrf"), (csrfToken != null ? csrfToken.getToken() : ""))) // then .andExpect(status().isOk()) .andExpect(content().contentType("text/html;charset=UTF-8")) .andReturn(); RegistrationPage registrationPage = new RegistrationPage(mvcResult.getResponse().getContentAsString()); registrationPage.hasErrors("user", "Please provide a valid email"); registrationPage.hasRegistrationFields(expectedUser.getName(), "incorrect_email"); }
@Test public void shouldGetPageWithEmailAlreadyTakenError() throws Exception { // given userDAO.save( new User("already_exists_id", "test name", "*****@*****.**", "Password123")); // when MvcResult mvcResult = mockMvc .perform( post("/register") .secure(true) .session(session) .contentType(MediaType.APPLICATION_FORM_URLENCODED) .param("name", expectedUser.getName()) .param("email", "*****@*****.**") .param( (csrfToken != null ? csrfToken.getParameterName() : "_csrf"), (csrfToken != null ? csrfToken.getToken() : ""))) // then .andExpect(status().isOk()) .andExpect(content().contentType("text/html;charset=UTF-8")) .andReturn(); RegistrationPage registrationPage = new RegistrationPage(mvcResult.getResponse().getContentAsString()); registrationPage.hasErrors("user", "That email address has already been taken"); registrationPage.hasRegistrationFields(expectedUser.getName(), "*****@*****.**"); }