BaseCommandValidator implements Validator { @Override public void validate(final Object target, final Errors errors) { final BaseCommand command = (BaseCommand) target; if (Revision.UNDEFINED.equals(command.getRevision())) { command.setRevision(Revision.HEAD); errors.rejectValue("revision", "browse.error.illegal-revision"); } }  @Override boolean supports(final Class clazz); @Override void validate(final Object target, final Errors errors);  }
@Test public void testValidate() { BaseCommandValidator validator = new BaseCommandValidator(); BaseCommand command = new BaseCommand(); BindException exception = new BindException(command, "test"); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setPath("/test/Test.java"); command.setRevision(Revision.parse("12")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setPath("/test/Test.java"); command.setRevision(Revision.parse("12")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRevision(Revision.parse("HEAD")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRevision(Revision.parse("{2007-01-01}")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRevision(Revision.parse("head ")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRevision(Revision.parse("HEad")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRevision(Revision.parse(" 123 ")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRevision(Revision.parse("{2007-01-01}")); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRevision(Revision.parse("2007-01-01")); validator.validate(command, exception); assertEquals(1, exception.getAllErrors().size()); assertEquals("browse.error.illegal-revision", exception.getFieldError("revision").getCode()); exception = new BindException(command, "test2"); command.setRevision(Revision.create(1)); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); exception = new BindException(command, "test2"); command.setSortMode(null); command.setSortType(null); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); exception = new BindException(command, "test2"); command.setSortMode(DirEntrySorter.SortMode.ASC); command.setSortType(DirEntryComparator.SortType.SIZE); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); }