Search in sources :

Example 6 with OptionalFields

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

the class ProvidenceTest method testOptionalFields.

@Test
public void testOptionalFields() {
    OptionalFields of = OptionalFields.builder().build();
    assertThat(of.hasBooleanValue(), is(false));
    assertThat(of.isBooleanValue(), is(false));
    assertThat(of.hasByteValue(), is(false));
    assertThat(of.getByteValue(), is((byte) 0));
    assertThat(of.hasShortValue(), is(false));
    assertThat(of.getShortValue(), is((short) 0));
    assertThat(of.hasIntegerValue(), is(false));
    assertThat(of.getIntegerValue(), is(0));
    assertThat(of.hasLongValue(), is(false));
    assertThat(of.getLongValue(), is(0L));
    assertThat(of.hasDoubleValue(), is(false));
    assertThat(of.getDoubleValue(), is(0.0));
    assertThat(of.hasStringValue(), is(false));
    assertThat(of.getStringValue(), is(nullValue()));
    assertThat(of.hasBinaryValue(), is(false));
    assertThat(of.getBinaryValue(), is(nullValue()));
    assertThat(of.hasEnumValue(), is(false));
    assertThat(of.getEnumValue(), is(nullValue()));
    assertThat(of.hasCompactValue(), is(false));
    assertThat(of.getCompactValue(), is(nullValue()));
}
Also used : OptionalFields(net.morimekta.test.providence.testing.OptionalFields) Test(org.junit.Test)

Example 7 with OptionalFields

use of net.morimekta.test.providence.testing.OptionalFields 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

OptionalFields (net.morimekta.test.providence.testing.OptionalFields)7 Test (org.junit.Test)7 CompactFields (net.morimekta.test.providence.testing.CompactFields)4 UnionFields (net.morimekta.test.providence.testing.UnionFields)2 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 PMessage (net.morimekta.providence.PMessage)1 PField (net.morimekta.providence.descriptor.PField)1 Containers (net.morimekta.test.providence.testing.Containers)1 RequiredFields (net.morimekta.test.providence.testing.RequiredFields)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 CoreMatchers.not (org.hamcrest.CoreMatchers.not)1 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)1 Matchers.isOneOf (org.hamcrest.Matchers.isOneOf)1 Assert.assertThat (org.junit.Assert.assertThat)1 Before (org.junit.Before)1