RESOLVED: BATCH-1175 Genricise Validator
This commit is contained in:
@@ -30,14 +30,14 @@ import org.springframework.validation.Errors;
|
||||
* @author Tomas Slanina
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class SpringValidator implements Validator, InitializingBean {
|
||||
public class SpringValidator<T> implements Validator<T>, InitializingBean {
|
||||
|
||||
private org.springframework.validation.Validator validator;
|
||||
|
||||
/**
|
||||
* @see Validator#validate(Object)
|
||||
*/
|
||||
public void validate(Object item) throws ValidationException {
|
||||
public void validate(T item) throws ValidationException {
|
||||
|
||||
if (!validator.supports(item.getClass())) {
|
||||
throw new ValidationException("Validation failed for " + item + ": " + item.getClass().getName()
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ValidatingItemProcessor<T> implements ItemProcessor<T, T> {
|
||||
|
||||
private Validator validator;
|
||||
private Validator<? super T> validator;
|
||||
|
||||
public ValidatingItemProcessor(Validator validator){
|
||||
public ValidatingItemProcessor(Validator<? super T> validator){
|
||||
Assert.notNull(validator, "Validator must not be null.");
|
||||
this.validator = validator;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class ValidatingItemProcessor<T> implements ItemProcessor<T, T> {
|
||||
*
|
||||
* @param validator
|
||||
*/
|
||||
public void setValidator(Validator validator) {
|
||||
public void setValidator(Validator<? super T> validator) {
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ package org.springframework.batch.item.validator;
|
||||
* @author tomas.slanina
|
||||
*
|
||||
*/
|
||||
public interface Validator {
|
||||
public interface Validator<T> {
|
||||
/**
|
||||
* Method used to validate if the value is valid.
|
||||
*
|
||||
* @param value object to be validated
|
||||
* @throws ValidationException if value is not valid.
|
||||
*/
|
||||
void validate(Object value) throws ValidationException;
|
||||
void validate(T value) throws ValidationException;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
package org.springframework.batch.item.validator;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link ValidatingItemProcessor}.
|
||||
*/
|
||||
public class ValidatingItemProcessorTests {
|
||||
|
||||
private Validator validator = createMock(Validator.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
private Validator<String> validator = createMock(Validator.class);
|
||||
|
||||
private ValidatingItemProcessor<String> tested = new ValidatingItemProcessor<String>(validator);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user