Search in sources :

Example 1 with ExceptionFields

use of net.morimekta.test.providence.testing.ExceptionFields in project providence by morimekta.

the class ProvidenceTest method testSerializable.

@Test
public void testSerializable() throws IOException, ClassNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    PApplicationException originalCause = new PApplicationException("test", PApplicationExceptionType.BAD_SEQUENCE_ID);
    ExceptionFields original = generator.generate(ExceptionFields.kDescriptor);
    original.initCause(originalCause);
    oos.writeObject(original);
    oos.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream in = new ObjectInputStream(bais);
    ExceptionFields actual = (ExceptionFields) in.readObject();
    assertThat(actual, is(equalToMessage(original)));
    assertThat(actual.getCause(), is(originalCause));
    assertThat(actual.getStackTrace(), is(original.getStackTrace()));
}
Also used : ExceptionFields(net.morimekta.test.providence.testing.ExceptionFields) ByteArrayInputStream(java.io.ByteArrayInputStream) PApplicationException(net.morimekta.providence.PApplicationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 PApplicationException (net.morimekta.providence.PApplicationException)1 ExceptionFields (net.morimekta.test.providence.testing.ExceptionFields)1 Test (org.junit.Test)1