use of com.squareup.wire.protos.simple.SimpleMessage in project wire by square.
the class WireTest method mutateBuilder.
@Test
public void mutateBuilder() throws Exception {
SimpleMessage message = new SimpleMessage.Builder().required_int32(10).build();
SimpleMessage.Builder builder = message.newBuilder();
builder.required_int32 = 20;
builder.repeated_double.add(30.5);
builder.optional_int32 = 40;
assertThat(builder.build()).isEqualTo(new SimpleMessage.Builder().required_int32(20).repeated_double(Arrays.asList(30.5)).optional_int32(40).build());
}
use of com.squareup.wire.protos.simple.SimpleMessage in project wire by square.
the class WireTest method testExtensionsNoRegistry.
@Test
public void testExtensionsNoRegistry() throws Exception {
ExternalMessage optional_external_msg = new ExternalMessage.Builder().fooext(Arrays.asList(444, 555)).barext(333).bazext(222).build();
SimpleMessage msg = new SimpleMessage.Builder().optional_external_msg(optional_external_msg).required_int32(456).build();
assertThat(msg.optional_external_msg.fooext).containsExactly(444, 555);
assertThat(msg.optional_external_msg.barext).isEqualTo(new Integer(333));
assertThat(msg.optional_external_msg.bazext).isEqualTo(new Integer(222));
ProtoAdapter<SimpleMessage> adapter = SimpleMessage.ADAPTER;
byte[] result = adapter.encode(msg);
assertThat(result.length).isEqualTo(21);
SimpleMessage newMsg = adapter.decode(result);
assertThat(newMsg.optional_external_msg.fooext).isEqualTo(Arrays.asList(444, 555));
assertThat(newMsg.optional_external_msg.barext).isEqualTo(333);
assertThat(newMsg.optional_external_msg.bazext).isEqualTo(222);
}
use of com.squareup.wire.protos.simple.SimpleMessage in project wire by square.
the class WireTest method testExtensions.
@Test
public void testExtensions() throws Exception {
ExternalMessage optional_external_msg = new ExternalMessage.Builder().fooext(Arrays.asList(444, 555)).barext(333).bazext(222).nested_message_ext(new SimpleMessage.NestedMessage.Builder().bb(77).build()).nested_enum_ext(SimpleMessage.NestedEnum.BAZ).build();
SimpleMessage msg = new SimpleMessage.Builder().optional_external_msg(optional_external_msg).required_int32(456).build();
assertThat(msg.optional_external_msg.fooext).containsExactly(444, 555);
assertThat(msg.optional_external_msg.barext).isEqualTo(new Integer(333));
assertThat(msg.optional_external_msg.bazext).isEqualTo(new Integer(222));
assertThat(msg.optional_external_msg.nested_message_ext.bb).isEqualTo(new Integer(77));
assertThat(msg.optional_external_msg.nested_enum_ext).isEqualTo(SimpleMessage.NestedEnum.BAZ);
ProtoAdapter<SimpleMessage> adapter = SimpleMessage.ADAPTER;
byte[] result = adapter.encode(msg);
assertThat(result.length).isEqualTo(29);
SimpleMessage newMsg = adapter.decode(result);
assertThat(newMsg.optional_external_msg.fooext).containsExactly(444, 555);
assertThat(newMsg.optional_external_msg.barext).isEqualTo(new Integer(333));
assertThat(newMsg.optional_external_msg.bazext).isEqualTo(new Integer(222));
}
Aggregations