1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.logging

File LogQueueTest.java

 

Code metrics

0
58
3
1
120
78
3
0.05
19.33
3
1

Classes

Class Line # Actions
LogQueueTest 33 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.Assert;
25    import org.junit.Test;
26    import org.xwiki.logging.event.LogEvent;
27   
28    /**
29    * Test {@link LogQueue}.
30    *
31    * @version $Id: 11805c0b71a5520c5b8d16b1cb7d0574e89619d2 $
32    */
 
33    public class LogQueueTest
34    {
 
35  1 toggle @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   
 
81  1 toggle @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   
 
101  1 toggle @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    }