Skip to content

Commit

Permalink
Add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaber committed Dec 31, 2023
1 parent 9879fa1 commit f946fc8
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ public String nameForField(
.isEqualTo(message.getStringAttribute());
}

@Test
public void testSingleNoNamingStrategy() {
PropertyNamingCamelCased message = ProtobufCreator.create(
PropertyNamingCamelCased.class
);

@SuppressWarnings("serial")
ObjectMapper mapper = new ObjectMapper()
.registerModule(new ProtobufModule());

JsonNode tree = toTree(mapper, message);

assertThat(tree.isObject()).isTrue();
assertThat(tree.size()).isEqualTo(1);
assertThat(tree.get("stringattribute")).isNotNull();
assertThat(tree.get("stringattribute").textValue())
.isEqualTo(message.getStringAttribute());
}

@Test
public void testSingleStillCamelCaseUsingNamingBase() {
PropertyNamingCamelCased message = ProtobufCreator.create(
Expand Down Expand Up @@ -208,6 +227,34 @@ public String nameForField(
}
}

@Test
public void testMultipleNoNamingStrategy() {
List<PropertyNamingCamelCased> messages = ProtobufCreator.create(
PropertyNamingCamelCased.class,
10
);

@SuppressWarnings("serial")
ObjectMapper mapper = new ObjectMapper()
.registerModule(new ProtobufModule());

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 testMultipleStillCamelCaseUsingNamingBase() {
List<PropertyNamingCamelCased> messages = ProtobufCreator.create(
Expand Down

0 comments on commit f946fc8

Please sign in to comment.