Search in sources :

Example 1 with Person

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

Example 2 with Person

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

Example 3 with Person

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

Example 4 with Person

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

Example 5 with Person

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

Aggregations

Person (com.squareup.wire.protos.person.Person)7 Test (org.junit.Test)7 PhoneNumber (com.squareup.wire.protos.person.Person.PhoneNumber)2 ByteString (okio.ByteString)2 Buffer (okio.Buffer)1