use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class PatternRuleTest method testRegex.
@Test
public void testRegex() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
final String patternValue = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$";
when(node.asText()).thenReturn(patternValue);
when(fieldVar.annotate(patternClass)).thenReturn(annotation);
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(patternClass);
verify(annotation, times(isApplicable ? 1 : 0)).param("regexp", patternValue);
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinLengthMaxLengthRuleTest method testMinLength.
@Test
public void testMinLength() {
when(config.isIncludeJsr303Annotations()).thenReturn(true);
final int minValue = new Random().nextInt();
when(subNode.asInt()).thenReturn(minValue);
when(node.get("minLength")).thenReturn(subNode);
when(fieldVar.annotate(sizeClass)).thenReturn(annotation);
when(node.has("minLength")).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, never()).param(eq("max"), anyString());
}
use of com.sun.codemodel.JFieldVar in project jsonschema2pojo by joelittlejohn.
the class MinLengthMaxLengthRuleTest 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("maxLength")).thenReturn(subNode);
when(fieldVar.annotate(sizeClass)).thenReturn(annotation);
when(node.has("maxLength")).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 MinLengthMaxLengthRuleTest 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("minLength")).thenReturn(subNode);
when(node.get("maxLength")).thenReturn(maxSubNode);
when(fieldVar.annotate(sizeClass)).thenReturn(annotation);
when(node.has("minLength")).thenReturn(true);
when(node.has("maxLength")).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 EnumRule method addQuickLookupMap.
protected JFieldVar addQuickLookupMap(EnumDefinition enumDefinition, JDefinedClass _enum) {
JType backingType = enumDefinition.getBackingType();
JClass lookupType = _enum.owner().ref(Map.class).narrow(backingType.boxify(), _enum);
JFieldVar lookupMap = _enum.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, lookupType, "CONSTANTS");
JClass lookupImplType = _enum.owner().ref(HashMap.class).narrow(backingType.boxify(), _enum);
lookupMap.init(JExpr._new(lookupImplType));
JForEach forEach = _enum.init().forEach(_enum, "c", JExpr.invoke("values"));
JInvocation put = forEach.body().invoke(lookupMap, "put");
put.arg(forEach.var().ref("value"));
put.arg(forEach.var());
return lookupMap;
}
Aggregations