use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinItemsMaxItemsRuleTest method testNotUsed.
@Test
public void testNotUsed() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
when(node.has("minItems")).thenReturn(false);
when(node.has("maxItems")).thenReturn(false);
when(fieldVar.type().boxify().fullName()).thenReturn(fieldClass.getTypeName());
JFieldVar result = rule.apply("node", node, null, fieldVar, null);
assertSame(fieldVar, result);
verify(fieldVar, never()).annotate(sizeClass);
verify(annotation, never()).param(anyString(), anyInt());
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinItemsMaxItemsRuleTest method testMaxAndMinLength.
@Test
public void testMaxAndMinLength() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
final int minValue = new Random().nextInt();
final int maxValue = new Random().nextInt();
JsonNode maxSubNode = Mockito.mock(JsonNode.class);
when(subNode.asInt()).thenReturn(minValue);
when(maxSubNode.asInt()).thenReturn(maxValue);
when(node.get("minItems")).thenReturn(subNode);
when(node.get("maxItems")).thenReturn(maxSubNode);
when(fieldVar.annotate(sizeClass)).thenReturn(annotation);
when(node.has("minItems")).thenReturn(true);
when(node.has("maxItems")).thenReturn(true);
when(fieldVar.type().boxify().fullName()).thenReturn(fieldClass.getTypeName());
JFieldVar result = rule.apply("node", node, null, fieldVar, null);
assertSame(fieldVar, result);
verify(fieldVar, times(isApplicable ? 1 : 0)).annotate(sizeClass);
verify(annotation, times(isApplicable ? 1 : 0)).param("min", minValue);
verify(annotation, times(isApplicable ? 1 : 0)).param("max", maxValue);
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinItemsMaxItemsRuleTest method testMaxLength.
@Test
public void testMaxLength() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
final int maxValue = new Random().nextInt();
when(subNode.asInt()).thenReturn(maxValue);
when(node.get("maxItems")).thenReturn(subNode);
when(fieldVar.annotate(sizeClass)).thenReturn(annotation);
when(node.has("maxItems")).thenReturn(true);
when(fieldVar.type().boxify().fullName()).thenReturn(fieldClass.getTypeName());
JFieldVar result = rule.apply("node", node, null, fieldVar, null);
assertSame(fieldVar, result);
verify(fieldVar, times(isApplicable ? 1 : 0)).annotate(sizeClass);
verify(annotation, times(isApplicable ? 1 : 0)).param("max", maxValue);
verify(annotation, never()).param(eq("min"), anyInt());
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinimumMaximumRuleTest method testMaximum.
@Test
public void testMaximum() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
final String maxValue = Integer.toString(new Random().nextInt());
when(subNode.asText()).thenReturn(maxValue);
when(node.get("maximum")).thenReturn(subNode);
when(fieldVar.annotate(decimalMaxClass)).thenReturn(annotationMax);
when(node.has("maximum")).thenReturn(true);
when(fieldVar.type().boxify().fullName()).thenReturn(fieldClass.getTypeName());
JFieldVar result = rule.apply("node", node, null, fieldVar, null);
assertSame(fieldVar, result);
verify(fieldVar, times(isApplicable ? 1 : 0)).annotate(decimalMaxClass);
verify(annotationMax, times(isApplicable ? 1 : 0)).param("value", maxValue);
verify(fieldVar, never()).annotate(decimalMinClass);
verify(annotationMin, never()).param(eq("value"), anyString());
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinimumMaximumRuleTest method testMaximumAndMinimum.
@Test
public void testMaximumAndMinimum() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
final String minValue = Integer.toString(new Random().nextInt());
final String maxValue = Integer.toString(new Random().nextInt());
JsonNode maxSubNode = Mockito.mock(JsonNode.class);
when(subNode.asText()).thenReturn(minValue);
when(maxSubNode.asText()).thenReturn(maxValue);
when(node.get("minimum")).thenReturn(subNode);
when(node.get("maximum")).thenReturn(maxSubNode);
when(fieldVar.annotate(decimalMinClass)).thenReturn(annotationMin);
when(fieldVar.annotate(decimalMaxClass)).thenReturn(annotationMax);
when(node.has("minimum")).thenReturn(true);
when(node.has("maximum")).thenReturn(true);
when(fieldVar.type().boxify().fullName()).thenReturn(fieldClass.getTypeName());
JFieldVar result = rule.apply("node", node, null, fieldVar, null);
assertSame(fieldVar, result);
verify(fieldVar, times(isApplicable ? 1 : 0)).annotate(decimalMinClass);
verify(annotationMin, times(isApplicable ? 1 : 0)).param("value", minValue);
verify(fieldVar, times(isApplicable ? 1 : 0)).annotate(decimalMaxClass);
verify(annotationMax, times(isApplicable ? 1 : 0)).param("value", maxValue);
}
Aggregations