1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.application

File LogbackLoggerTest.java

 

Code metrics

0
39
14
1
143
109
14
0.36
2.79
14
1

Classes

Class Line # Actions
LogbackLoggerTest 25 39 0% 14 0
1.0100%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    package org.europa.together.application;
2   
3    import java.io.File;
4    import java.io.IOException;
5    import org.europa.together.JUnit5Preperator;
6    import org.europa.together.business.Logger;
7    import org.europa.together.domain.LogLevel;
8    import org.europa.together.service.LoggingService;
9    import org.europa.together.utils.Constraints;
10    import org.junit.jupiter.api.AfterAll;
11    import org.junit.jupiter.api.AfterEach;
12    import static org.junit.jupiter.api.Assertions.*;
13    import org.junit.jupiter.api.Assumptions;
14    import org.junit.jupiter.api.BeforeAll;
15    import org.junit.jupiter.api.BeforeEach;
16    import org.junit.jupiter.api.Test;
17    import org.junit.jupiter.api.extension.ExtendWith;
18    import org.springframework.test.context.ContextConfiguration;
19    import org.springframework.test.context.junit.jupiter.SpringExtension;
20   
21    @SuppressWarnings("unchecked")
22    @ExtendWith({JUnit5Preperator.class})
23    @ExtendWith(SpringExtension.class)
24    @ContextConfiguration(locations = {"/applicationContext.xml"})
 
25    public class LogbackLoggerTest {
26   
27    private static final Logger LOGGER = new LogbackLogger(LogbackLoggerTest.class);
28   
29    //<editor-fold defaultstate="collapsed" desc="Test Preparation">
 
30  1 toggle @BeforeAll
31    static void setUp() {
32  1 Assumptions.assumeTrue(true, "Assumtion failed.");
33   
34  1 LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG);
35    }
36   
 
37  1 toggle @AfterAll
38    static void tearDown() {
39    }
40   
 
41  10 toggle @BeforeEach
42    void testCaseInitialization() {
43    }
44   
 
45  10 toggle @AfterEach
46    void testCaseTermination() {
47    }
48    //</editor-fold>
49   
 
50  1 toggle @Test
51    void constructor() {
52  1 LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG);
53   
54  1 Logger test_01 = new LogbackLogger(Logger.class);
55  1 assertNotNull(test_01);
56    }
57   
 
58  1 toggle @Test
59    void fallbackConstructor() throws IOException {
60  1 LOGGER.log("TEST CASE: fallbackConstructor", LogLevel.DEBUG);
61   
62  1 LoggingService service = new LoggingService();
63  1 service.createLogConfiguration();
64   
65  1 File config = new File(Constraints.SYSTEM_APP_DIR + "/logback.xml");
66  1 assertTrue(config.exists());
67  1 Logger test_02 = new LogbackLogger(Logger.class);
68  1 assertNotNull(test_02);
69   
70    //cleanUp
71  1 config.delete();
72  1 assertFalse(config.exists());
73    }
74   
 
75  1 toggle @Test
76    void failLog() throws Exception {
77  1 LOGGER.log("TEST CASE: faiLog", LogLevel.DEBUG);
78   
79  1 Logger logger = new LogbackLogger(Logger.class);
80  1 assertThrows(Exception.class, () -> {
81  1 logger.log("console logging test: trace", null);
82    });
83    }
84   
 
85  1 toggle @Test
86    void logTrace() {
87  1 LOGGER.log("TEST CASE: logTrace", LogLevel.DEBUG);
88   
89  1 Logger logger = new LogbackLogger(Logger.class);
90  1 assertEquals(LogLevel.TRACE, logger.log("console logging test: trace", LogLevel.TRACE));
91    }
92   
 
93  1 toggle @Test
94    void logDebug() {
95  1 LOGGER.log("TEST CASE: logDebug", LogLevel.DEBUG);
96   
97  1 Logger logger = new LogbackLogger(Logger.class);
98  1 assertEquals(LogLevel.DEBUG, logger.log("console logging test: debug", LogLevel.DEBUG));
99    }
100   
 
101  1 toggle @Test
102    void logInfo() {
103  1 LOGGER.log("TEST CASE: logInfo", LogLevel.DEBUG);
104   
105  1 Logger logger = new LogbackLogger(Logger.class);
106  1 assertEquals(LogLevel.INFO, logger.log("console logging test: info", LogLevel.INFO));
107    }
108   
 
109  1 toggle @Test
110    void logWarn() {
111  1 LOGGER.log("TEST CASE: logWarn", LogLevel.DEBUG);
112   
113  1 Logger logger = new LogbackLogger(Logger.class);
114  1 assertEquals(LogLevel.WARN, logger.log("console logging test: warn", LogLevel.WARN));
115    }
116   
 
117  1 toggle @Test
118    void logError() {
119  1 LOGGER.log("TEST CASE: logError", LogLevel.DEBUG);
120   
121  1 Logger logger = new LogbackLogger(Logger.class);
122  1 assertEquals(LogLevel.ERROR, logger.log("console logging test: error", LogLevel.ERROR));
123    }
124   
 
125  1 toggle @Test
126    void catchException() {
127  1 LOGGER.log("TEST CASE: catchException", LogLevel.DEBUG);
128   
129  1 Logger logger = new LogbackLogger(Logger.class);
130  1 assertEquals("Logging exception test.",
131    logger.catchException(new Exception("Logging exception test.")));
132    }
133   
 
134  1 toggle @Test
135    void catchNullpointerException() {
136  1 LOGGER.log("TEST CASE: catchNullpointerException", LogLevel.DEBUG);
137   
138  1 Logger logger = new LogbackLogger(Logger.class);
139  1 assertEquals("Logging exception test.",
140    logger.catchException(new NullPointerException("Logging exception test.")));
141    }
142   
143    }