Search in sources :

Example 1 with PhoneNumber

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);
}
Also used : PhoneNumber(com.squareup.wire.protos.person.Person.PhoneNumber) Person(com.squareup.wire.protos.person.Person) Test(org.junit.Test)

Example 2 with PhoneNumber

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);
}
Also used : PhoneNumber(com.squareup.wire.protos.person.Person.PhoneNumber) Person(com.squareup.wire.protos.person.Person) Test(org.junit.Test)

Aggregations

Person (com.squareup.wire.protos.person.Person)2 PhoneNumber (com.squareup.wire.protos.person.Person.PhoneNumber)2 Test (org.junit.Test)2