### Question:
PatternRule implements Rule<JFieldVar, JFieldVar> { @Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && isApplicableType(field)) { JAnnotationUse annotation = field.annotate(Pattern.class); annotation.param("regexp", node.asText()); } return field; } PatternRule(RuleFactory ruleFactory); @Override JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema);  }### Answer:
@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(Pattern.class)).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(Pattern.class); verify(annotation, times(isApplicable ? 1 : 0)).param("regexp", patternValue); }
@Test public void jsrDisable() { when(config.isIncludeJsr303Annotations()).thenReturn(false); JFieldVar result = rule.apply("node", node, null, fieldVar, null); assertSame(fieldVar, result); verify(fieldVar, never()).annotate(Pattern.class); verify(annotation, never()).param(anyString(), anyString()); }