use of com.squareup.wire.protos.person.Person in project wire by square.
the class WireTest method unmodifiedMutableListReusesImmutableInstance.
@Test
public void unmodifiedMutableListReusesImmutableInstance() {
PhoneNumber phone = new PhoneNumber.Builder().number("555-1212").type(PhoneType.WORK).build();
Person personWithPhone = new Person.Builder().id(1).name("Joe Schmoe").phone(singletonList(phone)).build();
Person personNoPhone = new Person.Builder().id(1).name("Joe Schmoe").build();
try {
personWithPhone.phone.set(0, null);
fail();
} catch (UnsupportedOperationException expected) {
}
assertThat(personNoPhone.phone).isSameAs(Collections.emptyList());
// Round-trip these instances through the builder and ensure the lists are the same instances.
assertThat(personWithPhone.newBuilder().build().phone).isSameAs(personWithPhone.phone);
assertThat(personNoPhone.newBuilder().build().phone).isSameAs(personNoPhone.phone);
}
use of com.squareup.wire.protos.person.Person in project wire by square.
the class WireTest method testPerson.
@Test
public void testPerson() throws IOException {
Person person = new Person.Builder().name("Omar").id(1234).email("omar@wire.com").phone(Arrays.asList(new PhoneNumber.Builder().number("410-555-0909").type(PhoneType.MOBILE).build())).build();
ProtoAdapter<Person> adapter = Person.ADAPTER;
byte[] data = adapter.encode(person);
adapter.decode(data);
}
use of com.squareup.wire.protos.person.Person in project wire by square.
the class WireTest method builderListsAreAlwaysMutable.
@Test
public void builderListsAreAlwaysMutable() {
PhoneNumber phone = new PhoneNumber.Builder().number("555-1212").type(PhoneType.WORK).build();
Person.Builder newBuilder = new Person.Builder();
newBuilder.phone.add(phone);
Person person = new Person.Builder().id(1).name("Joe Schmoe").phone(singletonList(phone)).build();
Person.Builder copyBuilder = person.newBuilder();
copyBuilder.phone.add(phone);
}
use of com.squareup.wire.protos.person.Person in project wire by square.
the class ProtoAdapterTest method getFromInstanceSameAsFromClass.
@Test
public void getFromInstanceSameAsFromClass() throws Exception {
Person person = new Person.Builder().id(99).name("Omar Little").build();
ProtoAdapter<Person> instanceAdapter = ProtoAdapter.get(person);
ProtoAdapter<Person> classAdapter = ProtoAdapter.get(Person.class);
assertThat(instanceAdapter).isSameAs(classAdapter);
}
use of com.squareup.wire.protos.person.Person in project wire by square.
the class SerializableTest method nestedMessage.
@Test
public void nestedMessage() throws Exception {
Person person = new Person.Builder().name("Omar").id(1234).email("omar@wire.com").phone(Arrays.asList(new Person.PhoneNumber.Builder().number("410-555-0909").type(Person.PhoneType.MOBILE).build())).build();
assertThat(deserialize(serialize(person))).isEqualTo(person);
}
Aggregations