|
|
|
using the provided code, sometimes I'm getting "arg0" instead of the right name in the output after a few runs.
{code} import org.hibernate.validator.parameternameprovider.ParanamerParameterNameProvider; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import javax.validation.constraints.NotNull; import java.lang.reflect.Method; import java.util.Set;
interface Service { void sayHello(@NotNull String world); } class ServiceImpl implements Service { @Override public void sayHello(String world) {} }
public class Test { public static void main(String[] args) throws NoSuchMethodException { ValidatorFactory factory = Validation.byDefaultProvider() .configure() .parameterNameProvider(new ParanamerParameterNameProvider()) .buildValidatorFactory(); Validator validator = factory.getValidator(); Service service = new ServiceImpl(); Method sayHello = Service.class.getMethod("sayHello", String.class); Set<ConstraintViolation<Service>> violations = validator.forExecutables().validateParameters(service, sayHello, new Object[]{null}); System.out.println("violations = " + violations.iterator().next().getPropertyPath()); } } {code} {code} <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>5.1.0.Final</version> </dependency>
<dependency> <groupId>org.glassfish.web</groupId> <artifactId>javax.el</artifactId> <version>2.2.6</version> </dependency>
<dependency> <groupId>com.thoughtworks.paranamer</groupId> <artifactId>paranamer</artifactId> <version>2.5.5</version> </dependency> </dependencies> {code} I'm attaching another example but with custom paranamer.
Running with maven I'm not getting the same result:
{noformat} PASS ==== Running org.test.TestTest May 06, 2014 5:11:27 PM org.hibernate.validator.internal.util.Version <clinit> INFO: HV000001: Hibernate Validator 5.1.0.Final Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.281 sec
FAIL ==== Running org.test.TestTest May 06, 2014 5:11:44 PM org.hibernate.validator.internal.util.Version <clinit> INFO: HV000001: Hibernate Validator 5.1.0.Final Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.292 sec <<< FAILURE! test(org.test.TestTest) Time elapsed: 0.254 sec <<< FAILURE! .... Results :
Failed tests: test(org.test.TestTest): expected:<sayHello.[foo]> but was:<sayHello.[xxx0]>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 {noformat}
|
|
|
|