Search in sources :

Example 1 with FastBinarySerializer

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)));
}
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)

Aggregations

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