@Test public void testValidate_invalidDate() { customerForm.setCustomerBirthYear(1997); customerForm.setCustomerBirthMonth(2); customerForm.setCustomerBirthDay(29); BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm"); customerFormValidator.validate(customerForm, result); assertThat(result.hasErrors(), is(true)); FieldError error = result.getFieldError("customerBirthYear"); assertThat(error, is(notNullValue())); assertThat(error.getCode(), is("IncorrectDate.customerBirth")); assertThat(error.getDefaultMessage(), is("Incorrect date was entered.")); }
@Test public void testValidate() { BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm"); customerFormValidator.validate(customerForm, result); assertThat(result.hasErrors(), is(false)); }
@Test public void testValidate_validLeapYear() { customerForm.setCustomerBirthYear(1996); customerForm.setCustomerBirthMonth(2); customerForm.setCustomerBirthDay(29); BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm"); customerFormValidator.validate(customerForm, result); assertThat(result.hasErrors(), is(false)); }
@Test public void testAccountCreation() { SignupForm form = populateForm(NAME, PASSWORD); Errors noErrors = new DirectFieldBindingResult(form, "form"); controller.signup(form, noErrors); // Verify that the account was created for user verify(userDetailsManager).createUser(argThat(hasProperty("username", equalTo(NAME)))); }
/** * Verify that hashed password is saved to userDetailsManager */ @Test public void testPasswordHash() { given(passwordEncoder.encode(PASSWORD)).willReturn(HASHED_PASSWORD); SignupForm form = populateForm(NAME, PASSWORD); Errors noErrors = new DirectFieldBindingResult(form, "form"); controller.signup(form, noErrors); // Verify that the hashed password was passed to the userDetailsManager verify(userDetailsManager).createUser(argThat(hasProperty("password", equalTo(HASHED_PASSWORD)))); }
@Test public void testValidationFailIsLogged() { SignupForm invalidForm = populateForm(null, null); Errors errors = new DirectFieldBindingResult(invalidForm, "form"); errors.rejectValue("name", "Invalid name"); errors.rejectValue("password", "Invalid password"); controller.signup(invalidForm, errors); assertThat(sysOut.asString(), containsString("Oh no!")); }
@Test public void testSuccessIsLogged() { SignupForm form = populateForm(NAME, PASSWORD); Errors noErrors = new DirectFieldBindingResult(form, "form"); controller.signup(form, noErrors); assertThat(sysOut.asString(), containsString("Success!")); }
private static DirectFieldBindingResult emailValidationErrors(FollowInitiativeDto followInitiativeDto) { return new DirectFieldBindingResult(followInitiativeDto, "email"); }
@Test public void testValidate_invalidPasswordConfirm() { customerForm.setCustomerPassConfirm("invalidPassword"); BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm"); customerFormValidator.validate(customerForm, result); assertThat(result.hasErrors(), is(true)); assertCustomerPassError(result.getFieldError("customerPass")); }
@Test public void testValidate_nullPassword() { customerForm.setCustomerPass(null); BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm"); customerFormValidator.validate(customerForm, result); assertThat(result.hasErrors(), is(true)); assertCustomerPassError(result.getFieldError("customerPass")); }
@Test public void testValidate_nullPasswordConfirm() { customerForm.setCustomerPassConfirm(null); BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm"); customerFormValidator.validate(customerForm, result); assertThat(result.hasErrors(), is(true)); assertCustomerPassError(result.getFieldError("customerPass")); }
@Test public void testSuccessForward() { SignupForm form = populateForm(NAME, PASSWORD); Errors noErrors = new DirectFieldBindingResult(form, "form"); String response = controller.signup(form, noErrors); assertEquals(SignupController.VIEW_SUCCESS, response); }