use of jakarta.validation.ParameterNameProvider in project today-infrastructure by TAKETODAY.
the class LocalValidatorFactoryBean method configureParameterNameProvider.
private void configureParameterNameProvider(ParameterNameDiscoverer discoverer, Configuration<?> configuration) {
final ParameterNameProvider defaultProvider = configuration.getDefaultParameterNameProvider();
configuration.parameterNameProvider(new ParameterNameProvider() {
@Override
public List<String> getParameterNames(Constructor<?> constructor) {
String[] paramNames = discoverer.getParameterNames(constructor);
return (paramNames != null ? Arrays.asList(paramNames) : defaultProvider.getParameterNames(constructor));
}
@Override
public List<String> getParameterNames(Method method) {
String[] paramNames = discoverer.getParameterNames(method);
return (paramNames != null ? Arrays.asList(paramNames) : defaultProvider.getParameterNames(method));
}
});
}
use of jakarta.validation.ParameterNameProvider in project hibernate-validator by hibernate.
the class ParameterlessMethodValidationTest method testEmptyParameters.
@Test
@TestForIssue(jiraKey = "HV-966")
public void testEmptyParameters() throws NoSuchMethodException {
HibernateValidatorConfiguration config = Validation.byProvider(HibernateValidator.class).configure();
ParameterNameProvider providerMock = new ParameterNameProvider() {
@Override
public List<String> getParameterNames(Constructor<?> constructor) {
throw new IllegalStateException("this method shouldn't be invoked");
}
@Override
public List<String> getParameterNames(Method method) {
if (method.getParameters().length == 0) {
throw new IllegalStateException("getParameterNames() shouldn't be invoked for parameterless method" + method.getName());
}
return Arrays.asList(new String[method.getParameterCount()]);
}
};
Validator validator = config.parameterNameProvider(providerMock).buildValidatorFactory().getValidator();
Bar bar = new Bar();
assertNoViolations(validator.forExecutables().validateParameters(bar, bar.getClass().getMethod("getString"), new Object[] {}));
}
use of jakarta.validation.ParameterNameProvider in project spring-framework by spring-projects.
the class LocalValidatorFactoryBean method configureParameterNameProvider.
private void configureParameterNameProvider(ParameterNameDiscoverer discoverer, Configuration<?> configuration) {
final ParameterNameProvider defaultProvider = configuration.getDefaultParameterNameProvider();
configuration.parameterNameProvider(new ParameterNameProvider() {
@Override
public List<String> getParameterNames(Constructor<?> constructor) {
String[] paramNames = discoverer.getParameterNames(constructor);
return (paramNames != null ? Arrays.asList(paramNames) : defaultProvider.getParameterNames(constructor));
}
@Override
public List<String> getParameterNames(Method method) {
String[] paramNames = discoverer.getParameterNames(method);
return (paramNames != null ? Arrays.asList(paramNames) : defaultProvider.getParameterNames(method));
}
});
}
use of jakarta.validation.ParameterNameProvider in project hibernate-validator by hibernate.
the class ValidatorFactoryBean method createParameterNameProvider.
private ParameterNameProvider createParameterNameProvider(Configuration<?> config) {
BootstrapConfiguration bootstrapConfiguration = config.getBootstrapConfiguration();
String parameterNameProviderFqcn = bootstrapConfiguration.getParameterNameProviderClassName();
if (parameterNameProviderFqcn == null) {
return config.getDefaultParameterNameProvider();
}
@SuppressWarnings("unchecked") Class<? extends ParameterNameProvider> parameterNameProviderClass = (Class<? extends ParameterNameProvider>) run(LoadClass.action(parameterNameProviderFqcn, null));
return createInstance(parameterNameProviderClass);
}
use of jakarta.validation.ParameterNameProvider in project beanvalidation-tck by eclipse-ee4j.
the class ManagedObjectsTest method testParameterNameProviderIsSubjectToDependencyInjection.
@Test
@SpecAssertion(section = Sections.INTEGRATION_GENERAL_OBJECTSLIFECYCLE, id = "d")
@SpecAssertion(section = Sections.INTEGRATION_DEPENDENCYINJECTION_CUSTOMCONFIGURATION, id = "a")
@SpecAssertion(section = Sections.INTEGRATION_DEPENDENCYINJECTION, id = "a")
public void testParameterNameProviderIsSubjectToDependencyInjection() {
assertNotNull(defaultValidatorFactory);
ParameterNameProvider parameterNameProvider = defaultValidatorFactory.getParameterNameProvider();
assertEquals(parameterNameProvider.getParameterNames((Constructor<?>) null), Arrays.asList(Greeter.MESSAGE));
}
Aggregations