Search in sources :

Example 1 with CompactFields

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

Example 2 with CompactFields

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

Example 3 with CompactFields

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"));
}
Also used : IntStream(java.util.stream.IntStream) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ConsoleWatcher(net.morimekta.testing.rules.ConsoleWatcher) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Random(java.util.Random) IOMessageWriter(net.morimekta.providence.mio.IOMessageWriter) ArrayList(java.util.ArrayList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) ExtraStreams(net.morimekta.util.ExtraStreams) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JsonSerializer(net.morimekta.providence.serializer.JsonSerializer) Test(org.junit.Test) Description(org.junit.runner.Description) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) PMessage(net.morimekta.providence.PMessage) PField(net.morimekta.providence.descriptor.PField) Rule(org.junit.Rule) FastBinarySerializer(net.morimekta.providence.serializer.FastBinarySerializer) MessageReader(net.morimekta.providence.mio.MessageReader) PrettySerializer(net.morimekta.providence.serializer.PrettySerializer) CompactFields(net.morimekta.test.android.CompactFields) ProvidenceMatchers.equalToMessage(net.morimekta.providence.testing.ProvidenceMatchers.equalToMessage) IOMessageReader(net.morimekta.providence.mio.IOMessageReader) Fairy(io.codearte.jfairy.Fairy) Random(java.util.Random) JsonSerializer(net.morimekta.providence.serializer.JsonSerializer) Fairy(io.codearte.jfairy.Fairy) CompactFields(net.morimekta.test.android.CompactFields) Test(org.junit.Test)

Example 4 with CompactFields

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)));
}
Also used : IntStream(java.util.stream.IntStream) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ConsoleWatcher(net.morimekta.testing.rules.ConsoleWatcher) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Random(java.util.Random) IOMessageWriter(net.morimekta.providence.mio.IOMessageWriter) ArrayList(java.util.ArrayList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) ExtraStreams(net.morimekta.util.ExtraStreams) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JsonSerializer(net.morimekta.providence.serializer.JsonSerializer) Test(org.junit.Test) Description(org.junit.runner.Description) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) PMessage(net.morimekta.providence.PMessage) PField(net.morimekta.providence.descriptor.PField) Rule(org.junit.Rule) FastBinarySerializer(net.morimekta.providence.serializer.FastBinarySerializer) MessageReader(net.morimekta.providence.mio.MessageReader) PrettySerializer(net.morimekta.providence.serializer.PrettySerializer) CompactFields(net.morimekta.test.android.CompactFields) ProvidenceMatchers.equalToMessage(net.morimekta.providence.testing.ProvidenceMatchers.equalToMessage) IOMessageReader(net.morimekta.providence.mio.IOMessageReader) Fairy(io.codearte.jfairy.Fairy) IOMessageWriter(net.morimekta.providence.mio.IOMessageWriter) FastBinarySerializer(net.morimekta.providence.serializer.FastBinarySerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) IOMessageReader(net.morimekta.providence.mio.IOMessageReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Fairy(io.codearte.jfairy.Fairy) CompactFields(net.morimekta.test.android.CompactFields) Test(org.junit.Test)

Example 5 with CompactFields

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"));
}
Also used : 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