Search in sources :

Example 1 with Containers

use of net.morimekta.test.providence.testing.Containers in project providence by morimekta.

the class ProvidenceBuilderTest method testEmptyCollections.

@Test
public void testEmptyCollections() {
    Containers._Builder builder = Containers.builder().setBinarySet(Collections.EMPTY_SET).setIntegerList(Collections.EMPTY_LIST).setLongMap(Collections.EMPTY_MAP);
    assertThat(builder.isModifiedBinarySet(), is(true));
    assertThat(builder.isModifiedIntegerList(), is(true));
    assertThat(builder.isModifiedLongMap(), is(true));
    assertThat(builder.modifiedFields().size(), is(3));
    assertThat(builder.modifiedFields(), hasItems(Containers._Field.BINARY_SET, Containers._Field.INTEGER_LIST, Containers._Field.LONG_MAP));
    Containers containers = builder.build();
    assertThat(containers.hasBinarySet(), is(true));
    assertThat(containers.hasIntegerList(), is(true));
    assertThat(containers.hasLongMap(), is(true));
    assertThat(containers.mutate().build(), is(equalToMessage(containers)));
}
Also used : Containers(net.morimekta.test.providence.testing.Containers) Test(org.junit.Test)

Example 2 with Containers

use of net.morimekta.test.providence.testing.Containers in project providence by morimekta.

the class ProvidenceTest method testMutable.

@Test
public void testMutable() {
    OptionalFields of = OptionalFields.builder().setCompactValue(new CompactFields("a", 4, null)).build();
    Containers a = Containers.builder().setOptionalFields(of).build();
    Containers._Builder b = a.mutate();
    assertThat(b.build().getOptionalFields(), is(sameInstance(of)));
    b.mutableOptionalFields().setIntegerValue(55);
    Containers c = b.build();
    // Even if the intermediate structure is mutated
    // inner contained structures are not rebuilt.
    assertThat(c.getOptionalFields().getIntegerValue(), is(55));
    assertThat(c.getOptionalFields().getCompactValue(), is(sameInstance(of.getCompactValue())));
}
Also used : OptionalFields(net.morimekta.test.providence.testing.OptionalFields) Containers(net.morimekta.test.providence.testing.Containers) CompactFields(net.morimekta.test.providence.testing.CompactFields) Test(org.junit.Test)

Aggregations

Containers (net.morimekta.test.providence.testing.Containers)2 Test (org.junit.Test)2 CompactFields (net.morimekta.test.providence.testing.CompactFields)1 OptionalFields (net.morimekta.test.providence.testing.OptionalFields)1