Browse Source

Add active window manager tests.

pull/127/head
Greg Holmes 9 years ago
parent
commit
18159a072f

+ 58
- 0
activewindow/test/com/dmdirc/addons/activewindow/ActiveWindowManagerTest.java View File

@@ -0,0 +1,58 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.activewindow;
24
+
25
+import com.dmdirc.ui.messages.sink.MessageSinkManager;
26
+
27
+import org.junit.Before;
28
+import org.junit.Test;
29
+import org.junit.runner.RunWith;
30
+import org.mockito.Mock;
31
+import org.mockito.runners.MockitoJUnitRunner;
32
+
33
+import static org.mockito.Mockito.verify;
34
+
35
+@RunWith(MockitoJUnitRunner.class)
36
+public class ActiveWindowManagerTest {
37
+
38
+    @Mock private MessageSinkManager messageSinkManager;
39
+    @Mock private ActiveWindowMessageSink activeWindowMessageSink;
40
+    private ActiveWindowManager activeWindowManager;
41
+
42
+    @Before
43
+    public void setUp() throws Exception {
44
+        activeWindowManager = new ActiveWindowManager(messageSinkManager, activeWindowMessageSink);
45
+    }
46
+
47
+    @Test
48
+    public void testRegister() throws Exception {
49
+        activeWindowManager.register();
50
+        verify(messageSinkManager).addSink(activeWindowMessageSink);
51
+    }
52
+
53
+    @Test
54
+    public void testUnregister() throws Exception {
55
+        activeWindowManager.unregister();
56
+        verify(messageSinkManager).removeSink(activeWindowMessageSink);
57
+    }
58
+}

+ 81
- 0
activewindow/test/com/dmdirc/commandparser/auto/ActiveWindowMessageSinkTest.java View File

@@ -0,0 +1,81 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.commandparser.auto;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.activewindow.ActiveWindowMessageSink;
27
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28
+import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
29
+import com.dmdirc.ui.messages.sink.MessageSinkManager;
30
+
31
+import java.util.Date;
32
+import java.util.Optional;
33
+import java.util.regex.Pattern;
34
+
35
+import org.junit.Before;
36
+import org.junit.Test;
37
+import org.junit.runner.RunWith;
38
+import org.mockito.Mock;
39
+import org.mockito.runners.MockitoJUnitRunner;
40
+
41
+import static junit.framework.TestCase.assertEquals;
42
+import static org.mockito.Mockito.never;
43
+import static org.mockito.Mockito.verify;
44
+import static org.mockito.Mockito.when;
45
+
46
+@RunWith(MockitoJUnitRunner.class)
47
+public class ActiveWindowMessageSinkTest {
48
+
49
+    private static final Pattern PATTERN = Pattern.compile("active");
50
+    @Mock private ActiveFrameManager activeFrameManager;
51
+    @Mock private MessageSinkManager messageSinkManager;
52
+    @Mock private FrameContainer frameContainer;
53
+    @Mock private TextFrame textFrame;
54
+    @Mock private Date date;
55
+    private ActiveWindowMessageSink sink;
56
+
57
+    @Before
58
+    public void setUp() throws Exception {
59
+        sink = new ActiveWindowMessageSink(activeFrameManager);
60
+        when(textFrame.getContainer()).thenReturn(frameContainer);
61
+    }
62
+
63
+    @Test
64
+    public void testGetPattern() throws Exception {
65
+        assertEquals(PATTERN.toString(), sink.getPattern().toString());
66
+    }
67
+
68
+    @Test
69
+    public void testHandleMessage_NoActive() throws Exception {
70
+        when(activeFrameManager.getActiveFrame()).thenReturn(Optional.empty());
71
+        sink.handleMessage(messageSinkManager, frameContainer, null, date, "type", "message");
72
+        verify(frameContainer, never()).addLine("type", date, "message");
73
+    }
74
+
75
+    @Test
76
+    public void testHandleMessage_Active() throws Exception {
77
+        when(activeFrameManager.getActiveFrame()).thenReturn(Optional.of(textFrame));
78
+        sink.handleMessage(messageSinkManager, frameContainer, null, date, "type", "message");
79
+        verify(frameContainer).addLine("type", date, "message");
80
+    }
81
+}

Loading…
Cancel
Save