use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class FormatRuleArraysTest method useArraysWithCustomTypeMapping.
@Test
public void useArraysWithCustomTypeMapping() {
JType result = rule.apply("fooBar", TextNode.valueOf("test"), null, new JCodeModel().ref(Object.class), null);
assertTrue(result.isArray());
JType expectedJType = new JCodeModel().ref(expectedType);
assertThat(result.fullName(), equalTo(expectedJType.fullName()));
}
use of com.sun.codemodel.JCodeModel 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, 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));
}
use of com.sun.codemodel.JCodeModel 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, 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(notNullClass.getSimpleName()));
assertThat(fooAnnotations.size(), is(0));
}
use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class TypeUtilTest method testResolveTypeCanHandleWildcard.
@Test
public void testResolveTypeCanHandleWildcard() {
final JCodeModel codeModel = new JCodeModel();
final JClass _class = TypeUtil.resolveType(codeModel.rootPackage(), "java.util.List<?>");
assertThat(_class.erasure(), equalTo(codeModel.ref(List.class)));
assertThat(_class.typeParams(), emptyArray());
assertThat(_class.isParameterized(), is(Boolean.TRUE));
assertThat(_class.getTypeParameters(), hasSize(1));
assertThat(_class.getTypeParameters().get(0)._extends(), is(equalTo(codeModel.ref(Object.class))));
}
use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class TypeUtilTest method testResolveTypeCanHandleExtendsWildcard.
@Test
public void testResolveTypeCanHandleExtendsWildcard() {
final JCodeModel codeModel = new JCodeModel();
final JClass _class = TypeUtil.resolveType(codeModel.rootPackage(), "java.util.List<? extends java.lang.Number>");
assertThat(_class.erasure(), equalTo(codeModel.ref(List.class)));
assertThat(_class.typeParams(), emptyArray());
assertThat(_class.isParameterized(), is(Boolean.TRUE));
assertThat(_class.getTypeParameters(), hasSize(1));
assertThat(_class.getTypeParameters().get(0)._extends(), is(equalTo(codeModel.ref(Number.class))));
}
Aggregations