use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesCustomObject.
@Test
public void applyGeneratesCustomObject() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "object");
JDefinedClass mockObjectType = mock(JDefinedClass.class);
ObjectRule mockObjectRule = mock(ObjectRule.class);
when(mockObjectRule.apply("fooBar", objectNode, jpackage, null)).thenReturn(mockObjectType);
when(ruleFactory.getObjectRule()).thenReturn(mockObjectRule);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result, is((JType) mockObjectType));
}
use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class RequiredArrayRuleTest method shouldUpdateJavaDoc.
@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, jclass, new Schema(null, requiredNode, requiredNode));
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));
}
use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class RequiredArrayRuleTest method shouldUpdateAnnotations.
@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, jclass, new Schema(null, requiredNode, requiredNode));
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));
}
use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class RequiredRuleTest method applyAddsTextWhenRequired.
@Test
public void applyAddsTextWhenRequired() throws JClassAlreadyExistsException {
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
ObjectMapper mapper = new ObjectMapper();
BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(true);
JDocCommentable result = rule.apply("fooBar", descriptionNode, jclass, null);
assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
assertThat(result.javadoc().size(), is(1));
assertThat((String) result.javadoc().get(0), is("\n(Required)"));
}
use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class RequiredRuleTest method applySkipsTextWhenNotRequired.
@Test
public void applySkipsTextWhenNotRequired() throws JClassAlreadyExistsException {
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
ObjectMapper mapper = new ObjectMapper();
BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(false);
JDocCommentable result = rule.apply("fooBar", descriptionNode, jclass, null);
assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
assertThat(result.javadoc().size(), is(0));
}
Aggregations