use of net.morimekta.providence.serializer.FastBinarySerializer in project providence by morimekta.
the class GeneratorWatcherTest method testRandom_customWriter.
@Test
public void testRandom_customWriter() throws IOException {
Fairy fairy = Fairy.create(Locale.ENGLISH);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GeneratorWatcher<SimpleGeneratorBase, SimpleGeneratorContext> generator = GeneratorWatcher.create().setMessageWriter(new IOMessageWriter(baos, new FastBinarySerializer())).setMaxCollectionItems(2).withGenerator(CompactFields.kDescriptor, gen -> {
gen.setAlwaysPresent(CompactFields._Field.NAME);
gen.setValueGenerator(CompactFields._Field.NAME, ctx -> fairy.textProducer().word(1));
}).dumpOnFailure();
generator.starting(Description.EMPTY);
CompactFields compact = generator.generate(CompactFields.kDescriptor);
assertThat(compact.getLabel(), is(notNullValue()));
assertThat(compact.getName(), is(notNullValue()));
assertThat(compact.getName(), not(containsString(" ")));
assertThat(compact.hasId(), is(true));
assertThat(generator.allGenerated(), hasItem(compact));
generator.failed(new Throwable(), Description.EMPTY);
assertThat(console.output(), is(""));
assertThat(console.error(), is(""));
IOMessageReader reader = new IOMessageReader(new ByteArrayInputStream(baos.toByteArray()), new FastBinarySerializer());
assertThat(reader.read(CompactFields.kDescriptor), is(equalToMessage(compact)));
}
Aggregations