@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(DecimalMin.class)).thenReturn(annotationMin); when(fieldVar.annotate(DecimalMax.class)).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(DecimalMin.class); verify(annotationMin, times(isApplicable ? 1 : 0)).param("value", minValue); verify(fieldVar, times(isApplicable ? 1 : 0)).annotate(DecimalMax.class); verify(annotationMax, times(isApplicable ? 1 : 0)).param("value", maxValue); }
@Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) { if (node.has("minimum")) { JAnnotationUse annotation = field.annotate(DecimalMin.class); annotation.param("value", node.get("minimum").asText()); } if (node.has("maximum")) { JAnnotationUse annotation = field.annotate(DecimalMax.class); annotation.param("value", node.get("maximum").asText()); } } return field; }
MinimumMaximumRule implements Rule<JFieldVar, JFieldVar> { @Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) { if (node.has("minimum")) { JAnnotationUse annotation = field.annotate(DecimalMin.class); annotation.param("value", node.get("minimum").asText()); } if (node.has("maximum")) { JAnnotationUse annotation = field.annotate(DecimalMax.class); annotation.param("value", node.get("maximum").asText()); } } return field; } }
MinimumMaximumRule implements Rule<JFieldVar, JFieldVar> { @Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) { if (node.has("minimum")) { JAnnotationUse annotation = field.annotate(DecimalMin.class); annotation.param("value", node.get("minimum").asText()); } if (node.has("maximum")) { JAnnotationUse annotation = field.annotate(DecimalMax.class); annotation.param("value", node.get("maximum").asText()); } } return field; } protected  MinimumMaximumRule(RuleFactory ruleFactory); }
MinimumMaximumRule implements Rule<JFieldVar, JFieldVar> { @Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) { if (node.has("minimum")) { JAnnotationUse annotation = field.annotate(DecimalMin.class); annotation.param("value", node.get("minimum").asText()); } if (node.has("maximum")) { JAnnotationUse annotation = field.annotate(DecimalMax.class); annotation.param("value", node.get("maximum").asText()); } } return field; } protected  MinimumMaximumRule(RuleFactory ruleFactory); @Override JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema); }
MinimumMaximumRule implements Rule<JFieldVar, JFieldVar> { @Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) { if (node.has("minimum")) { JAnnotationUse annotation = field.annotate(DecimalMin.class); annotation.param("value", node.get("minimum").asText()); } if (node.has("maximum")) { JAnnotationUse annotation = field.annotate(DecimalMax.class); annotation.param("value", node.get("maximum").asText()); } } return field; } protected  MinimumMaximumRule(RuleFactory ruleFactory); @Override JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema);  }