use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JacksonModuleTest method testPropertyNameOverride.
@Test
@Parameters
public void testPropertyNameOverride(String fieldName, String expectedOverrideValue, String kebabCaseName) throws Exception {
new JacksonModule().applyToConfigBuilder(this.configBuilder);
ArgumentCaptor<ConfigFunction<FieldScope, String>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart, Mockito.times(2)).withPropertyNameOverrideResolver(captor.capture());
FieldScope field = new TestType(TestClassForPropertyNameOverride.class).getMemberField(fieldName);
List<String> overrideValues = captor.getAllValues().stream().map(nameOverride -> nameOverride.apply(field)).collect(Collectors.toList());
Assert.assertEquals(expectedOverrideValue, overrideValues.get(0));
Assert.assertEquals(kebabCaseName, overrideValues.get(1));
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JacksonModuleTest method testDescriptionForTypeResolver.
@Test
@Parameters
public void testDescriptionForTypeResolver(String fieldName, String expectedDescription) throws Exception {
new JacksonModule().applyToConfigBuilder(this.configBuilder);
FieldScope field = new TestType(TestClassForDescription.class).getMemberField(fieldName);
ArgumentCaptor<ConfigFunction<TypeScope, String>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.typesInGeneralConfigPart).withDescriptionResolver(captor.capture());
String description = captor.getValue().apply(field);
Assert.assertEquals(expectedDescription, description);
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class AdditionalPropertiesModuleTest method testResolveAdditionalProperties.
@Test
@Parameters
@SuppressWarnings("unchecked")
public void testResolveAdditionalProperties(Module moduleInstance, Type expectedAdditionalProperties, Type type, Type[] typeParameters) {
moduleInstance.applyToConfigBuilder(this.builder);
ArgumentCaptor<ConfigFunction<TypeScope, Type>> resolverCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.generalConfigPart).withAdditionalPropertiesResolver(resolverCaptor.capture());
ConfigFunction<TypeScope, Type> additionalPropertiesResolver = resolverCaptor.getValue();
TypeContext typeContext = this.getContext().getTypeContext();
TypeScope scope = typeContext.createTypeScope(typeContext.resolve(type, typeParameters));
Type result = additionalPropertiesResolver.apply(scope);
if (expectedAdditionalProperties == null || expectedAdditionalProperties == Void.class) {
Assert.assertEquals(expectedAdditionalProperties, result);
} else {
Assert.assertEquals(typeContext.resolve(expectedAdditionalProperties), result);
}
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JakartaValidationModuleTest method testStringFormatAndPatternResolvers.
private void testStringFormatAndPatternResolvers(String fieldName, String expectedFormat, String expectedPattern) throws Exception {
TestType testType = new TestType(TestClassForStringProperties.class);
FieldScope field = testType.getMemberField(fieldName);
ArgumentCaptor<ConfigFunction<FieldScope, String>> formatCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withStringFormatResolver(formatCaptor.capture());
String formatValue = formatCaptor.getValue().apply(field);
Assert.assertEquals(expectedFormat, formatValue);
ArgumentCaptor<ConfigFunction<FieldScope, String>> patternCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withStringPatternResolver(patternCaptor.capture());
String patternValue = patternCaptor.getValue().apply(field);
Assert.assertEquals(expectedPattern, patternValue);
}
use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.
the class JakartaValidationModuleTest method testValidationGroupSetting.
@Test
@Parameters
@TestCaseName("{method}({0}, {1}, {2}) [{index}]")
public void testValidationGroupSetting(String testCase, String fieldName, Boolean expectedResult, Class<?>[] validationGroups) {
JakartaValidationModule module = new JakartaValidationModule();
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);
}
Aggregations