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 jakarta.servlet.ServletContext;
10 import jakarta.servlet.ServletException;
11
12 import org.junit.jupiter.api.AfterEach;
13 import org.junit.jupiter.api.BeforeEach;
14
15 import ch.qos.logback.core.CoreConstants;
16 import org.junit.jupiter.api.Test;
17
18 public class LogbackServletContainerInitializerTest {
19
20 LogbackServletContainerInitializer lsci = new LogbackServletContainerInitializer();
21
22 @BeforeEach
23 public void setUp() throws Exception {
24 }
25
26 @AfterEach
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))
41 .thenReturn("true");
42 lsci.onStartup(null, mockedServletContext);
43 verify(mockedServletContext, times(0)).addListener(any(LogbackServletContextListener.class));
44 }
45
46 }