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));
}
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())));
}
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)));
}
}
Aggregations