|
@@ -0,0 +1,107 @@
|
|
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.DMDircMBassador;
|
|
26
|
+import com.dmdirc.GlobalWindow;
|
|
27
|
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
|
|
28
|
+import com.dmdirc.interfaces.CommandController;
|
|
29
|
+
|
|
30
|
+import com.google.common.base.Optional;
|
|
31
|
+
|
|
32
|
+import org.junit.Before;
|
|
33
|
+import org.junit.Test;
|
|
34
|
+import org.junit.runner.RunWith;
|
|
35
|
+import org.mockito.Mock;
|
|
36
|
+import org.mockito.runners.MockitoJUnitRunner;
|
|
37
|
+
|
|
38
|
+import static junit.framework.TestCase.assertFalse;
|
|
39
|
+import static org.junit.Assert.assertEquals;
|
|
40
|
+import static org.junit.Assert.assertTrue;
|
|
41
|
+
|
|
42
|
+@RunWith(MockitoJUnitRunner.class)
|
|
43
|
+public class AutoCommandManagerTest {
|
|
44
|
+
|
|
45
|
+ @Mock GlobalCommandParser globalCommandParser;
|
|
46
|
+ @Mock GlobalWindow globalWindow;
|
|
47
|
+ @Mock CommandController commandController;
|
|
48
|
+ @Mock DMDircMBassador eventBus;
|
|
49
|
+ private AutoCommandManager autoCommandManager;
|
|
50
|
+
|
|
51
|
+ @Before
|
|
52
|
+ public void setup() {
|
|
53
|
+ final AutoCommandHandlerFactory factory = new AutoCommandHandlerFactory(
|
|
54
|
+ globalCommandParser, globalWindow, commandController);
|
|
55
|
+ autoCommandManager = new AutoCommandManager(eventBus, factory);
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ @Test
|
|
59
|
+ public void testRemoveAutoCommand() {
|
|
60
|
+ final AutoCommand global = new AutoCommand(Optional.<String>absent(),
|
|
61
|
+ Optional.<String>absent(), Optional.<String>absent(), "DO STUFF");
|
|
62
|
+ final AutoCommand connection = new AutoCommand(Optional.<String>absent(),
|
|
63
|
+ Optional.fromNullable("Quakenet"), Optional.<String>absent(), "DO STUFF");
|
|
64
|
+ autoCommandManager.addAutoCommand(global);
|
|
65
|
+ autoCommandManager.addAutoCommand(connection);
|
|
66
|
+ assertEquals(2, autoCommandManager.getAutoCommands().size());
|
|
67
|
+ assertTrue(autoCommandManager.getAutoCommands().contains(connection));
|
|
68
|
+ autoCommandManager.removeAutoCommand(connection);
|
|
69
|
+ assertEquals(1, autoCommandManager.getAutoCommands().size());
|
|
70
|
+ assertFalse(autoCommandManager.getAutoCommands().contains(connection));
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ @Test
|
|
74
|
+ public void testGetAutoCommands() {
|
|
75
|
+ final AutoCommand global = new AutoCommand(Optional.<String>absent(),
|
|
76
|
+ Optional.<String>absent(), Optional.<String>absent(), "DO STUFF");
|
|
77
|
+ final AutoCommand connection = new AutoCommand(Optional.<String>absent(),
|
|
78
|
+ Optional.fromNullable("Quakenet"), Optional.<String>absent(), "DO STUFF");
|
|
79
|
+ autoCommandManager.addAutoCommand(global);
|
|
80
|
+ autoCommandManager.addAutoCommand(connection);
|
|
81
|
+ assertEquals(2, autoCommandManager.getAutoCommands().size());
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ @Test
|
|
85
|
+ public void testGetGlobalAutoCommands() {
|
|
86
|
+ final AutoCommand global = new AutoCommand(Optional.<String>absent(),
|
|
87
|
+ Optional.<String>absent(), Optional.<String>absent(), "DO STUFF");
|
|
88
|
+ final AutoCommand connection = new AutoCommand(Optional.<String>absent(),
|
|
89
|
+ Optional.fromNullable("Quakenet"), Optional.<String>absent(), "DO STUFF");
|
|
90
|
+ autoCommandManager.addAutoCommand(global);
|
|
91
|
+ autoCommandManager.addAutoCommand(connection);
|
|
92
|
+ assertEquals(1, autoCommandManager.getGlobalAutoCommands().size());
|
|
93
|
+ assertTrue(autoCommandManager.getGlobalAutoCommands().contains(global));
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ @Test
|
|
97
|
+ public void testGetConnectionAutoCommands() {
|
|
98
|
+ final AutoCommand global = new AutoCommand(Optional.<String>absent(),
|
|
99
|
+ Optional.<String>absent(), Optional.<String>absent(), "DO STUFF");
|
|
100
|
+ final AutoCommand connection = new AutoCommand(Optional.<String>absent(),
|
|
101
|
+ Optional.fromNullable("Quakenet"), Optional.<String>absent(), "DO STUFF");
|
|
102
|
+ autoCommandManager.addAutoCommand(global);
|
|
103
|
+ autoCommandManager.addAutoCommand(connection);
|
|
104
|
+ assertEquals(1, autoCommandManager.getConnectionAutoCommands().size());
|
|
105
|
+ assertTrue(autoCommandManager.getConnectionAutoCommands().contains(connection));
|
|
106
|
+ }
|
|
107
|
+}
|