use of net.morimekta.test.android.CompactFields in project providence by morimekta.
the class GeneratorWatcherTest method testRandom_defaultDump.
@Test
public void testRandom_defaultDump() {
GeneratorWatcher<SimpleGeneratorBase, SimpleGeneratorContext> generator = GeneratorWatcher.create().dumpOnFailure();
generator.starting(Description.EMPTY);
CompactFields compact = generator.generate(CompactFields.kDescriptor);
assertThat(compact.getLabel(), is(notNullValue()));
assertThat(compact.getName(), is(notNullValue()));
assertThat(compact.hasId(), is(true));
assertThat(generator.allGenerated(), hasItem(compact));
generator.failed(new Throwable(), Description.EMPTY);
assertThat(console.output(), is(""));
assertThat(console.error(), is(pretty(compact) + "\n"));
}
use of net.morimekta.test.android.CompactFields in project providence by morimekta.
the class GeneratorWatcherTest method testRandom_noDump.
@Test
public void testRandom_noDump() {
GeneratorWatcher<SimpleGeneratorBase, SimpleGeneratorContext> generator = GeneratorWatcher.create();
generator.starting(Description.EMPTY);
CompactFields compact = generator.generate(CompactFields.kDescriptor);
assertThat(compact.getLabel(), is(notNullValue()));
assertThat(compact.getName(), is(notNullValue()));
assertThat(compact.hasId(), is(true));
assertThat(generator.allGenerated(), hasItem(compact));
generator.failed(new Throwable(), Description.EMPTY);
assertThat(console.output(), is(""));
assertThat(console.error(), is(""));
}
use of net.morimekta.test.android.CompactFields in project providence by morimekta.
the class GeneratorWatcherTest method testRandom_customSerializer.
@Test
public void testRandom_customSerializer() throws IOException {
Random random = new Random();
Fairy fairy = Fairy.create(Locale.ENGLISH);
GeneratorWatcher<SimpleGeneratorBase, SimpleGeneratorContext> watcher = GeneratorWatcher.create().setOutputSerializer(new JsonSerializer()).setMaxCollectionItems(2).setRandom(random).withGenerator(CompactFields.kDescriptor, gen -> gen.setAlwaysPresent(CompactFields._Field.NAME).setAlwaysAbsent(CompactFields._Field.LABEL).setValueGenerator(CompactFields._Field.NAME, ctx -> fairy.textProducer().word(1))).setFairy(fairy).dumpOnFailure();
watcher.starting(Description.EMPTY);
CompactFields compact = watcher.generate(CompactFields.kDescriptor);
assertThat(compact.getLabel(), is(nullValue()));
assertThat(compact.getName(), is(notNullValue()));
assertThat(compact.getName(), not(containsString(" ")));
assertThat(compact.hasId(), is(true));
assertThat(watcher.allGenerated(), hasItem(compact));
watcher.failed(new Throwable(), Description.EMPTY);
assertThat(console.output(), is(""));
assertThat(console.error(), is(json(compact) + "\n"));
}
use of net.morimekta.test.android.CompactFields 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)));
}
use of net.morimekta.test.android.CompactFields in project providence by morimekta.
the class GeneratorWatcherTest method testRandom_withPregenResource.
@Test
public void testRandom_withPregenResource() {
CompactFields compact = CompactFields.builder().setId(123).setName("villa").setLabel("Sjampanjebrus").build();
CompactFields compact2 = CompactFields.builder().setId(125).setName("villa2").setLabel("Brus med smak").build();
GeneratorWatcher<SimpleGeneratorBase, SimpleGeneratorContext> generator = GeneratorWatcher.create().dumpOnFailure().setResourceReader("/pregen.cfg");
generator.starting(Description.EMPTY);
CompactFields gen = generator.generate(CompactFields.kDescriptor);
CompactFields gen2 = generator.generate(CompactFields.kDescriptor);
assertThat(gen, notNullValue());
assertThat(gen2, notNullValue());
assertThat(generator.allGenerated(), hasItem(compact));
assertThat(generator.allGenerated(), hasItem(compact2));
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" + "android.CompactFields {\n" + " name = \"villa2\"\n" + " id = 125\n" + " label = \"Brus med smak\"\n" + "}\n"));
}
Aggregations