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.times;
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 log = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    private Appender<ILoggingEvent> mockAppender;
    private ArgumentCaptor<LoggingEvent> captorLoggingEvent;

    @Before
    public void setUp(Appender<ILoggingEvent> appender, ArgumentCaptor<LoggingEvent> captor) throws Exception {
        mockAppender = appender;
        this.captorLoggingEvent = captor;

        log.addAppender(mockAppender);
    }

    @After
    public void tearDown() throws Exception {
        log.detachAppender(mockAppender);
    }


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

        verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture());
        final LoggingEvent loggingEvent = captorLoggingEvent.getValue();
        assertThat(loggingEvent.getFormattedMessage()).isEqualTo("Just a test.");
    }
}
@@ -526,21 +526,20 @@
 Mockito.
-times
+mock
 ;%0Aimport
@@ -857,71 +857,18 @@
 ger 
-log = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)
+rootLogger
 ;%0A%0A 
@@ -890,36 +890,39 @@
 nder
-%3CILoggingEvent%3E
+ mockedAppender =
  mock
+(
 Appender
 ;%0A  
@@ -913,24 +913,31 @@
 ock(Appender
+.class)
 ;%0A    privat
@@ -957,40 +957,74 @@
 tor%3C
-LoggingEvent%3E captorLoggingEvent
+Appender%3E argumentCaptor = ArgumentCaptor.forClass(Appender.class)
 ;%0A%0A 
@@ -1109,23 +1109,27 @@
 tor%3C
-LoggingEvent%3E c
+Appender%3E argumentC
 apto
@@ -1162,73 +1162,78 @@
     
-mockAppender = appender;%0A        this.captorLoggingEvent = captor
+rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)
 ;%0A%0A 
@@ -1239,19 +1239,26 @@
         
-log
+rootLogger
 .addAppe
@@ -1258,32 +1258,34 @@
 addAppender(mock
+ed
 Appender);%0A    %7D
@@ -1351,19 +1351,26 @@
         
-log
+rootLogger
 .detachA
@@ -1377,24 +1377,26 @@
 ppender(mock
+ed
 Appender);%0A 
@@ -1539,24 +1539,26 @@
 ify(mock
+ed
 Appender
 , times(
@@ -1553,18 +1553,8 @@
 nder
-, times(1)
 ).do
@@ -1560,34 +1560,30 @@
 oAppend(
-captorLoggingEvent
+argumentCaptor
 .capture
@@ -1599,104 +1599,72 @@
     
-final LoggingEvent loggingEvent = captorLoggingEvent
+assertThat(((LoggingEvent) argumentCaptor
 .get
+All
 Value
+s
 ()
-;%0A        assertThat(loggingEvent
+.get(0))
 .get
@@ -1714,11 +1714,13 @@
 %22);%0A
+%0A
     %7D%0A%7D
+%0A

Update LoggerTest.java