View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe;
12  
13  import jakarta.servlet.ServletContextEvent;
14  
15  import javax.imageio.ImageIO;
16  
17  import org.junit.jupiter.api.Test;
18  import org.junit.jupiter.api.extension.ExtendWith;
19  import org.mockito.InjectMocks;
20  import org.mockito.Mock;
21  import org.mockito.Mockito;
22  import org.mockito.junit.jupiter.MockitoExtension;
23  
24  /**
25   * The Class AwtAppContextClassloaderListenerTest.
26   */
27  @ExtendWith(MockitoExtension.class)
28  class AwtAppContextClassloaderListenerTest {
29  
30    /** The listener. */
31    @InjectMocks
32    AwtAppContextClassloaderListener listener;
33  
34    /** The event. */
35    @Mock
36    ServletContextEvent event;
37  
38    /** The image IO. */
39    @Mock
40    ImageIO imageIO;
41  
42    /**
43     * Context initialized test.
44     */
45    @Test
46    void contextInitializedTest() {
47      try (var mocked = Mockito.mockStatic(ImageIO.class)) {
48        listener.contextInitialized(event);
49        mocked.verify(() -> ImageIO.getCacheDirectory(), Mockito.times(1));
50      }
51    }
52  
53    /**
54     * Context initialized error test.
55     */
56    @Test
57    void contextInitializedErrorTest() {
58      try (var mocked = Mockito.mockStatic(ImageIO.class)) {
59        mocked.when(ImageIO::getCacheDirectory).thenThrow(new RuntimeException());
60        listener.contextInitialized(event);
61      }
62    }
63  
64    /**
65     * Context destroyed test.
66     */
67    @Test
68    void contextDestroyedTest() {
69      // Dummy Test as method is not implemented
70      listener.contextDestroyed(event);
71    }
72  
73  }