001package ch.qos.logback.classic.servlet;
002
003import static org.mockito.ArgumentMatchers.any;
004import static org.mockito.Mockito.mock;
005import static org.mockito.Mockito.times;
006import static org.mockito.Mockito.verify;
007import static org.mockito.Mockito.when;
008
009import javax.servlet.ServletContext;
010import javax.servlet.ServletException;
011
012import org.junit.After;
013import org.junit.Before;
014import org.junit.Test;
015
016import ch.qos.logback.core.CoreConstants;
017
018public class LogbackServletContainerInitializerTest {
019
020    LogbackServletContainerInitializer lsci = new LogbackServletContainerInitializer();
021    
022    @Before
023    public void setUp() throws Exception {
024    }
025
026    @After
027    public void tearDown() throws Exception {
028    }
029
030    @Test
031    public void testOnStartup() throws ServletException {
032        ServletContext mockedServletContext = mock(ServletContext.class);
033        lsci.onStartup(null, mockedServletContext);
034        verify(mockedServletContext).addListener(any(LogbackServletContextListener.class));
035    }
036
037    @Test
038    public void noListenerShouldBeAddedWhenDisabled() throws ServletException {
039        ServletContext mockedServletContext = mock(ServletContext.class);
040        when(mockedServletContext.getInitParameter(CoreConstants.DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY)).thenReturn("true");
041        lsci.onStartup(null, mockedServletContext);
042        verify(mockedServletContext, times(0)).addListener(any(LogbackServletContextListener.class));
043    }
044
045}