package software.reinvent.log;


import org.jukito.JukitoRunner;
import org.jukito.UseModules;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.Appender;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
 * Created on 11.01.2017.
 *
 * @author <a href="mailto:lenny@reinvent.software">Leonard Daume</a>
 */
@RunWith(JukitoRunner.class)
@UseModules(LoggerModule.class)
public class LoggerTest {

    @InjectLogger
    private org.slf4j.Logger injectedLogger;

    private Logger rootLogger;

    private Appender mockedAppender = mock(Appender.class);
    private ArgumentCaptor<Appender> argumentCaptor = ArgumentCaptor.forClass(Appender.class);

    @Before
    public void setUp(Appender<ILoggingEvent> appender, ArgumentCaptor<Appender> argumentCaptor) throws Exception {
        rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

        rootLogger.addAppender(mockedAppender);
    }

    @After
    public void tearDown() throws Exception {
        rootLogger.detachAppender(mockedAppender);
    }


    @Test
    public void testInjectedLogger() throws Exception {
        injectedLogger.info("Just a {}.", "test");

        verify(mockedAppender).doAppend(argumentCaptor.capture());
        assertThat(((LoggingEvent) argumentCaptor.getAllValues().get(0)).getFormattedMessage()).isEqualTo("Just a test.");

    }
}

@@ -26,16 +26,50 @@
 .log;%0A%0A%0A
+import com.google.inject.Inject;%0A%0A
 import o
@@ -88,24 +88,24 @@
 kitoRunner;%0A
-
 import org.j
@@ -337,57 +337,8 @@
 er;%0A
-import ch.qos.logback.classic.spi.ILoggingEvent;%0A
 impo
@@ -481,48 +481,8 @@
 at;%0A
-import static org.mockito.Mockito.mock;%0A
 impo
@@ -803,32 +803,44 @@
 er rootLogger;%0A%0A
+    @Inject%0A
     private Appe
@@ -862,32 +862,11 @@
 nder
- = mock(Appender.class);
+;%0A%0A
 %0A   
@@ -996,81 +996,8 @@
 tUp(
-Appender%3CILoggingEvent%3E appender, ArgumentCaptor%3CAppender%3E argumentCaptor
 ) th
@@ -1093,17 +1093,16 @@
 _NAME);%0A
-%0A
         

Update LoggerTest.java