1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.logging; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
import org.junit.Test; |
26 |
|
import org.xwiki.logging.event.LogEvent; |
27 |
|
|
28 |
|
|
29 |
|
@link |
30 |
|
|
31 |
|
@version |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (61) |
Complexity: 3 |
Complexity Density: 0.05 |
|
33 |
|
public class LogQueueTest |
34 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
35 |
1 |
@Test... |
36 |
|
public void testError() |
37 |
|
{ |
38 |
1 |
LogQueue queue = new LogQueue(); |
39 |
1 |
LogEvent logEvent; |
40 |
|
|
41 |
1 |
queue.error(""); |
42 |
1 |
logEvent = queue.poll(); |
43 |
1 |
Assert.assertEquals(Arrays.asList(""), logEvent.getMessageElements()); |
44 |
1 |
Assert.assertEquals("", logEvent.getFormattedMessage()); |
45 |
|
|
46 |
1 |
queue.error("message"); |
47 |
1 |
Assert.assertEquals("message", queue.poll().getFormattedMessage()); |
48 |
|
|
49 |
1 |
queue.error("message {}", "param"); |
50 |
1 |
Assert.assertEquals("message param", queue.poll().getFormattedMessage()); |
51 |
|
|
52 |
1 |
queue.error("message {} {}", "param1", "param2"); |
53 |
1 |
logEvent = queue.poll(); |
54 |
1 |
Assert.assertEquals("message param1 param2", logEvent.getFormattedMessage()); |
55 |
1 |
Assert.assertEquals(Arrays.asList("message ", " ", ""), logEvent.getMessageElements()); |
56 |
1 |
Assert.assertEquals(Arrays.asList("param1", "param2"), Arrays.asList(logEvent.getArgumentArray())); |
57 |
|
|
58 |
1 |
queue.error("message {}", "param1", new Exception()); |
59 |
1 |
logEvent = queue.poll(); |
60 |
1 |
Assert.assertEquals("message param1", logEvent.getFormattedMessage()); |
61 |
1 |
Assert.assertEquals(Arrays.asList("message ", ""), logEvent.getMessageElements()); |
62 |
1 |
Assert.assertEquals(Arrays.asList("param1"), Arrays.asList(logEvent.getArgumentArray())); |
63 |
1 |
Assert.assertNotNull(logEvent.getThrowable()); |
64 |
1 |
Assert.assertNull(logEvent.getTranslationKey()); |
65 |
|
|
66 |
1 |
queue.error("message {}", new Object[] { "param1", new Exception() }); |
67 |
1 |
logEvent = queue.poll(); |
68 |
1 |
Assert.assertEquals("message param1", logEvent.getFormattedMessage()); |
69 |
1 |
Assert.assertEquals(Arrays.asList("message ", ""), logEvent.getMessageElements()); |
70 |
1 |
Assert.assertEquals(Arrays.asList("param1"), Arrays.asList(logEvent.getArgumentArray())); |
71 |
1 |
Assert.assertNotNull(logEvent.getThrowable()); |
72 |
1 |
Assert.assertNull(logEvent.getTranslationKey()); |
73 |
|
|
74 |
1 |
queue.error(new TranslationMarker("translation.key"), "message"); |
75 |
1 |
logEvent = queue.poll(); |
76 |
1 |
Assert.assertEquals("translation.key", logEvent.getTranslationKey()); |
77 |
1 |
Assert.assertEquals(Arrays.asList("message"), logEvent.getMessageElements()); |
78 |
1 |
Assert.assertEquals(Arrays.asList(), Arrays.asList(logEvent.getArgumentArray())); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void testContainLogsFrom() |
83 |
|
{ |
84 |
1 |
LogQueue queue = new LogQueue(); |
85 |
|
|
86 |
1 |
Assert.assertFalse(queue.containLogsFrom(LogLevel.TRACE)); |
87 |
1 |
Assert.assertFalse(queue.containLogsFrom(LogLevel.DEBUG)); |
88 |
1 |
Assert.assertFalse(queue.containLogsFrom(LogLevel.INFO)); |
89 |
1 |
Assert.assertFalse(queue.containLogsFrom(LogLevel.WARN)); |
90 |
1 |
Assert.assertFalse(queue.containLogsFrom(LogLevel.ERROR)); |
91 |
|
|
92 |
1 |
queue.warn(""); |
93 |
|
|
94 |
1 |
Assert.assertTrue(queue.containLogsFrom(LogLevel.TRACE)); |
95 |
1 |
Assert.assertTrue(queue.containLogsFrom(LogLevel.DEBUG)); |
96 |
1 |
Assert.assertTrue(queue.containLogsFrom(LogLevel.INFO)); |
97 |
1 |
Assert.assertTrue(queue.containLogsFrom(LogLevel.WARN)); |
98 |
1 |
Assert.assertFalse(queue.containLogsFrom(LogLevel.ERROR)); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void testGetLogsFrom() |
103 |
|
{ |
104 |
1 |
LogQueue queue = new LogQueue(); |
105 |
|
|
106 |
1 |
Assert.assertTrue(queue.getLogsFrom(LogLevel.TRACE).isEmpty()); |
107 |
1 |
Assert.assertTrue(queue.getLogsFrom(LogLevel.DEBUG).isEmpty()); |
108 |
1 |
Assert.assertTrue(queue.getLogsFrom(LogLevel.INFO).isEmpty()); |
109 |
1 |
Assert.assertTrue(queue.getLogsFrom(LogLevel.WARN).isEmpty()); |
110 |
1 |
Assert.assertTrue(queue.getLogsFrom(LogLevel.ERROR).isEmpty()); |
111 |
|
|
112 |
1 |
queue.warn(""); |
113 |
|
|
114 |
1 |
Assert.assertFalse(queue.getLogsFrom(LogLevel.TRACE).isEmpty()); |
115 |
1 |
Assert.assertFalse(queue.getLogsFrom(LogLevel.DEBUG).isEmpty()); |
116 |
1 |
Assert.assertFalse(queue.getLogsFrom(LogLevel.INFO).isEmpty()); |
117 |
1 |
Assert.assertFalse(queue.getLogsFrom(LogLevel.WARN).isEmpty()); |
118 |
1 |
Assert.assertTrue(queue.getLogsFrom(LogLevel.ERROR).isEmpty()); |
119 |
|
} |
120 |
|
} |