package net.kencochrane.raven.marshaller.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import net.kencochrane.raven.event.interfaces.ExceptionInterface;
import net.kencochrane.raven.event.interfaces.ImmutableThrowable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class TestExceptionInterfaceBinding extends AbstractTestInterfaceBinding {
    private ExceptionInterfaceBinding interfaceBinding;
    @Mock
    private ExceptionInterface mockExceptionInterface;

    @Before
    public void setUp() throws Exception {
        super.setUp();
        interfaceBinding = new ExceptionInterfaceBinding();
    }

    @Test
    public void testSimpleException() throws Exception {
        String message = UUID.randomUUID().toString();
        Throwable throwable = new IllegalStateException(message);
        when(mockExceptionInterface.getThrowable()).thenReturn(new ImmutableThrowable(throwable));

        JsonGenerator jsonGenerator = getJsonGenerator();
        interfaceBinding.writeInterface(jsonGenerator, mockExceptionInterface);
        jsonGenerator.close();

        JsonNode rootNode = getMapper().readValue(getJsonParser(), JsonNode.class);
        assertThat(rootNode.get("module").asText(), is(throwable.getClass().getPackage().getName()));
        assertThat(rootNode.get("type").asText(), is(throwable.getClass().getSimpleName()));
        assertThat(rootNode.get("value").asText(), is(message));
    }
}

@@ -1532,24 +1532,129 @@
 at(rootNode.
+isArray(), is(true));%0A        JsonNode exceptionNode = rootNode.get(0);%0A        assertThat(exceptionNode.
 get(%22module%22
@@ -1726,36 +1726,41 @@
      assertThat(
-root
+exception
 Node.get(%22type%22)
@@ -1828,28 +1828,33 @@
  assertThat(
-root
+exception
 Node.get(%22va
@@ -1879,20 +1879,94 @@
 (message));%0A
+        assertThat(exceptionNode.get(%22stacktrace%22).isObject(), is(true));%0A
     %7D%0A%7D%0A

Update TestExceptionInterfaceBinding