package net.kencochrane.raven;

import net.kencochrane.raven.connection.Connection;
import net.kencochrane.raven.event.Event;
import net.kencochrane.raven.event.EventBuilder;
import net.kencochrane.raven.event.helper.EventBuilderHelper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class RavenTest {
    private Raven raven;
    @Mock
    private Connection mockConnection;
    @Mock
    private EventBuilderHelper mockBuilderHelper;
    @Mock
    private Event mockEvent;

    @Before
    public void setUp() throws Exception {
        raven = new Raven();
        raven.setConnection(mockConnection);
    }

    @Test
    public void testSendEvent() throws Exception {
        raven.sendEvent(mockEvent);

        verify(mockConnection).send(mockEvent);
    }

    @Test
    public void testChangeConnection() throws Exception {
        Connection mockNewConnection = mock(Connection.class);

        raven.setConnection(mockNewConnection);
        raven.sendEvent(mockEvent);

        verify(mockConnection, never()).send(mockEvent);
        verify(mockNewConnection).send(mockEvent);
    }

    @Test
    public void testAddRemoveBuilderHelpers() throws Exception {
        assertThat(raven.getBuilderHelpers(), not(contains(mockBuilderHelper)));

        raven.addBuilderHelper(mockBuilderHelper);
        assertThat(raven.getBuilderHelpers(), contains(mockBuilderHelper));
        raven.removeBuilderHelper(mockBuilderHelper);
        assertThat(raven.getBuilderHelpers(), not(contains(mockBuilderHelper)));
    }

    @Test(expected = UnsupportedOperationException.class)
    public void testCantModifyBuilderHelpersDirectly() throws Exception {
        raven.getBuilderHelpers().add(mockBuilderHelper);
    }

    @Test
    public void testRunBuilderHelpers() throws Exception {
        EventBuilder eventBuilder = mock(EventBuilder.class);
        raven.addBuilderHelper(mockBuilderHelper);

        raven.runBuilderHelpers(eventBuilder);

        verify(mockBuilderHelper).helpBuildingEvent(eventBuilder);
    }
}

@@ -226,24 +226,90 @@
 lderHelper;%0A
+import net.kencochrane.raven.event.interfaces.ExceptionInterface;%0A
 import org.j
@@ -321,16 +321,16 @@
 Before;%0A
-
 import o
@@ -377,16 +377,51 @@
 unWith;%0A
+import org.mockito.ArgumentCaptor;%0A
 import o
@@ -485,16 +485,40 @@
 unner;%0A%0A
+import java.util.UUID;%0A%0A
 import s
@@ -602,57 +602,9 @@
 ers.
-contains;%0Aimport static org.hamcrest.Matchers.not
+*
 ;%0Aim
@@ -1099,32 +1099,32 @@
 nt(mockEvent);%0A%0A
-
         verify(m
@@ -1154,32 +1154,1201 @@
 kEvent);%0A    %7D%0A%0A
+    @Test%0A    public void testSendMessage() throws Exception %7B%0A        String message = UUID.randomUUID().toString();%0A        ArgumentCaptor%3CEvent%3E eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);%0A        raven.sendMessage(message);%0A%0A        verify(mockConnection).send(eventArgumentCaptor.capture());%0A        assertThat(eventArgumentCaptor.getValue().getLevel(), equalTo(Event.Level.INFO));%0A        assertThat(eventArgumentCaptor.getValue().getMessage(), equalTo(message));%0A    %7D%0A%0A    @Test%0A    public void testSendException() throws Exception %7B%0A        String message = UUID.randomUUID().toString();%0A        Exception exception = new Exception(message);%0A        ArgumentCaptor%3CEvent%3E eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);%0A        raven.sendException(exception);%0A%0A        verify(mockConnection).send(eventArgumentCaptor.capture());%0A        assertThat(eventArgumentCaptor.getValue().getLevel(), equalTo(Event.Level.ERROR));%0A        assertThat(eventArgumentCaptor.getValue().getMessage(), equalTo(message));%0A        assertThat(eventArgumentCaptor.getValue().getSentryInterfaces(), hasKey(ExceptionInterface.EXCEPTION_INTERFACE));%0A    %7D%0A%0A
     @Test%0A    pu

Add tests for sendMessage and sendException