package com.dwalldorf.timetrack.backend;

import static org.mockito.Mockito.*;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public abstract class BaseTest {

    @Before
    public final void beforeSetUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        this.setUp();
    }

    protected void setUp() {
    }

    protected JoinPoint createJoinPointMock() {
        JoinPoint joinPointMock = Mockito.mock(JoinPoint.class);
        Signature signatureMock = Mockito.mock(Signature.class);

        when(signatureMock.toString()).thenReturn("SomeBean#someMethod");
        when(joinPointMock.getSignature()).thenReturn(signatureMock);

        return joinPointMock;
    }
}
@@ -57,27 +57,326 @@
 org.
-mockito.Mockito.*;%0A
+junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.mockito.Mockito.*;%0A%0Aimport ch.qos.logback.classic.Level;%0Aimport ch.qos.logback.classic.Logger;%0Aimport ch.qos.logback.classic.spi.LoggingEvent;%0Aimport ch.qos.logback.core.Appender;%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0Aimp
@@ -500,16 +500,51 @@
 unWith;%0A
+import org.mockito.ArgumentCaptor;%0A
 import o
@@ -648,16 +648,48 @@
 tRunner;
+%0Aimport org.slf4j.LoggerFactory;
 %0A%0A@RunWi
@@ -759,114 +759,578 @@
     
-@Before%0A    public final void beforeSetUp() throws Exception %7B%0A        MockitoAnnotations.initMocks(this);
+private static final org.slf4j.Logger logger = LoggerFactory.getLogger(BaseTest.class);%0A%0A    private Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);%0A    private Appender mockAppender = spy(Appender.class);%0A%0A    private ArgumentCaptor%3CLoggingEvent%3E loggingEventCaptor = ArgumentCaptor.forClass(LoggingEvent.class);%0A%0A    @Before%0A    public final void beforeSetUp() throws Exception %7B%0A        MockitoAnnotations.initMocks(this);%0A%0A        when(mockAppender.getName()).thenReturn(%22MOCK_APPENDER%22);%0A        rootLogger.addAppender(mockAppender);%0A
 %0A   
@@ -1405,16 +1405,22 @@
 otected 
+final 
 JoinPoin
@@ -1756,10 +1756,1472 @@
 k;%0A    %7D
+%0A%0A    protected final void assertLogged(String message, Level logLevel) %7B%0A        assertLogged(message, logLevel, null);%0A    %7D%0A%0A    protected final void assertLogged(String message, Level logLevel, String markerName) %7B%0A        verify(mockAppender).doAppend(loggingEventCaptor.capture());%0A        List%3CLoggingEvent%3E loggingEvents = getLoggingEvents(message);%0A%0A        if (loggingEvents.size() == 0) %7B%0A            logger.error(%22Wanted: %7B%7D%22, message);%0A            logger.error(%22Found:%22);%0A            for (LoggingEvent loggingEvent : getLoggingEvents(null)) %7B%0A                logger.error(loggingEvent.getFormattedMessage());%0A            %7D%0A        %7D%0A%0A        assertTrue(loggingEvents.size() %3E= 1);%0A        for (LoggingEvent loggingEvent : loggingEvents) %7B%0A            assertEquals(logLevel, loggingEvent.getLevel());%0A%0A            if (markerName != null) %7B%0A                assertEquals(markerName, loggingEvent.getMarker().getName());%0A            %7D%0A        %7D%0A    %7D%0A%0A    private List%3CLoggingEvent%3E getLoggingEvents(String message) %7B%0A        List%3CLoggingEvent%3E allLogMessages = loggingEventCaptor.getAllValues();%0A        if (message == null) %7B%0A            return allLogMessages;%0A        %7D%0A%0A        List%3CLoggingEvent%3E result = new ArrayList%3C%3E();%0A        for (LoggingEvent loggingEvent : allLogMessages) %7B%0A            if (loggingEvent.getFormattedMessage().equals(message)) %7B%0A                result.add(loggingEvent);%0A            %7D%0A        %7D%0A%0A        return result;%0A    %7D
 %0A%7D

add ability to assert logger interaction