Search in sources :

Example 1 with UnionFields

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

the class ProvidenceTest method testUnion.

@Test
public void testUnion() {
    UnionFields uf = UnionFields.withCompactValue(new CompactFields("a", 4, null));
    assertThat(uf.unionField(), is(UnionFields._Field.COMPACT_VALUE));
    assertThat(uf.hasCompactValue(), is(true));
    assertThat(uf.getCompactValue(), is(any(CompactFields.class)));
    assertThat(uf.getEnumValue(), is(nullValue()));
    assertThat(uf.getBinaryValue(), is(nullValue()));
    assertThat(uf.hasBooleanValue(), is(false));
    assertThat(uf.hasByteValue(), is(false));
}
Also used : UnionFields(net.morimekta.test.providence.testing.UnionFields) CompactFields(net.morimekta.test.providence.testing.CompactFields) Test(org.junit.Test)

Example 2 with UnionFields

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

the class ProvidenceTest method testHashCode.

@Test
public void testHashCode() {
    OptionalFields of = OptionalFields.builder().build();
    OptionalFields of2 = OptionalFields.builder().build();
    RequiredFields rf = RequiredFields.builder().build();
    UnionFields uf = UnionFields.withCompactValue(new CompactFields("a", 4, null));
    assertThat(of, not(sameInstance(of2)));
    assertThat(of.hashCode(), is(equalTo(of2.hashCode())));
    assertThat(of.hashCode(), not(equalTo(rf.hashCode())));
    assertThat(uf.hashCode(), not(equalTo(rf.hashCode())));
}
Also used : UnionFields(net.morimekta.test.providence.testing.UnionFields) OptionalFields(net.morimekta.test.providence.testing.OptionalFields) RequiredFields(net.morimekta.test.providence.testing.RequiredFields) CompactFields(net.morimekta.test.providence.testing.CompactFields) Test(org.junit.Test)

Example 3 with UnionFields

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

the class MessageGeneratorTest method testGenerate_unionPresence_oneRequired.

@Test
public void testGenerate_unionPresence_oneRequired() {
    MessageGenerator<FixedUuidContext, UnionFields, UnionFields._Field> unionGenerator = base.messageGeneratorFor(UnionFields.kDescriptor);
    unionGenerator.setAlwaysPresent(UnionFields._Field.INTEGER_VALUE);
    for (int i = 0; i < 10; ++i) {
        UnionFields unionFields = unionGenerator.generate(base.createContext());
        assertThat(unionFields.unionField(), is(UnionFields._Field.INTEGER_VALUE));
    }
    unionGenerator.resetDefaultPresence().setAlwaysAbsent(UnionFields._Field.INTEGER_VALUE, UnionFields._Field.SHORT_VALUE, UnionFields._Field.LONG_VALUE, UnionFields._Field.STRING_VALUE, UnionFields._Field.BINARY_VALUE);
    for (int i = 0; i < 10; ++i) {
        UnionFields unionFields = unionGenerator.generate(base.createContext());
        assertThat(unionFields.unionField(), not(isOneOf(UnionFields._Field.INTEGER_VALUE, UnionFields._Field.SHORT_VALUE, UnionFields._Field.LONG_VALUE, UnionFields._Field.STRING_VALUE, UnionFields._Field.BINARY_VALUE)));
    }
}
Also used : UnionFields(net.morimekta.test.providence.testing.UnionFields) Test(org.junit.Test)

Aggregations

UnionFields (net.morimekta.test.providence.testing.UnionFields)3 Test (org.junit.Test)3 CompactFields (net.morimekta.test.providence.testing.CompactFields)2 OptionalFields (net.morimekta.test.providence.testing.OptionalFields)1 RequiredFields (net.morimekta.test.providence.testing.RequiredFields)1