use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class EnumRuleTest method applyGeneratesUniqueEnumNamesForMultipleEnumNodesWithSameName.
@Test
public void applyGeneratesUniqueEnumNamesForMultipleEnumNodesWithSameName() {
Answer<String> firstArgAnswer = new FirstArgAnswer<String>();
when(nameHelper.getFieldName(anyString(), any(JsonNode.class))).thenAnswer(firstArgAnswer);
when(nameHelper.replaceIllegalCharacters(anyString())).thenAnswer(firstArgAnswer);
when(nameHelper.normalizeName(anyString())).thenAnswer(firstArgAnswer);
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectMapper objectMapper = new ObjectMapper();
ArrayNode arrayNode = objectMapper.createArrayNode();
arrayNode.add("open");
arrayNode.add("closed");
ObjectNode enumNode = objectMapper.createObjectNode();
enumNode.put("type", "string");
enumNode.set("enum", arrayNode);
// We're always a string for the purposes of this test
when(typeRule.apply("status", enumNode, jpackage, schema)).thenReturn(jpackage.owner()._ref(String.class));
JType result1 = rule.apply("status", enumNode, jpackage, schema);
JType result2 = rule.apply("status", enumNode, jpackage, schema);
assertThat(result1.fullName(), is("org.jsonschema2pojo.rules.Status"));
assertThat(result2.fullName(), is("org.jsonschema2pojo.rules.Status_"));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesDate.
@Test
public void applyGeneratesDate() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "string");
TextNode formatNode = TextNode.valueOf("date-time");
objectNode.set("format", formatNode);
JType mockDateType = mock(JType.class);
FormatRule mockFormatRule = mock(FormatRule.class);
when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), Mockito.isA(JType.class), isNull(Schema.class))).thenReturn(mockDateType);
when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result, equalTo(mockDateType));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesNumberUsingJavaTypeFloat.
@Test
public void applyGeneratesNumberUsingJavaTypeFloat() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "number");
objectNode.put("javaType", "java.lang.Float");
when(config.isUsePrimitives()).thenReturn(true);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result.fullName(), is("java.lang.Float"));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesString.
@Test
public void applyGeneratesString() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "string");
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result.fullName(), is(String.class.getName()));
}
use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesNumberUsingJavaTypeFloatPrimitive.
@Test
public void applyGeneratesNumberUsingJavaTypeFloatPrimitive() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "number");
objectNode.put("javaType", "float");
when(config.isUsePrimitives()).thenReturn(false);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result.fullName(), is("float"));
}
Aggregations