Преглед изворни кода

Add the missing files.

pull/340/head
Greg Holmes пре 9 година
родитељ
комит
ac2ba4775a

+ 25
- 0
logging/build.gradle Прегледај датотеку

@@ -0,0 +1,25 @@
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
+dependencies {
24
+    testCompile group: 'com.google.jimfs', name: 'jimfs', version: '1.0'
25
+}

+ 2
- 3
logging/src/com/dmdirc/addons/logging/LoggingManager.java Прегледај датотеку

@@ -102,7 +102,7 @@ public class LoggingManager implements ConfigChangeListener {
102 102
             "EEEE MMMM dd, yyyy - HH:mm:ss");
103 103
     /** Object for synchronising access to the date forma.t */
104 104
     private static final Object FORMAT_LOCK = new Object();
105
-    private static final String timestamp = "[dd/MM/yyyy HH:mm:ss]";
105
+    private static final DateFormat LOG_FORMAT = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]");
106 106
     /** This plugin's plugin info. */
107 107
     private final String domain;
108 108
     private final PluginInfo pluginInfo;
@@ -488,8 +488,7 @@ public class LoggingManager implements ConfigChangeListener {
488 488
         final StringBuilder finalLine = new StringBuilder();
489 489
 
490 490
         if (addtime) {
491
-            final DateFormat dateFormat = new SimpleDateFormat(timestamp);
492
-            final String dateString = dateFormat.format(new Date()).trim();
491
+            final String dateString = LOG_FORMAT.format(new Date()).trim();
493 492
             finalLine.append(dateString);
494 493
             finalLine.append(' ');
495 494
         }

+ 5
- 0
logging/test-res/com/dmdirc/addons/logging/logfile.txt Прегледај датотеку

@@ -0,0 +1,5 @@
1
+[21/12/2015 12:57:01] RAR
2
+[21/12/2015 12:58:02] RAAR
3
+[21/12/2015 12:59:03] RAAAR
4
+[21/12/2015 13:00:04] RAAAAR
5
+[21/12/2015 13:01:05] RAAAAAR

+ 99
- 0
logging/test/com/dmdirc/addons/logging/HistoryWindowTest.java Прегледај датотеку

@@ -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
+}

Loading…
Откажи
Сачувај