@Test public void defaultTest() { ParameterTypeValidator validator = new MockSingleValueParameterTypeValidator("hello"); assertEquals(RequestParameter.create("hello"), validator.isValid(null)); assertEquals(RequestParameter.create("world"), validator.isValid("world")); }
@Override public RequestParameter isValid(String value) { if (value != null) { return isValidSingleParam(value); } else if (this.hasDefault()) return RequestParameter.create(getDefault()); else throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(null); }
SingleValueParameterTypeValidator implements ParameterTypeValidator { @Override public RequestParameter isValid(String value) { if (value != null) { return isValidSingleParam(value); } else if (this.hasDefault()) return RequestParameter.create(getDefault()); else throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(null); } }
SingleValueParameterTypeValidator implements ParameterTypeValidator { @Override public RequestParameter isValid(String value) { if (value != null) { return isValidSingleParam(value); } else if (this.hasDefault()) return RequestParameter.create(getDefault()); else throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(null); } SingleValueParameterTypeValidator(T defaultValue); }
SingleValueParameterTypeValidator implements ParameterTypeValidator { @Override public RequestParameter isValid(String value) { if (value != null) { return isValidSingleParam(value); } else if (this.hasDefault()) return RequestParameter.create(getDefault()); else throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(null); } SingleValueParameterTypeValidator(T defaultValue); abstract RequestParameter isValidSingleParam(String value); @Override RequestParameter isValid(String value); @Override RequestParameter isValidCollection(List<String> value); @Override T getDefault(); }
SingleValueParameterTypeValidator implements ParameterTypeValidator { @Override public RequestParameter isValid(String value) { if (value != null) { return isValidSingleParam(value); } else if (this.hasDefault()) return RequestParameter.create(getDefault()); else throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(null); } SingleValueParameterTypeValidator(T defaultValue); abstract RequestParameter isValidSingleParam(String value); @Override RequestParameter isValid(String value); @Override RequestParameter isValidCollection(List<String> value); @Override T getDefault(); public T defaultValue; }