use of com.squareup.wire.protos.person.Person.PhoneNumber 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.PhoneNumber 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);
}
Aggregations