@Test
public void testMarshallUser() throws Exception {
SerializationContext ctx = createContext();
User user = new User();
user.setId(1);
user.setName("John");
user.setSurname("Batman");
user.setGender(User.Gender.MALE);
user.setAccountIds(Arrays.asList(1, 3));
user.setAddresses(Collections.singletonList(new Address("Old Street", "XYZ42")));
byte[] bytes = ProtobufUtil.toByteArray(ctx, user);
User decoded = ProtobufUtil.fromByteArray(ctx, bytes, User.class);
assertEquals(1, decoded.getId());
assertEquals("John", decoded.getName());
assertEquals("Batman", decoded.getSurname());
assertEquals(User.Gender.MALE, decoded.getGender());
assertNotNull(decoded.getAddresses());
assertEquals(1, decoded.getAddresses().size());
assertEquals("Old Street", decoded.getAddresses().get(0).getStreet());
assertEquals("XYZ42", decoded.getAddresses().get(0).getPostCode());
assertNotNull(decoded.getAccountIds());
assertEquals(2, decoded.getAccountIds().size());
assertEquals(1, decoded.getAccountIds().get(0).intValue());
assertEquals(3, decoded.getAccountIds().get(1).intValue());
}