|
@@ -0,0 +1,99 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2015 DMDirc Developers
|
|
3
|
+ *
|
|
4
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+ * of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+ * in the Software without restriction, including without limitation the rights
|
|
7
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+ * copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+ * furnished to do so, subject to the following conditions:
|
|
10
|
+ *
|
|
11
|
+ * The above copyright notice and this permission notice shall be included in
|
|
12
|
+ * all copies or substantial portions of the Software.
|
|
13
|
+ *
|
|
14
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+ * SOFTWARE.
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+package com.dmdirc.addons.logging;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.DMDircMBassador;
|
|
26
|
+import com.dmdirc.FrameContainer;
|
|
27
|
+import com.dmdirc.config.ConfigBinder;
|
|
28
|
+import com.dmdirc.events.DisplayPropertyMap;
|
|
29
|
+import com.dmdirc.interfaces.Connection;
|
|
30
|
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
|
31
|
+import com.dmdirc.ui.messages.BackBuffer;
|
|
32
|
+import com.dmdirc.ui.messages.BackBufferFactory;
|
|
33
|
+import com.dmdirc.ui.messages.IRCDocument;
|
|
34
|
+
|
|
35
|
+import java.nio.file.Paths;
|
|
36
|
+import java.text.SimpleDateFormat;
|
|
37
|
+import java.util.Optional;
|
|
38
|
+
|
|
39
|
+import org.junit.Before;
|
|
40
|
+import org.junit.Test;
|
|
41
|
+import org.junit.runner.RunWith;
|
|
42
|
+import org.mockito.InOrder;
|
|
43
|
+import org.mockito.Mock;
|
|
44
|
+import org.mockito.runners.MockitoJUnitRunner;
|
|
45
|
+
|
|
46
|
+import static junit.framework.TestCase.assertEquals;
|
|
47
|
+import static org.mockito.Matchers.any;
|
|
48
|
+import static org.mockito.Matchers.eq;
|
|
49
|
+import static org.mockito.Mockito.inOrder;
|
|
50
|
+import static org.mockito.Mockito.when;
|
|
51
|
+@RunWith(MockitoJUnitRunner.class)
|
|
52
|
+public class HistoryWindowTest {
|
|
53
|
+
|
|
54
|
+ @Mock private IRCDocument document;
|
|
55
|
+ @Mock private BackBuffer backBuffer;
|
|
56
|
+ @Mock private AggregateConfigProvider config;
|
|
57
|
+ @Mock private ConfigBinder configBinder;
|
|
58
|
+ @Mock private Connection connection;
|
|
59
|
+ @Mock private FrameContainer frameContainer;
|
|
60
|
+ @Mock private DMDircMBassador eventBus;
|
|
61
|
+ @Mock private BackBufferFactory backBufferFactory;
|
|
62
|
+ private HistoryWindow instance;
|
|
63
|
+
|
|
64
|
+ @Before
|
|
65
|
+ public void setUp() throws Exception {
|
|
66
|
+ when(backBufferFactory.getBackBuffer(any())).thenReturn(backBuffer);
|
|
67
|
+ when(backBuffer.getDocument()).thenReturn(document);
|
|
68
|
+ when(config.getBinder()).thenReturn(configBinder);
|
|
69
|
+ when(frameContainer.getConfigManager()).thenReturn(config);
|
|
70
|
+ when(frameContainer.getConnection()).thenReturn(Optional.of(connection));
|
|
71
|
+ instance = new HistoryWindow("Awesome",
|
|
72
|
+ Paths.get(getClass().getResource("logfile.txt").toURI()),
|
|
73
|
+ frameContainer, eventBus, backBufferFactory, 4);
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ @Test
|
|
77
|
+ public void testGetConnection() throws Exception {
|
|
78
|
+ assertEquals(Optional.of(connection), instance.getConnection());
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ @Test
|
|
82
|
+ public void testOutputLoggingBackBuffer() throws Exception {
|
|
83
|
+ instance.outputLoggingBackBuffer(4);
|
|
84
|
+ final InOrder inOrder = inOrder(document);
|
|
85
|
+ inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
|
|
86
|
+ .parse("[21/12/2015 13:01:05]").getTime()), eq
|
|
87
|
+ (DisplayPropertyMap.EMPTY), eq("RAAAAAR"));
|
|
88
|
+ inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
|
|
89
|
+ .parse("[21/12/2015 13:00:04]").getTime()), eq
|
|
90
|
+ (DisplayPropertyMap.EMPTY), eq("RAAAAR"));
|
|
91
|
+ inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
|
|
92
|
+ .parse("[21/12/2015 12:59:03]").getTime()), eq
|
|
93
|
+ (DisplayPropertyMap.EMPTY), eq("RAAAR"));
|
|
94
|
+ inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
|
|
95
|
+ .parse("[21/12/2015 12:58:02]").getTime()), eq
|
|
96
|
+ (DisplayPropertyMap.EMPTY), eq("RAAR"));
|
|
97
|
+ inOrder.verifyNoMoreInteractions();
|
|
98
|
+ }
|
|
99
|
+}
|