View Javadoc
1   package ch.qos.logback.classic.servlet;
2   
3   import static org.mockito.ArgumentMatchers.any;
4   import static org.mockito.Mockito.mock;
5   import static org.mockito.Mockito.times;
6   import static org.mockito.Mockito.verify;
7   import static org.mockito.Mockito.when;
8   
9   import javax.servlet.ServletContext;
10  import javax.servlet.ServletException;
11  
12  import org.junit.After;
13  import org.junit.Before;
14  import org.junit.Test;
15  
16  import ch.qos.logback.core.CoreConstants;
17  
18  public class LogbackServletContainerInitializerTest {
19  
20      LogbackServletContainerInitializer lsci = new LogbackServletContainerInitializer();
21      
22      @Before
23      public void setUp() throws Exception {
24      }
25  
26      @After
27      public void tearDown() throws Exception {
28      }
29  
30      @Test
31      public void testOnStartup() throws ServletException {
32          ServletContext mockedServletContext = mock(ServletContext.class);
33          lsci.onStartup(null, mockedServletContext);
34          verify(mockedServletContext).addListener(any(LogbackServletContextListener.class));
35      }
36  
37      @Test
38      public void noListenerShouldBeAddedWhenDisabled() throws ServletException {
39          ServletContext mockedServletContext = mock(ServletContext.class);
40          when(mockedServletContext.getInitParameter(CoreConstants.DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY)).thenReturn("true");
41          lsci.onStartup(null, mockedServletContext);
42          verify(mockedServletContext, times(0)).addListener(any(LogbackServletContextListener.class));
43      }
44  
45  }