Browse Source

Add AutoCommandLifecycleManagerTest.

Change-Id: I6b07117bb136b3817a92cb9c31dfd3222fc52a7c
Reviewed-on: http://gerrit.dmdirc.com/3969
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
pull/1/head
Greg Holmes 9 years ago
parent
commit
47ddc34331

+ 74
- 0
test/com/dmdirc/commandparser/auto/AutoCommandLifecycleManagerTest.java View File

@@ -0,0 +1,74 @@
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.google.common.collect.Sets;
26
+
27
+import java.util.Set;
28
+
29
+import org.junit.Before;
30
+import org.junit.Test;
31
+import org.junit.runner.RunWith;
32
+import org.mockito.Mock;
33
+import org.mockito.runners.MockitoJUnitRunner;
34
+
35
+import static org.mockito.Mockito.verify;
36
+import static org.mockito.Mockito.when;
37
+
38
+@RunWith(MockitoJUnitRunner.class)
39
+public class AutoCommandLifecycleManagerTest {
40
+
41
+    @Mock private AutoCommandManager autoCommandManager;
42
+    @Mock private AutoCommandStore autoCommandStore;
43
+    @Mock private AutoCommand command1;
44
+    @Mock private AutoCommand command2;
45
+    @Mock private AutoCommand command3;
46
+    private AutoCommandLifecycleManager autoCommandLifecycleManager;
47
+    private Set<AutoCommand> getCommands;
48
+
49
+    @Before
50
+    public void setup() {
51
+        autoCommandLifecycleManager = new AutoCommandLifecycleManager(autoCommandManager,
52
+                autoCommandStore);
53
+        getCommands = Sets.newHashSet(command1, command2, command3);
54
+        when(autoCommandStore.readAutoCommands()).thenReturn(
55
+                Sets.newHashSet(command1, command2));
56
+        when(autoCommandManager.getAutoCommands()).thenReturn(getCommands);
57
+    }
58
+
59
+    @Test
60
+    public void testStartUp() {
61
+        autoCommandLifecycleManager.startUp();
62
+        verify(autoCommandStore).readAutoCommands();
63
+        verify(autoCommandManager).addAutoCommand(command1);
64
+        verify(autoCommandManager).addAutoCommand(command2);
65
+        verify(autoCommandManager).start();
66
+    }
67
+
68
+    @Test
69
+    public void testShutDown() {
70
+        autoCommandLifecycleManager.shutDown();
71
+        verify(autoCommandManager).stop();
72
+        verify(autoCommandStore).writeAutoCommands(getCommands);
73
+    }
74
+}

Loading…
Cancel
Save