use of net.morimekta.test.android.CompactFields in project providence by morimekta.
the class GeneratorWatcherTest method testRandom_multipleMessages.
@Test
public void testRandom_multipleMessages() {
GeneratorWatcher<SimpleGeneratorBase, SimpleGeneratorContext> generator = GeneratorWatcher.create().setFillRate(0.667).dumpOnFailure();
generator.starting(Description.EMPTY);
ArrayList<CompactFields> list = new ArrayList<>(100);
IntStream.range(0, 100).forEach(i -> list.add(generator.generate(CompactFields.kDescriptor)));
assertThat(list.size(), is(100));
for (CompactFields compact : list) {
assertThat(generator.allGenerated(), hasItem(compact));
}
generator.failed(new Throwable(), Description.EMPTY);
assertThat(console.output(), is(""));
for (CompactFields compact : list) {
assertThat(console.error(), containsString(pretty(compact) + "\n"));
}
}
use of net.morimekta.test.android.CompactFields in project providence by morimekta.
the class GeneratorWatcherTest method testRandom_withReader.
@Test
public void testRandom_withReader() {
ByteArrayInputStream bais = new ByteArrayInputStream(("{\n" + " name = \"villa\"\n" + " id = 123\n" + " label = \"Sjampanjebrus\"\n" + "}\n").getBytes(StandardCharsets.UTF_8));
MessageReader reader = new IOMessageReader(bais, new PrettySerializer());
CompactFields compact = CompactFields.builder().setId(123).setName("villa").setLabel("Sjampanjebrus").build();
GeneratorWatcher<SimpleGeneratorBase, SimpleGeneratorContext> generator = GeneratorWatcher.create().dumpOnFailure().setMessageReader(reader);
generator.starting(Description.EMPTY);
CompactFields gen = generator.generate(CompactFields.kDescriptor);
assertThat(gen, is(equalToMessage(compact)));
assertThat(generator.allGenerated(), hasItem(compact));
generator.failed(new Throwable(), Description.EMPTY);
assertThat(console.output(), is(""));
assertThat(console.error(), is("android.CompactFields {\n" + " name = \"villa\"\n" + " id = 123\n" + " label = \"Sjampanjebrus\"\n" + "}\n"));
}
Aggregations