Search in sources :

Example 6 with CompactFields

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"));
    }
}
Also used : ArrayList(java.util.ArrayList) CompactFields(net.morimekta.test.android.CompactFields) Test(org.junit.Test)

Example 7 with CompactFields

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"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOMessageReader(net.morimekta.providence.mio.IOMessageReader) PrettySerializer(net.morimekta.providence.serializer.PrettySerializer) MessageReader(net.morimekta.providence.mio.MessageReader) IOMessageReader(net.morimekta.providence.mio.IOMessageReader) CompactFields(net.morimekta.test.android.CompactFields) Test(org.junit.Test)

Aggregations

CompactFields (net.morimekta.test.android.CompactFields)7 Test (org.junit.Test)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 IOMessageReader (net.morimekta.providence.mio.IOMessageReader)3 MessageReader (net.morimekta.providence.mio.MessageReader)3 PrettySerializer (net.morimekta.providence.serializer.PrettySerializer)3 Fairy (io.codearte.jfairy.Fairy)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Locale (java.util.Locale)2 Random (java.util.Random)2 IntStream (java.util.stream.IntStream)2 PMessage (net.morimekta.providence.PMessage)2 PField (net.morimekta.providence.descriptor.PField)2 IOMessageWriter (net.morimekta.providence.mio.IOMessageWriter)2 FastBinarySerializer (net.morimekta.providence.serializer.FastBinarySerializer)2 JsonSerializer (net.morimekta.providence.serializer.JsonSerializer)2 ProvidenceMatchers.equalToMessage (net.morimekta.providence.testing.ProvidenceMatchers.equalToMessage)2