@Override public SELF isInstanceOf(Class<?> type) { return super.isInstanceOf(type); }
@Override public SELF isInstanceOf(Class<?> type) { return super.isInstanceOf(type); }
@Test public void testMultipleSnakeCaseToCamelCase() { List<PropertyNamingSnakeCased> messages = ProtobufCreator.create(PropertyNamingSnakeCased.class, 10); JsonNode tree = toTree(camelCase(), messages); assertThat(tree).isInstanceOf(ArrayNode.class); assertThat(tree.size()).isEqualTo(10); for (int i = 0; i < 10; i++) { JsonNode subTree = tree.get(i); assertThat(subTree.isObject()).isTrue(); assertThat(subTree.size()).isEqualTo(1); assertThat(subTree.get("stringAttribute")).isNotNull(); assertThat(subTree.get("stringAttribute").textValue()).isEqualTo(messages.get(i).getStringAttribute()); } }
@Test public void testMultipleUnderscore() { List<PropertyNamingSnakeCased> messages = ProtobufCreator.create(PropertyNamingSnakeCased.class, 10); JsonNode tree = toTree(underscore(), messages); assertThat(tree).isInstanceOf(ArrayNode.class); assertThat(tree.size()).isEqualTo(10); for (int i = 0; i < 10; i++) { JsonNode subTree = tree.get(i); assertThat(subTree.isObject()).isTrue(); assertThat(subTree.size()).isEqualTo(1); assertThat(subTree.get("string_attribute")).isNotNull(); assertThat(subTree.get("string_attribute").textValue()).isEqualTo(messages.get(i).getStringAttribute()); } }
@Test public void canParseToEnumSet() throws Exception { assertThat(parser.parse("AAA, CCC", new GenericType<EnumSet<MyEnum>>() {})) .containsExactly(MyEnum.AAA, MyEnum.CCC) .isInstanceOf(EnumSet.class); }
@Test public void testMultipleStillCamelCase() { List<PropertyNamingCamelCased> messages = ProtobufCreator.create(PropertyNamingCamelCased.class, 10); @SuppressWarnings("serial") ObjectMapper mapper = new ObjectMapper().registerModule(new ProtobufModule()).setPropertyNamingStrategy( new PropertyNamingStrategy.PropertyNamingStrategyBase() { @Override public String translate(String propertyName) { return propertyName; } }); JsonNode tree = toTree(mapper, messages); assertThat(tree).isInstanceOf(ArrayNode.class); assertThat(tree.size()).isEqualTo(10); for (int i = 0; i < 10; i++) { JsonNode subTree = tree.get(i); assertThat(subTree.isObject()).isTrue(); assertThat(subTree.size()).isEqualTo(1); assertThat(subTree.get("stringAttribute")).isNotNull(); assertThat(subTree.get("stringAttribute").textValue()).isEqualTo(messages.get(i).getStringAttribute()); } }
@Test public void canParseToEmptyEnumSet() throws Exception { assertThat(parser.parse("null", new GenericType<EnumSet<MyEnum>>() {})) .isInstanceOf(EnumSet.class) .isEmpty(); }
@Test public void canParseToEmptyCollectionClasses() throws Exception { for (GenericType<? extends Collection<String>> type : COLLECTION_CLASSES) { Class<?> rawType = toRawType(type); Collection<String> collection = parser.parse("null", type); assertThat(collection) .isInstanceOf(rawType) .isEmpty(); assertThat(collection.getClass()).isEqualTo(rawType); } }
@Test public void canParseToCollectionInterfaces() throws Exception { for (GenericType<? extends Collection<String>> type : COLLECTION_INTERFACES) { Class<?> rawType = toRawType(type); Collection<String> collection = parser.parse("null", type); assertThat(collection) .isInstanceOf(rawType) .isEmpty(); } }
@Test public void canParseToCollectionClasses() throws Exception { for (GenericType<? extends Collection<String>> type : COLLECTION_CLASSES) { Class<?> rawType = toRawType(type); Collection<String> collection = parser.parse(DUMMY_STRING, type); assertThat(collection) .containsExactly(DUMMY_STRING) .hasSize(1) .isInstanceOf(rawType); assertThat(collection.getClass()).isEqualTo(rawType); } }
@Test public void canParseToEmptyCollectionInterfaces() throws Exception { for (GenericType<? extends Collection<String>> type : COLLECTION_INTERFACES) { Class<?> rawType = toRawType(type); assertThat(parser.parse(DUMMY_STRING, type)) .containsExactly(DUMMY_STRING) .hasSize(1) .isInstanceOf(rawType); } }