### Question:
RequiredArrayRule implements Rule<JDefinedClass, JDefinedClass> { @Override public JDefinedClass apply(String nodeName, JsonNode node, JsonNode parent, JDefinedClass jclass, Schema schema) { List<String> requiredFieldMethods = new ArrayList<>(); JsonNode properties = schema.getContent().get("properties"); for (Iterator<JsonNode> iterator = node.elements(); iterator.hasNext(); ) { String requiredArrayItem = iterator.next().asText(); if (requiredArrayItem.isEmpty()) { continue; } JsonNode propertyNode = null; if (properties != null) { propertyNode = properties.findValue(requiredArrayItem); } String fieldName = ruleFactory.getNameHelper().getPropertyName(requiredArrayItem, propertyNode); JFieldVar field = jclass.fields().get(fieldName); if (field == null) { continue; } addJavaDoc(field); if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) { addNotNullAnnotation(field); } if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations()) { addNonnullAnnotation(field); } requiredFieldMethods.add(getGetterName(fieldName, field.type(), node)); requiredFieldMethods.add(getSetterName(fieldName, node)); } updateGetterSetterJavaDoc(jclass, requiredFieldMethods); return jclass; } protected  RequiredArrayRule(RuleFactory ruleFactory); @Override JDefinedClass apply(String nodeName, JsonNode node, JsonNode parent, JDefinedClass jclass, Schema schema); static final String REQUIRED_COMMENT_TEXT; }### Answer:
@Test public void shouldUpdateJavaDoc() throws JClassAlreadyExistsException { JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME); jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "fooBar"); jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "foo"); ObjectMapper mapper = new ObjectMapper(); ArrayNode requiredNode = mapper.createArrayNode().add("fooBar"); rule.apply("Class", requiredNode, null, jclass, new Schema(null, requiredNode, null)); JDocComment fooBarJavaDoc = jclass.fields().get("fooBar").javadoc(); JDocComment fooJavaDoc = jclass.fields().get("foo").javadoc(); assertThat(fooBarJavaDoc.size(), is(1)); assertThat((String) fooBarJavaDoc.get(0), is("\n(Required)")); assertThat(fooJavaDoc.size(), is(0)); }
@Test public void shouldUpdateAnnotations() throws JClassAlreadyExistsException { setupRuleFactoryToIncludeJsr303(); JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME); jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "fooBar"); jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "foo"); ObjectMapper mapper = new ObjectMapper(); ArrayNode requiredNode = mapper.createArrayNode().add("foo_bar"); rule.apply("Class", requiredNode, null, jclass, new Schema(null, requiredNode, null)); Collection<JAnnotationUse> fooBarAnnotations = jclass.fields().get("fooBar").annotations(); Collection<JAnnotationUse> fooAnnotations = jclass.fields().get("foo").annotations(); assertThat(fooBarAnnotations.size(), is(1)); assertThat(fooBarAnnotations.iterator().next().getAnnotationClass().name(), is(NotNull.class.getSimpleName())); assertThat(fooAnnotations.size(), is(0)); }