Examples of BindingResult


Examples of org.springframework.validation.BindingResult

 
  @Test
  public void create_InvalidPasswordLength() {
    final Model model = createNiceMock(Model.class);
    final NewUser newUser = new NewUser();
    final BindingResult errors = createNiceMock(BindingResult.class);
    final String username = "usename";
    final String password = "pas"; //invalid length password
    final String confirmPassword = password;
    List<ObjectError> errorList = new ArrayList<ObjectError>();
       
    newUser.setUsername(username);
    newUser.setPassword(password);
    newUser.setConfirmPassword(confirmPassword);
   
    errorList.add(new ObjectError("password.invalid.length", "Password must be atleast 4 characters long"));
   
    expect(errors.hasErrors()).andReturn(true).anyTimes();   
    expect(errors.getAllErrors()).andReturn(errorList).anyTimes();
    replay(errors);
    replay(model);
    String result = new String(newAccountController.create(newUser, errors, model, request));
    errorList = errors.getAllErrors();

    assertThat(errorList.size(), CoreMatchers.equalTo(1));
    assertThat(errorList.get(0).getDefaultMessage(), CoreMatchers.equalTo("Password must be atleast 4 characters long"));
    assertThat(result, CoreMatchers.equalTo(ViewNames.NEW_ACCOUNT));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.