Skip to content

Commit da2f54a

Browse files
committed
expanding the test to also serialize / deserialize list, and map
1 parent 2154655 commit da2f54a

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackDataformatForPojoTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020

2121
import java.io.IOException;
2222
import java.nio.charset.Charset;
23-
import java.util.Arrays;
2423

2524
import static org.hamcrest.CoreMatchers.not;
2625
import static org.hamcrest.CoreMatchers.containsString;
2726

2827
import static org.junit.Assert.assertEquals;
2928
import static org.junit.Assert.assertThat;
30-
import static org.junit.Assert.assertTrue;
29+
import static org.junit.Assert.assertArrayEquals;
3130

3231
public class MessagePackDataformatForPojoTest
3332
extends MessagePackDataformatTestBase
@@ -44,7 +43,7 @@ public void testNormal()
4443
assertEquals(normalPojo.l, value.l);
4544
assertEquals(normalPojo.f, value.f, 0.000001f);
4645
assertEquals(normalPojo.d, value.d, 0.000001f);
47-
assertTrue(Arrays.equals(normalPojo.b, value.b));
46+
assertArrayEquals(normalPojo.b, value.b);
4847
assertEquals(normalPojo.bi, value.bi);
4948
assertEquals(normalPojo.suit, Suit.HEART);
5049
}
@@ -56,7 +55,7 @@ public void testNestedList()
5655
byte[] bytes = objectMapper.writeValueAsBytes(nestedListPojo);
5756
NestedListPojo value = objectMapper.readValue(bytes, NestedListPojo.class);
5857
assertEquals(nestedListPojo.s, value.s);
59-
assertTrue(Arrays.equals(nestedListPojo.strs.toArray(), value.strs.toArray()));
58+
assertArrayEquals(nestedListPojo.strs.toArray(), value.strs.toArray());
6059
}
6160

6261
@Test
@@ -112,12 +111,13 @@ public void testSerializationWithoutSchema()
112111
{
113112
ObjectMapper objectMapper = new ObjectMapper(factory); // to not affect shared objectMapper state
114113
objectMapper.setAnnotationIntrospector(new JsonArrayFormat());
115-
UsingCustomConstructorPojo orig = new UsingCustomConstructorPojo("komamitsu", 55);
116-
byte[] bytes = objectMapper.writeValueAsBytes(orig);
114+
byte[] bytes = objectMapper.writeValueAsBytes(complexPojo);
117115
String scheme = new String(bytes, Charset.forName("UTF-8"));
118-
assertThat(scheme, not(containsString("name")));
119-
UsingCustomConstructorPojo value = objectMapper.readValue(bytes, UsingCustomConstructorPojo.class);
116+
assertThat(scheme, not(containsString("name"))); // validating schema doesn't contains keys, that's just array
117+
ComplexPojo value = objectMapper.readValue(bytes, ComplexPojo.class);
120118
assertEquals("komamitsu", value.name);
121-
assertEquals(55, value.age);
119+
assertEquals(20, value.age);
120+
assertArrayEquals(complexPojo.values.toArray(), value.values.toArray());
121+
assertEquals(complexPojo.grades.get("math"), value.grades.get("math"));
122122
}
123123
}

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackDataformatTestBase.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.ArrayList;
3333
import java.util.Arrays;
3434
import java.util.List;
35+
import java.util.Map;
36+
import java.util.Collections;
3537

3638
public class MessagePackDataformatTestBase
3739
{
@@ -43,6 +45,7 @@ public class MessagePackDataformatTestBase
4345
protected NestedListPojo nestedListPojo;
4446
protected NestedListComplexPojo nestedListComplexPojo;
4547
protected TinyPojo tinyPojo;
48+
protected ComplexPojo complexPojo;
4649

4750
@Before
4851
public void setup()
@@ -65,14 +68,21 @@ public void setup()
6568

6669
nestedListPojo = new NestedListPojo();
6770
nestedListPojo.s = "a string";
68-
nestedListPojo.strs = Arrays.asList(new String[] {"string", "another string", "another string"});
71+
nestedListPojo.strs = Arrays.asList("string", "another string", "another string");
6972

7073
tinyPojo = new TinyPojo();
7174
tinyPojo.t = "t string";
75+
7276
nestedListComplexPojo = new NestedListComplexPojo();
7377
nestedListComplexPojo.s = "a string";
7478
nestedListComplexPojo.foos = new ArrayList<TinyPojo>();
7579
nestedListComplexPojo.foos.add(tinyPojo);
80+
81+
complexPojo = new ComplexPojo();
82+
complexPojo.name = "komamitsu";
83+
complexPojo.age = 20;
84+
complexPojo.grades = Collections.singletonMap("math", 97);
85+
complexPojo.values = Arrays.asList("one", "two", "three");
7686
}
7787

7888
@After
@@ -108,6 +118,14 @@ public static class NestedListPojo
108118
public List<String> strs;
109119
}
110120

121+
public static class ComplexPojo
122+
{
123+
public String name;
124+
public int age;
125+
public List<String> values;
126+
public Map<String, Integer> grades;
127+
}
128+
111129
public static class TinyPojo
112130
{
113131
public String t;

0 commit comments

Comments
 (0)