use of net.morimekta.test.providence.testing.OptionalFields in project providence by morimekta.
the class MessageGeneratorTest method testGenerate_presenceOverrides.
@Test
public void testGenerate_presenceOverrides() {
base.withMessageGenerator(OptionalFields.kDescriptor, gen -> gen.setAlwaysPresent(OptionalFields._Field.BINARY_VALUE, OptionalFields._Field.BOOLEAN_VALUE, OptionalFields._Field.BYTE_VALUE).setAlwaysAbsent(OptionalFields._Field.INTEGER_VALUE, OptionalFields._Field.SHORT_VALUE, OptionalFields._Field.LONG_VALUE));
OptionalFields res = generator.generate(base.createContext());
assertThat(res.hasBinaryValue(), is(true));
assertThat(res.hasBooleanValue(), is(true));
assertThat(res.hasByteValue(), is(true));
assertThat(res.hasIntegerValue(), is(false));
assertThat(res.hasShortValue(), is(false));
assertThat(res.hasLongValue(), is(false));
}
use of net.morimekta.test.providence.testing.OptionalFields in project providence by morimekta.
the class ProvidenceBuilderTest method testMerge.
@Test
public void testMerge() {
OptionalFields a = OptionalFields.builder().setIntegerValue(1).setDoubleValue(1.1).setCompactValue(new CompactFields("a", 1, "al")).build();
OptionalFields b = OptionalFields.builder().setIntegerValue(2).setCompactValue(new CompactFields("b", 2, null)).build();
OptionalFields exp = OptionalFields.builder().setIntegerValue(2).setDoubleValue(1.1).setCompactValue(new CompactFields("b", 2, "al")).build();
OptionalFields c = a.mergeWith(b);
assertEquals(exp, c);
}
use of net.morimekta.test.providence.testing.OptionalFields 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.OptionalFields in project providence by morimekta.
the class MessageGeneratorTest method testGenerate_withCutsomContext.
@Test
public void testGenerate_withCutsomContext() {
base.setDefaultFillRate(1.0).withMessageGenerator(OptionalFields.kDescriptor, generator -> generator.setValueGenerator(OptionalFields._Field.STRING_VALUE, context -> context.getUuid().toString()).setValueGenerator(OptionalFields._Field.LONG_VALUE, context -> context.getUuid().getMostSignificantBits()));
FixedUuidContext reused = base.createContext();
OptionalFields first = generator.generate(reused);
OptionalFields second = generator.generate(base.createContext());
assertThat(first.getStringValue(), is(not(second.getStringValue())));
long firstMost = UUID.fromString(first.getStringValue()).getMostSignificantBits();
long secondMost = UUID.fromString(second.getStringValue()).getMostSignificantBits();
assertThat(first.getLongValue(), is(firstMost));
assertThat(second.getLongValue(), is(secondMost));
OptionalFields whenReused = generator.generate(reused);
assertThat(whenReused.getStringValue(), is(first.getStringValue()));
}
use of net.morimekta.test.providence.testing.OptionalFields in project providence by morimekta.
the class ProvidenceBuilderTest method testMergeBuilder.
@Test
public void testMergeBuilder() {
OptionalFields._Builder a = OptionalFields.builder().setIntegerValue(1).setCompactValue(new CompactFields("a", 1, "al"));
OptionalFields b = OptionalFields.builder().setDoubleValue(1.1).setCompactValue(new CompactFields("b", 2, null)).build();
// C will have modified from both a and b.
OptionalFields._Builder c = a.merge(b);
assertThat(c.isModified(OptionalFields._Field.INTEGER_VALUE), is(true));
assertThat(c.isModified(OptionalFields._Field.COMPACT_VALUE), is(true));
assertThat(c.isModified(OptionalFields._Field.DOUBLE_VALUE), is(true));
assertThat(c.isModified(OptionalFields._Field.ENUM_VALUE), is(false));
assertThat(c.modifiedFields().size(), is(3));
assertThat(c.modifiedFields(), hasItems(OptionalFields._Field.INTEGER_VALUE, OptionalFields._Field.COMPACT_VALUE, OptionalFields._Field.DOUBLE_VALUE));
// enum value will also be modified, although nothing has changed internally.
c.clearEnumValue();
assertThat(c.isModified(OptionalFields._Field.INTEGER_VALUE), is(true));
assertThat(c.isModified(OptionalFields._Field.COMPACT_VALUE), is(true));
assertThat(c.isModified(OptionalFields._Field.DOUBLE_VALUE), is(true));
assertThat(c.isModified(OptionalFields._Field.ENUM_VALUE), is(true));
assertThat(c.modifiedFields().size(), is(4));
assertThat(c.modifiedFields(), hasItems(OptionalFields._Field.INTEGER_VALUE, OptionalFields._Field.COMPACT_VALUE, OptionalFields._Field.DOUBLE_VALUE, OptionalFields._Field.ENUM_VALUE));
// See that all fields expected are set.
b = c.build();
for (OptionalFields._Field field : OptionalFields.kDescriptor.getFields()) {
switch(field) {
case INTEGER_VALUE:
case COMPACT_VALUE:
case DOUBLE_VALUE:
assertThat(field.getName(), b.has(field), is(true));
break;
case ENUM_VALUE:
// this is a cleared value so it was modified, but won't have a valid value.
assertThat(field.getName(), b.has(field), is(false));
break;
default:
assertThat(field.getName(), b.has(field), is(false));
break;
}
}
// See that all fields modified after reset is false.
c = b.mutate();
for (OptionalFields._Field field : OptionalFields.kDescriptor.getFields()) {
assertThat(c.isModified(field), is(false));
}
assertThat(c.modifiedFields().size(), is(0));
}
Aggregations