本文整理汇总了Java中javax.validation.executable.ExecutableValidator.validateConstructorParameters方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableValidator.validateConstructorParameters方法的具体用法?Java ExecutableValidator.validateConstructorParameters怎么用?Java ExecutableValidator.validateConstructorParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.executable.ExecutableValidator
的用法示例。
在下文中一共展示了ExecutableValidator.validateConstructorParameters方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructorViolationsWhenNullParameters
import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
@Test
public void constructorViolationsWhenNullParameters() throws NoSuchMethodException, SecurityException {
final MyParameter parameter = new MyParameter();
ExecutableValidator methodValidator = validator.forExecutables();
Constructor<MyBean2> constructor = MyBean2.class
.getConstructor(parameter.getClass());
Set<ConstraintViolation<MyBean2>> constraints = methodValidator
.validateConstructorParameters(constructor, new Object[] {parameter});
ConstraintViolation<MyBean2> violation = constraints.iterator().next();
assertThat(constraints.size(), equalTo(1));
assertThat(violation.getMessageTemplate(), equalTo("{javax.validation.constraints.NotNull.message}"));
assertThat(violation.getPropertyPath().toString(), equalTo("MyBean2.arg0.value"));
}
示例2: constructorViolationsWhenNotNullParameters
import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
@Test
public void constructorViolationsWhenNotNullParameters() throws NoSuchMethodException, SecurityException {
final MyParameter parameter = new MyParameter();
parameter.setValue("foo");
ExecutableValidator methodValidator = validator.forExecutables();
Constructor<MyBean2> constructor = MyBean2.class
.getConstructor(parameter.getClass());
Set<ConstraintViolation<MyBean2>> constraints = methodValidator
.validateConstructorParameters(constructor, new Object[] {parameter});
assertThat(constraints.isEmpty(), equalTo(true));
}
示例3: testConstructorParameters
import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
@Test
public void testConstructorParameters() throws NoSuchMethodException {
ExecutableValidator executableValidator = validator.forExecutables();
Constructor<RentalStation> constructor = RentalStation.class.getConstructor(String.class, String.class);
Set<ConstraintViolation<RentalStation>> violations = executableValidator.validateConstructorParameters
(constructor, new Object[] {"Hertz", ""});
assertThat(violations.size()).isEqualTo(0);
violations = executableValidator.validateConstructorParameters
(constructor, new Object[] {null, ""});
assertThat(violations.size()).isEqualTo(1);
violations = executableValidator.validateConstructorParameters
(constructor, new Object[] {null, null});
assertThat(violations.size()).isEqualTo(2);
}
示例4: validateParameters
import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
@Override
public void validateParameters(final Constructor constructor, final Object[] parameters) {
final ExecutableValidator executableValidator = validatorFactory.getValidator().forExecutables();
final Set<ConstraintViolation<?>> violations = executableValidator.validateConstructorParameters(constructor, parameters);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}