AddParentsValidator extends AbstractBaseValidator { public void validate(Object comm, Errors errors) { AddParentsCommand command = (AddParentsCommand) comm; if(AddParentsCommand.ACTION_ADD_PARENTS.equals(command.getActionCmd())) { if((command.getParentOids() == null || command.getParentOids().length == 0) && command.getSelectedCount() == 0) { errors.reject("groups.errors.addparents.must_select"); } } }  boolean supports(Class clazz); void validate(Object comm, Errors errors);  }
@Test public final void testValidate() { try { AddParentsCommand cmd = new AddParentsCommand(); Errors errors = new BindException(cmd, "AddParentsCommand"); cmd.setActionCmd(AddParentsCommand.ACTION_ADD_PARENTS); testInstance.validate(cmd, errors); assertEquals("Expecting 1 errors", 1, errors.getErrorCount()); assertEquals("Expecting error[0]", true, errors.getAllErrors().toArray()[0].toString().contains("groups.errors.addparents.must_select")); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }