use of net.morimekta.test.providence.testing.AutoIdFields in project providence by morimekta.
the class ProvidenceTest method testAutoIdFields.
@Test
public void testAutoIdFields() throws IOException {
AutoIdFields af = AutoIdFields.builder().setBooleanValue(false).setByteValue((byte) 4).setShortValue((short) 6).setIntegerValue(8).setLongValue(10L).setDoubleValue(12.12).setStringValue("a string").setBinaryValue(Binary.fromHexString("0123456789abcdef")).setCompactValue(new CompactFields("name", 14, "label")).setEnumValue(Value.SIXTEENTH).build();
BinarySerializer serializer = new BinarySerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(baos, af);
AutoIdFields af2 = serializer.deserialize(new ByteArrayInputStream(baos.toByteArray()), AutoIdFields.kDescriptor);
assertThat(af2, is(equalToMessage(af)));
// An interesting side effect from auto ID fields, is that the numeric
// order is reverse that of declared order. Always.
assertEquals("{\n" + " compactValue = {\n" + " name = \"name\"\n" + " id = 14\n" + " label = \"label\"\n" + " }\n" + " enumValue = SIXTEENTH\n" + " binaryValue = b64(ASNFZ4mrze8)\n" + " stringValue = \"a string\"\n" + " doubleValue = 12.12\n" + " longValue = 10\n" + " integerValue = 8\n" + " shortValue = 6\n" + " byteValue = 4\n" + " booleanValue = false\n" + "}", debugString(af2));
}
Aggregations