package com.proofpoint.log;

import org.testng.annotations.Test;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * TODO: test Throwable variations
 */
public class TestLogger
{
    @Test
    public void testDebugFormat()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
        when(mockLogger.isDebugEnabled()).thenReturn(true);

        Logger logger = new Logger(mockLogger);
        logger.debug("hello, %s", "you");

        verify(mockLogger).debug("hello, you");
    }

    @Test
    public void testInfoFormat()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
        when(mockLogger.isInfoEnabled()).thenReturn(true);

        Logger logger = new Logger(mockLogger);
        logger.info("hello, %s", "you");

        verify(mockLogger).info("hello, you");
    }

    @Test
    public void testWarnFormat()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
        when(mockLogger.isWarnEnabled()).thenReturn(true);

        Logger logger = new Logger(mockLogger);
        logger.warn("hello, %s", "you");

        verify(mockLogger).warn("hello, you");
    }

    @Test
    public void testErrorFormat()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);
        when(mockLogger.isErrorEnabled()).thenReturn(true);

        Logger logger = new Logger(mockLogger);
        logger.error("hello, %s", "you");

        verify(mockLogger).error("hello, you");
    }


    @Test
    public void testDebugShortCircuit()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);

        when(mockLogger.isDebugEnabled()).thenReturn(false);

        Logger logger = new Logger(mockLogger);
        logger.debug("hello");

        verify(mockLogger, never()).debug(any(String.class));
        verify(mockLogger, never()).debug(any(String.class), any(Object.class));
        verify(mockLogger, never()).debug(any(String.class), any(Object.class), any(Object.class));
        verify(mockLogger, never()).debug(any(String.class), any(Object[].class));
        verify(mockLogger, never()).debug(any(String.class), any(Throwable.class));
    }

    @Test
    public void testInfoShortCircuit()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);

        when(mockLogger.isInfoEnabled()).thenReturn(false);

        Logger logger = new Logger(mockLogger);
        logger.info("hello");

        verify(mockLogger, never()).info(any(String.class));
        verify(mockLogger, never()).info(any(String.class), any(Object.class));
        verify(mockLogger, never()).info(any(String.class), any(Object.class), any(Object.class));
        verify(mockLogger, never()).info(any(String.class), any(Object[].class));
        verify(mockLogger, never()).info(any(String.class), any(Throwable.class));
    }

    @Test
    public void testWarnShortCircuit()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);

        when(mockLogger.isWarnEnabled()).thenReturn(false);

        Logger logger = new Logger(mockLogger);
        logger.warn("hello");

        verify(mockLogger, never()).warn(any(String.class));
        verify(mockLogger, never()).warn(any(String.class), any(Object.class));
        verify(mockLogger, never()).warn(any(String.class), any(Object.class), any(Object.class));
        verify(mockLogger, never()).warn(any(String.class), any(Object[].class));
        verify(mockLogger, never()).warn(any(String.class), any(Throwable.class));
    }

    @Test
    public void testErrorShortCircuit()
    {
        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);

        when(mockLogger.isErrorEnabled()).thenReturn(false);

        Logger logger = new Logger(mockLogger);
        logger.warn("hello");

        verify(mockLogger, never()).error(any(String.class));
        verify(mockLogger, never()).error(any(String.class), any(Object.class));
        verify(mockLogger, never()).error(any(String.class), any(Object.class), any(Object.class));
        verify(mockLogger, never()).error(any(String.class), any(Object[].class));
        verify(mockLogger, never()).error(any(String.class), any(Throwable.class));
    }
}

@@ -261,16 +261,60 @@
 to.when;
+%0Aimport static org.testng.Assert.assertTrue;
 %0A%0A/**%0A *
@@ -376,16 +376,299 @@
 ogger%0A%7B%0A
+    @Test%0A    public void testIsDebugEnabled()%0A    %7B%0A        org.slf4j.Logger mockLogger = mock(org.slf4j.Logger.class);%0A        when(mockLogger.isDebugEnabled()).thenReturn(true);%0A%0A        Logger logger = new Logger(mockLogger);%0A%0A        assertTrue(logger.isDebugEnabled());%0A    %7D%0A%0A
     @Tes

add test for Logger