use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JakartaValidationModuleTest method testNullableCheckOnMethod.
private void testNullableCheckOnMethod(String fieldName, Boolean expectedResult) throws Exception {
ArgumentCaptor<ConfigFunction<MethodScope, Boolean>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.methodConfigPart).withNullableCheck(captor.capture());
TestType testType = new TestType(TestClassForNullableCheck.class);
String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
MethodScope method = testType.getMemberMethod(methodName);
Boolean result = captor.getValue().apply(method);
Assert.assertEquals(expectedResult, result);
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JakartaValidationModuleTest method testNullableCheckOnField.
private void testNullableCheckOnField(String fieldName, Boolean expectedResult) throws Exception {
ArgumentCaptor<ConfigFunction<FieldScope, Boolean>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withNullableCheck(captor.capture());
TestType testType = new TestType(TestClassForNullableCheck.class);
FieldScope field = testType.getMemberField(fieldName);
Boolean result = captor.getValue().apply(field);
Assert.assertEquals(expectedResult, result);
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JakartaValidationModuleTest method testStringLengthResolvers.
private void testStringLengthResolvers(String fieldName, Integer expectedMinLength, Integer expectedMaxLength) throws Exception {
TestType testType = new TestType(TestClassForStringProperties.class);
FieldScope field = testType.getMemberField(fieldName);
ArgumentCaptor<ConfigFunction<FieldScope, Integer>> minLengthCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withStringMinLengthResolver(minLengthCaptor.capture());
Integer minLength = minLengthCaptor.getValue().apply(field);
Assert.assertEquals(expectedMinLength, minLength);
ArgumentCaptor<ConfigFunction<FieldScope, Integer>> maxLengthCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withStringMaxLengthResolver(maxLengthCaptor.capture());
Integer maxLength = maxLengthCaptor.getValue().apply(field);
Assert.assertEquals(expectedMaxLength, maxLength);
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JavaxValidationModuleTest method testValidationGroupSetting.
@Test
@Parameters
@TestCaseName("{method}({0}, {1}, {2}) [{index}]")
public void testValidationGroupSetting(String testCase, String fieldName, Boolean expectedResult, Class<?>[] validationGroups) {
JavaxValidationModule module = new JavaxValidationModule();
if (validationGroups != null) {
module.forValidationGroups(validationGroups);
}
module.applyToConfigBuilder(this.configBuilder);
ArgumentCaptor<ConfigFunction<FieldScope, Boolean>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withNullableCheck(captor.capture());
TestType testType = new TestType(TestClassForValidationGroups.class);
FieldScope field = testType.getMemberField(fieldName);
Boolean result = captor.getValue().apply(field);
Assert.assertEquals(expectedResult, result);
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JavaxValidationModuleTest method testArrayItemCountResolvers.
private void testArrayItemCountResolvers(String fieldName, Integer expectedMinItems, Integer expectedMaxItems) throws Exception {
TestType testType = new TestType(TestClassForArrayItemCount.class);
FieldScope field = testType.getMemberField(fieldName);
ArgumentCaptor<ConfigFunction<FieldScope, Integer>> minItemCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withArrayMinItemsResolver(minItemCaptor.capture());
Integer minItemCount = minItemCaptor.getValue().apply(field);
Assert.assertEquals(expectedMinItems, minItemCount);
ArgumentCaptor<ConfigFunction<FieldScope, Integer>> maxItemCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withArrayMaxItemsResolver(maxItemCaptor.capture());
Integer maxItemCount = maxItemCaptor.getValue().apply(field);
Assert.assertEquals(expectedMaxItems, maxItemCount);
}
Aggregations