1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.logging

File LogQueueTest.java

 

Code metrics

0
58
3
1
125
82
3
0.05
19.33
3
1

Classes

Class Line # Actions
LogQueueTest 38 58 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.logging;
21   
22    import java.util.Arrays;
23   
24    import org.junit.jupiter.api.Test;
25    import org.xwiki.logging.event.LogEvent;
26   
27    import static org.junit.jupiter.api.Assertions.assertEquals;
28    import static org.junit.jupiter.api.Assertions.assertFalse;
29    import static org.junit.jupiter.api.Assertions.assertNotNull;
30    import static org.junit.jupiter.api.Assertions.assertNull;
31    import static org.junit.jupiter.api.Assertions.assertTrue;
32   
33    /**
34    * Test {@link LogQueue}.
35    *
36    * @version $Id: e4dd0387f7479da70f9f4c3c0b99bd7b2d2f8d1b $
37    */
 
38    public class LogQueueTest
39    {
 
40  1 toggle @Test
41    public void error()
42    {
43  1 LogQueue queue = new LogQueue();
44  1 LogEvent logEvent;
45   
46  1 queue.error("");
47  1 logEvent = queue.poll();
48  1 assertEquals(Arrays.asList(""), logEvent.getMessageElements());
49  1 assertEquals("", logEvent.getFormattedMessage());
50   
51  1 queue.error("message");
52  1 assertEquals("message", queue.poll().getFormattedMessage());
53   
54  1 queue.error("message {}", "param");
55  1 assertEquals("message param", queue.poll().getFormattedMessage());
56   
57  1 queue.error("message {} {}", "param1", "param2");
58  1 logEvent = queue.poll();
59  1 assertEquals("message param1 param2", logEvent.getFormattedMessage());
60  1 assertEquals(Arrays.asList("message ", " ", ""), logEvent.getMessageElements());
61  1 assertEquals(Arrays.asList("param1", "param2"), Arrays.asList(logEvent.getArgumentArray()));
62   
63  1 queue.error("message {}", "param1", new Exception());
64  1 logEvent = queue.poll();
65  1 assertEquals("message param1", logEvent.getFormattedMessage());
66  1 assertEquals(Arrays.asList("message ", ""), logEvent.getMessageElements());
67  1 assertEquals(Arrays.asList("param1"), Arrays.asList(logEvent.getArgumentArray()));
68  1 assertNotNull(logEvent.getThrowable());
69  1 assertNull(logEvent.getTranslationKey());
70   
71  1 queue.error("message {}", new Object[] { "param1", new Exception() });
72  1 logEvent = queue.poll();
73  1 assertEquals("message param1", logEvent.getFormattedMessage());
74  1 assertEquals(Arrays.asList("message ", ""), logEvent.getMessageElements());
75  1 assertEquals(Arrays.asList("param1"), Arrays.asList(logEvent.getArgumentArray()));
76  1 assertNotNull(logEvent.getThrowable());
77  1 assertNull(logEvent.getTranslationKey());
78   
79  1 queue.error(new TranslationMarker("translation.key"), "message");
80  1 logEvent = queue.poll();
81  1 assertEquals("translation.key", logEvent.getTranslationKey());
82  1 assertEquals(Arrays.asList("message"), logEvent.getMessageElements());
83  1 assertEquals(Arrays.asList(), Arrays.asList(logEvent.getArgumentArray()));
84    }
85   
 
86  1 toggle @Test
87    public void containLogsFrom()
88    {
89  1 LogQueue queue = new LogQueue();
90   
91  1 assertFalse(queue.containLogsFrom(LogLevel.TRACE));
92  1 assertFalse(queue.containLogsFrom(LogLevel.DEBUG));
93  1 assertFalse(queue.containLogsFrom(LogLevel.INFO));
94  1 assertFalse(queue.containLogsFrom(LogLevel.WARN));
95  1 assertFalse(queue.containLogsFrom(LogLevel.ERROR));
96   
97  1 queue.warn("");
98   
99  1 assertTrue(queue.containLogsFrom(LogLevel.TRACE));
100  1 assertTrue(queue.containLogsFrom(LogLevel.DEBUG));
101  1 assertTrue(queue.containLogsFrom(LogLevel.INFO));
102  1 assertTrue(queue.containLogsFrom(LogLevel.WARN));
103  1 assertFalse(queue.containLogsFrom(LogLevel.ERROR));
104    }
105   
 
106  1 toggle @Test
107    public void getLogsFrom()
108    {
109  1 LogQueue queue = new LogQueue();
110   
111  1 assertTrue(queue.getLogsFrom(LogLevel.TRACE).isEmpty());
112  1 assertTrue(queue.getLogsFrom(LogLevel.DEBUG).isEmpty());
113  1 assertTrue(queue.getLogsFrom(LogLevel.INFO).isEmpty());
114  1 assertTrue(queue.getLogsFrom(LogLevel.WARN).isEmpty());
115  1 assertTrue(queue.getLogsFrom(LogLevel.ERROR).isEmpty());
116   
117  1 queue.warn("");
118   
119  1 assertFalse(queue.getLogsFrom(LogLevel.TRACE).isEmpty());
120  1 assertFalse(queue.getLogsFrom(LogLevel.DEBUG).isEmpty());
121  1 assertFalse(queue.getLogsFrom(LogLevel.INFO).isEmpty());
122  1 assertFalse(queue.getLogsFrom(LogLevel.WARN).isEmpty());
123  1 assertTrue(queue.getLogsFrom(LogLevel.ERROR).isEmpty());
124    }
125    }