use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class JavaxValidationModuleTest 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.MethodScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForMethod_withCustomPropertyDefinition.
@Test
public void testCreateStandardDefinitionReferenceForMethod_withCustomPropertyDefinition() {
Mockito.doReturn(new CustomPropertyDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property"))).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(MethodScope.class), Mockito.any(), Mockito.any());
MethodScope targetMethod = this.getTestClassMethod("isBooleanField");
JsonNode result = this.contextImpl.createStandardDefinitionReference(targetMethod, null);
Assert.assertEquals("{\"$comment\":\"custom property\",\"title\":\"Method Title\",\"description\":\"Type Description\"}", result.toString());
}
use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForMethod_withCustomPropertyAndTypeDefinitions.
@Test
public void testCreateStandardDefinitionReferenceForMethod_withCustomPropertyAndTypeDefinitions() {
Mockito.doReturn(new CustomDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom type"), true)).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(ResolvedType.class), Mockito.any(), Mockito.any());
Mockito.doReturn(new CustomPropertyDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property"))).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(MethodScope.class), Mockito.any(), Mockito.any());
MethodScope targetMethod = this.getTestClassMethod("isBooleanField");
JsonNode result = this.contextImpl.createStandardDefinitionReference(targetMethod, null);
Assert.assertEquals("{\"$comment\":\"custom property\",\"title\":\"Method Title\",\"description\":\"Type Description\"}", result.toString());
}
use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class SchemaGeneratorConfigImplTest method testIsNullableMethod.
@Test
@Parameters(method = "parametersForTestIsNullable")
public void testIsNullableMethod(Boolean configResult, boolean optionEnabled, boolean expectedResult) throws Exception {
MethodScope method = this.getTestClassMethod("getField");
Mockito.when(this.methodConfigPart.isNullable(method)).thenReturn(configResult);
if (optionEnabled) {
this.enabledOptions.add(Option.NULLABLE_METHOD_RETURN_VALUES_BY_DEFAULT);
}
boolean result = this.instance.isNullable(method);
Assert.assertEquals(expectedResult, result);
}
use of com.github.victools.jsonschema.generator.MethodScope in project jsonschema-generator by victools.
the class SchemaGeneratorConfigImplTest method testIsRequiredMethod.
@Test
@Parameters({ "true", "false" })
public void testIsRequiredMethod(boolean configuredAndExpectedResult) throws Exception {
MethodScope method = this.getTestClassMethod("getField");
Mockito.when(this.methodConfigPart.isRequired(method)).thenReturn(configuredAndExpectedResult);
boolean result = this.instance.isRequired(method);
Assert.assertEquals(configuredAndExpectedResult, result);
}
Aggregations