|
@@ -1,124 +0,0 @@
|
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.actions.wrappers;
|
24
|
|
-
|
25
|
|
-import com.dmdirc.actions.Action;
|
26
|
|
-import com.dmdirc.actions.ActionCondition;
|
27
|
|
-import com.dmdirc.actions.CoreActionComparison;
|
28
|
|
-import com.dmdirc.actions.CoreActionComponent;
|
29
|
|
-import com.dmdirc.actions.CoreActionType;
|
30
|
|
-import com.dmdirc.interfaces.CommandController;
|
31
|
|
-import com.dmdirc.interfaces.actions.ActionType;
|
32
|
|
-import com.dmdirc.logger.ErrorManager;
|
33
|
|
-import com.dmdirc.logger.Logger;
|
34
|
|
-import com.dmdirc.ui.WindowManager;
|
35
|
|
-
|
36
|
|
-import java.util.ArrayList;
|
37
|
|
-import java.util.List;
|
38
|
|
-
|
39
|
|
-import org.junit.Before;
|
40
|
|
-import org.junit.BeforeClass;
|
41
|
|
-import org.junit.Test;
|
42
|
|
-import org.junit.runner.RunWith;
|
43
|
|
-import org.mockito.Mock;
|
44
|
|
-import org.mockito.runners.MockitoJUnitRunner;
|
45
|
|
-
|
46
|
|
-import static org.junit.Assert.*;
|
47
|
|
-import static org.mockito.Mockito.*;
|
48
|
|
-
|
49
|
|
-@RunWith(MockitoJUnitRunner.class)
|
50
|
|
-public class AliasWrapperTest {
|
51
|
|
-
|
52
|
|
- @Mock private Action action;
|
53
|
|
- @Mock private ActionCondition condition;
|
54
|
|
- @Mock private WindowManager windowManager;
|
55
|
|
- @Mock private CommandController commandController;
|
56
|
|
- private List<ActionCondition> conditions;
|
57
|
|
-
|
58
|
|
- private AliasWrapper aliasWrapper;
|
59
|
|
-
|
60
|
|
- @BeforeClass
|
61
|
|
- public static void overrideLogger() {
|
62
|
|
- // We expect errors to be generated, so mock out the error manager.
|
63
|
|
- Logger.setErrorManager(mock(ErrorManager.class));
|
64
|
|
- }
|
65
|
|
-
|
66
|
|
- @Before
|
67
|
|
- public void setup() {
|
68
|
|
- when(commandController.getCommandChar()).thenReturn('!');
|
69
|
|
-
|
70
|
|
- conditions = new ArrayList<>();
|
71
|
|
- aliasWrapper = new AliasWrapper(commandController, windowManager);
|
72
|
|
-
|
73
|
|
- when(condition.getArg()).thenReturn(1);
|
74
|
|
- when(condition.getComparison()).thenReturn(CoreActionComparison.STRING_EQUALS);
|
75
|
|
- when(condition.getComponent()).thenReturn(CoreActionComponent.STRING_STRING);
|
76
|
|
- when(condition.getTarget()).thenReturn("name");
|
77
|
|
- when(action.getConditions()).thenReturn(conditions);
|
78
|
|
- when(action.getTriggers()).thenReturn(new ActionType[] { CoreActionType.UNKNOWN_COMMAND });
|
79
|
|
- }
|
80
|
|
-
|
81
|
|
- @Test
|
82
|
|
- public void testAddsAlias() {
|
83
|
|
- conditions.add(condition);
|
84
|
|
-
|
85
|
|
- aliasWrapper.add(action);
|
86
|
|
- assertFalse(aliasWrapper.getAliases().isEmpty());
|
87
|
|
- }
|
88
|
|
-
|
89
|
|
- @Test
|
90
|
|
- public void testDoesNotAddActionWithNoConditions() {
|
91
|
|
- aliasWrapper.add(action);
|
92
|
|
- assertTrue(aliasWrapper.getAliases().isEmpty());
|
93
|
|
- }
|
94
|
|
-
|
95
|
|
- @Test
|
96
|
|
- public void testDoesNotAddActionWithWrongTrigger() {
|
97
|
|
- when(action.getTriggers()).thenReturn(new ActionType[] { CoreActionType.ACTION_CREATED });
|
98
|
|
-
|
99
|
|
- aliasWrapper.add(action);
|
100
|
|
- assertTrue(aliasWrapper.getAliases().isEmpty());
|
101
|
|
- }
|
102
|
|
-
|
103
|
|
- @Test
|
104
|
|
- public void testGetsCommandName() {
|
105
|
|
- conditions.add(condition);
|
106
|
|
- assertEquals("!name", aliasWrapper.getCommandName(action));
|
107
|
|
- }
|
108
|
|
-
|
109
|
|
- @Test
|
110
|
|
- public void testGetsCommandNameWithMultipleConditions() {
|
111
|
|
- final ActionCondition otherCondition = mock(ActionCondition.class);
|
112
|
|
- when(otherCondition.getArg()).thenReturn(7);
|
113
|
|
-
|
114
|
|
- conditions.add(otherCondition);
|
115
|
|
- conditions.add(condition);
|
116
|
|
- assertEquals("!name", aliasWrapper.getCommandName(action));
|
117
|
|
- }
|
118
|
|
-
|
119
|
|
- @Test
|
120
|
|
- public void testGetCommandNameReturnsNullIfUnknown() {
|
121
|
|
- assertNull(aliasWrapper.getCommandName(action));
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
-}
|