package net.kencochrane.raven.jul;

import net.kencochrane.raven.AbstractLoggerTest;
import net.kencochrane.raven.event.Event;
import org.junit.Before;
import org.junit.Test;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SentryHandlerTest extends AbstractLoggerTest {
    private Logger logger;

    @Before
    public void setUp() throws Exception {
        logger = Logger.getAnonymousLogger();
        logger.setUseParentHandlers(false);
        logger.setLevel(Level.ALL);
        logger.addHandler(new SentryHandler(getMockRaven()));
    }

    @Override
    public void logAnyLevel(String message) {
        logger.log(Level.INFO, message);
    }

    @Override
    public void logAnyLevel(String message, Throwable exception) {
        logger.log(Level.SEVERE, message, exception);
    }

    @Override
    public void logAnyLevel(String message, List<String> parameters) {
        logger.log(Level.INFO, message, parameters.toArray());
    }

    @Override
    public String getCurrentLoggerName() {
        return logger.getName();
    }

    @Override
    @Test
    public void testLogLevelConversions() throws Exception {
        assertLevelConverted(Event.Level.DEBUG, Level.FINEST);
        assertLevelConverted(Event.Level.DEBUG, Level.FINER);
        assertLevelConverted(Event.Level.DEBUG, Level.FINE);
        assertLevelConverted(Event.Level.DEBUG, Level.CONFIG);
        assertLevelConverted(Event.Level.INFO, Level.INFO);
        assertLevelConverted(Event.Level.WARNING, Level.WARNING);
        assertLevelConverted(Event.Level.ERROR, Level.SEVERE);
    }

    private void assertLevelConverted(Event.Level expectedLevel, Level level) {
        logger.log(level, null);
        assertLogLevel(expectedLevel);
    }
}

@@ -74,24 +74,76 @@
 LoggerTest;%0A
+import net.kencochrane.raven.connection.Connection;%0A
 import net.k
@@ -240,24 +240,58 @@
 .util.List;%0A
+import java.util.logging.Handler;%0A
 import java.
@@ -344,16 +344,54 @@
 ogger;%0A%0A
+import static org.mockito.Mockito.*;%0A%0A
 public c
@@ -1748,24 +1748,649 @@
 RE);%0A    %7D%0A%0A
+    @Test%0A    public void testClosePropagates() throws Exception %7B%0A        when(getMockRaven().getConnection()).thenReturn(mock(Connection.class));%0A        Handler handler = new SentryHandler(getMockRaven(), true);%0A%0A        handler.close();%0A%0A        verify(getMockRaven().getConnection()).close();%0A    %7D%0A%0A    @Test%0A    public void testCloseDoesntPropagate() throws Exception %7B%0A        when(getMockRaven().getConnection()).thenReturn(mock(Connection.class));%0A        Handler handler = new SentryHandler(getMockRaven(), false);%0A%0A        handler.close();%0A%0A        verify(getMockRaven().getConnection(), never()).close();%0A    %7D%0A%0A
     private 

Add tests to check close propagation in JUL