Переглянути джерело

Commands clean up

Reduce dependency on CommandManager singleton
Use Lombok and delete loads of boilerplate code

Change-Id: Id178d20df1838eef99abdc0c3ca12b6dbd2a062f
Reviewed-on: http://gerrit.dmdirc.com/2310
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.6.7rc1
Chris Smith 12 роки тому
джерело
коміт
a9631ebf02

+ 7
- 33
src/com/dmdirc/commandparser/BaseCommandInfo.java Переглянути файл

@@ -22,51 +22,25 @@
22 22
 
23 23
 package com.dmdirc.commandparser;
24 24
 
25
+import lombok.Getter;
26
+import lombok.RequiredArgsConstructor;
27
+
25 28
 /**
26 29
  * A basic {@link CommandInfo} implementation whose parameters can be
27 30
  * configured via the constructor.
28 31
  */
32
+@Getter
33
+@RequiredArgsConstructor
34
+@SuppressWarnings("PMD.UnusedPrivateField")
29 35
 public class BaseCommandInfo implements CommandInfo {
30 36
 
31 37
     /** The name of the command. */
32 38
     private final String name;
33 39
 
34 40
     /** The help text for this command. */
35
-    private final String helpText;
41
+    private final String help;
36 42
 
37 43
     /** The type of the command. */
38 44
     private final CommandType type;
39 45
 
40
-    /**
41
-     * Creates a new BaseCommandInfo with the specified information.
42
-     *
43
-     * @param name The name of the command
44
-     * @param helpText The help text for this command
45
-     * @param type The type of the command
46
-     */
47
-    public BaseCommandInfo(final String name, final String helpText,
48
-            final CommandType type) {
49
-        this.name = name;
50
-        this.helpText = helpText;
51
-        this.type = type;
52
-    }
53
-
54
-    /** {@inheritDoc} */
55
-    @Override
56
-    public String getName() {
57
-        return name;
58
-    }
59
-
60
-    /** {@inheritDoc} */
61
-    @Override
62
-    public String getHelp() {
63
-        return helpText;
64
-    }
65
-
66
-    /** {@inheritDoc} */
67
-    @Override
68
-    public CommandType getType() {
69
-        return type;
70
-    }
71
-
72 46
 }

+ 33
- 3
src/com/dmdirc/commandparser/CommandArguments.java Переглянути файл

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.commandparser;
24 24
 
25 25
 import com.dmdirc.Precondition;
26
+import com.dmdirc.interfaces.CommandController;
26 27
 import com.dmdirc.logger.Logger;
27 28
 
28 29
 import java.util.Arrays;
@@ -46,22 +47,51 @@ public class CommandArguments {
46 47
     /** The line split into whitespace-delimited words. */
47 48
     private String[] words;
48 49
 
50
+    /** Command controller to consult for command chars, etc. */
51
+    private final CommandController controller;
52
+
49 53
     /**
50 54
      * Creates a new command arguments parser for the specified line.
51 55
      *
52 56
      * @param line The line to be parsed
53 57
      */
54 58
     public CommandArguments(final String line) {
55
-        this.line = line;
59
+        this(CommandManager.getCommandManager(), line);
56 60
     }
57 61
 
58 62
     /**
63
+     * Creates a new command arguments parser for the specified line.
64
+     *
65
+     * @param controller The command controller to consult for information
66
+     * about command characters, etc.
67
+     * @param line The line to be parsed
68
+     * @since 0.6.7
69
+     */
70
+    public CommandArguments(final CommandController controller, final String line) {
71
+        this.controller = controller;
72
+        this.line = line;
73
+    }
74
+
75
+   /**
59 76
      * Creates a new command arguments parser for the specified words.
60 77
      *
61 78
      * @param words The words which form the line ot be parsed
62 79
      * @since 0.6.3
63 80
      */
64 81
     public CommandArguments(final Collection<String> words) {
82
+        this(CommandManager.getCommandManager(), words);
83
+    }
84
+
85
+    /**
86
+     * Creates a new command arguments parser for the specified words.
87
+     *
88
+     * @param controller The command controller to consult for information
89
+     * about command characters, etc.
90
+     * @param words The words which form the line ot be parsed
91
+     * @since 0.6.7
92
+     */
93
+    public CommandArguments(final CommandController controller, final Collection<String> words) {
94
+        this.controller = controller;
65 95
         this.words = words.toArray(new String[words.size()]);
66 96
 
67 97
         final StringBuilder builder = new StringBuilder();
@@ -208,7 +238,7 @@ public class CommandArguments {
208 238
      * @return True if the input was a command, false otherwise
209 239
      */
210 240
     public boolean isCommand() {
211
-        return !line.isEmpty() && line.charAt(0) == CommandManager.getCommandManager().getCommandChar();
241
+        return !line.isEmpty() && line.charAt(0) == controller.getCommandChar();
212 242
     }
213 243
 
214 244
     /**
@@ -218,7 +248,7 @@ public class CommandArguments {
218 248
      */
219 249
     public boolean isSilent() {
220 250
         return isCommand() && line.length() >= 2
221
-                && line.charAt(1) == CommandManager.getCommandManager().getSilenceChar();
251
+                && line.charAt(1) == controller.getSilenceChar();
222 252
     }
223 253
 
224 254
     /**

+ 7
- 29
src/com/dmdirc/commandparser/CommandInfoPair.java Переглянути файл

@@ -24,46 +24,24 @@ package com.dmdirc.commandparser;
24 24
 
25 25
 import com.dmdirc.commandparser.commands.Command;
26 26
 
27
+import lombok.Getter;
28
+import lombok.RequiredArgsConstructor;
29
+
27 30
 /**
28 31
  * A combination of a {@link Command} and the {@link CommandInfo} which
29 32
  * triggered it.
30 33
  *
31 34
  * @since 0.6.4
32 35
  */
36
+@RequiredArgsConstructor
37
+@Getter
38
+@SuppressWarnings("PMD.UnusedPrivateField")
33 39
 public class CommandInfoPair {
34 40
 
35 41
     /** The command info which caused the command to be triggered. */
36 42
     private final CommandInfo commandInfo;
43
+
37 44
     /** The command in question. */
38 45
     private final Command command;
39 46
 
40
-    /**
41
-     * Creates a new CommandInfoPair.
42
-     *
43
-     * @param commandInfo The command info associated with the command
44
-     * @param command The command
45
-     */
46
-    public CommandInfoPair(final CommandInfo commandInfo, final Command command) {
47
-        this.commandInfo = commandInfo;
48
-        this.command = command;
49
-    }
50
-
51
-    /**
52
-     * Retrieves the command part of this pair.
53
-     *
54
-     * @return This pair's command
55
-     */
56
-    public Command getCommand() {
57
-        return command;
58
-    }
59
-
60
-    /**
61
-     * Retrieves the commandinfo part of this pair.
62
-     *
63
-     * @return This pair's commandinfo
64
-     */
65
-    public CommandInfo getCommandInfo() {
66
-        return commandInfo;
67
-    }
68
-
69 47
 }

+ 19
- 1
src/com/dmdirc/commandparser/commands/Command.java Переглянути файл

@@ -26,11 +26,17 @@ import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandManager;
28 28
 import com.dmdirc.commandparser.commands.context.CommandContext;
29
+import com.dmdirc.interfaces.CommandController;
29 30
 import com.dmdirc.ui.messages.Styliser;
30 31
 
32
+import lombok.AccessLevel;
33
+import lombok.Getter;
34
+import lombok.RequiredArgsConstructor;
35
+
31 36
 /**
32 37
  * Represents a generic command.
33 38
  */
39
+@RequiredArgsConstructor
34 40
 public abstract class Command {
35 41
 
36 42
     /** The format name used for command output. */
@@ -39,6 +45,18 @@ public abstract class Command {
39 45
     /** The format name used for command errors. */
40 46
     protected static final String FORMAT_ERROR = "commandError";
41 47
 
48
+    /** The controller this command is associated with. */
49
+    @Getter(AccessLevel.PROTECTED)
50
+    private final CommandController controller;
51
+
52
+    /**
53
+     * Creates a new instance of Command using the default CommandManager
54
+     * provided by {@link CommandManager#getCommandManager()}.
55
+     */
56
+    public Command() {
57
+        this(CommandManager.getCommandManager());
58
+    }
59
+
42 60
     /**
43 61
      * Sends a line, if appropriate, to the specified target.
44 62
      * @param target The command window to send the line to
@@ -64,7 +82,7 @@ public abstract class Command {
64 82
     protected final void showUsage(final FrameContainer target,
65 83
             final boolean isSilent, final String name, final String args) {
66 84
         sendLine(target, isSilent, "commandUsage",
67
-                CommandManager.getCommandManager().getCommandChar(),
85
+                controller.getCommandChar(),
68 86
                 name, args);
69 87
     }
70 88
 

+ 6
- 40
src/com/dmdirc/commandparser/commands/IntelligentCommand.java Переглянути файл

@@ -27,6 +27,9 @@ import com.dmdirc.ui.input.AdditionalTabTargets;
27 27
 
28 28
 import java.util.List;
29 29
 
30
+import lombok.Getter;
31
+import lombok.RequiredArgsConstructor;
32
+
30 33
 /**
31 34
  * Intelligent commands implement a method that provides a list of possible
32 35
  * options for them, for use (for example) by table completers.
@@ -49,6 +52,9 @@ public interface IntelligentCommand {
49 52
      *
50 53
      * @since 0.6.4
51 54
      */
55
+    @RequiredArgsConstructor
56
+    @Getter
57
+    @SuppressWarnings("PMD.UnusedPrivateField")
52 58
     class IntelligentCommandContext {
53 59
 
54 60
         /** The window the command is being entered in. */
@@ -60,45 +66,5 @@ public interface IntelligentCommand {
60 66
         /** The partially typed word, if any. */
61 67
         private final String partial;
62 68
 
63
-        /**
64
-         * Creates a new context with the specified arguments.
65
-         *
66
-         * @param window The window the command is being entered in
67
-         * @param previousArgs The previously supplied arguments, if any
68
-         * @param partial The partially-typed word being completed
69
-         */
70
-        public IntelligentCommandContext(final WritableFrameContainer window,
71
-                final List<String> previousArgs, final String partial) {
72
-            this.window = window;
73
-            this.previousArgs = previousArgs;
74
-            this.partial = partial;
75
-        }
76
-
77
-        /**
78
-         * Retrieves the window that the command was entered in.
79
-         *
80
-         * @return The command's input window
81
-         */
82
-        public WritableFrameContainer getWindow() {
83
-            return window;
84
-        }
85
-
86
-        /**
87
-         * Retrieves the previously supplied arguments.
88
-         *
89
-         * @return Any arguments supplied prior to the current one
90
-         */
91
-        public List<String> getPreviousArgs() {
92
-            return previousArgs;
93
-        }
94
-
95
-        /**
96
-         * Retrieves the partially typed word which is being completed.
97
-         *
98
-         * @return The partial word being completed
99
-         */
100
-        public String getPartial() {
101
-            return partial;
102
-        }
103 69
     }
104 70
 }

+ 9
- 57
src/com/dmdirc/commandparser/commands/PreviousCommand.java Переглянути файл

@@ -24,71 +24,23 @@ package com.dmdirc.commandparser.commands;
24 24
 
25 25
 import java.util.Date;
26 26
 
27
+import lombok.EqualsAndHashCode;
28
+import lombok.Getter;
29
+import lombok.RequiredArgsConstructor;
30
+
27 31
 /**
28 32
  * Stores information about a previously executed command.
29 33
  */
34
+@RequiredArgsConstructor
35
+@EqualsAndHashCode
36
+@Getter
37
+@SuppressWarnings("PMD.UnusedPrivateField")
30 38
 public final class PreviousCommand {
31 39
 
32 40
     /** The full command that was executed. */
33 41
     private final String line;
34 42
 
35 43
     /** The timestamp of its execution. */
36
-    private final long time;
37
-
38
-    /**
39
-     * Creates a new record of the specified command.
40
-     *
41
-     * @param line The full command that was executed
42
-     */
43
-    public PreviousCommand(final String line) {
44
-        this.line = line;
45
-        this.time = new Date().getTime();
46
-    }
47
-
48
-    /**
49
-     * Retrieves the time that the command was executed at.
50
-     *
51
-     * @return The timestamp that the command was executed at
52
-     */
53
-    public long getTime() {
54
-        return time;
55
-    }
56
-
57
-    /**
58
-     * Retrieves the command that was executed.
59
-     *
60
-     * @return The command that was executed.
61
-     */
62
-    public String getLine() {
63
-        return line;
64
-    }
65
-
66
-    /** {@inheritDoc} */
67
-    @Override
68
-    public boolean equals(final Object obj) {
69
-        if (obj == null) {
70
-            return false;
71
-        }
72
-
73
-        if (getClass() != obj.getClass()) {
74
-            return false;
75
-        }
76
-
77
-        final PreviousCommand other = (PreviousCommand) obj;
78
-        if (this.line != other.line
79
-                && (this.line == null || !this.line.equals(other.line))) {
80
-            return false;
81
-        }
82
-
83
-        return true;
84
-    }
85
-
86
-    /** {@inheritDoc} */
87
-    @Override
88
-    public int hashCode() {
89
-        int hash = 5;
90
-        hash = 97 * hash + (this.line == null ? 0 : this.line.hashCode());
91
-        return hash;
92
-    }
44
+    private final long time = new Date().getTime();
93 45
 
94 46
 }

+ 2
- 3
src/com/dmdirc/commandparser/commands/global/AliasCommand.java Переглянути файл

@@ -30,7 +30,6 @@ import com.dmdirc.actions.wrappers.AliasWrapper;
30 30
 import com.dmdirc.commandparser.BaseCommandInfo;
31 31
 import com.dmdirc.commandparser.CommandArguments;
32 32
 import com.dmdirc.commandparser.CommandInfo;
33
-import com.dmdirc.commandparser.CommandManager;
34 33
 import com.dmdirc.commandparser.CommandType;
35 34
 import com.dmdirc.commandparser.commands.Command;
36 35
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -60,7 +59,7 @@ public class AliasCommand extends Command implements IntelligentCommand {
60 59
         if (args.getArguments()[0].equalsIgnoreCase("--remove")) {
61 60
             final String name
62 61
                     = args.getArguments()[1].charAt(0)
63
-                    == CommandManager.getCommandManager().getCommandChar()
62
+                    == getController().getCommandChar()
64 63
                     ? args.getArguments()[1].substring(1) : args.getArguments()[1];
65 64
 
66 65
             if (doRemove(name)) {
@@ -75,7 +74,7 @@ public class AliasCommand extends Command implements IntelligentCommand {
75 74
         }
76 75
 
77 76
         final String name = args.getArguments()[0].charAt(0)
78
-                == CommandManager.getCommandManager().getCommandChar()
77
+                == getController().getCommandChar()
79 78
                 ? args.getArguments()[0].substring(1) : args.getArguments()[0];
80 79
 
81 80
         for (Action alias : AliasWrapper.getAliasWrapper()) {

+ 3
- 5
src/com/dmdirc/commandparser/commands/global/Help.java Переглянути файл

@@ -27,7 +27,6 @@ import com.dmdirc.WritableFrameContainer;
27 27
 import com.dmdirc.commandparser.BaseCommandInfo;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.CommandInfo;
30
-import com.dmdirc.commandparser.CommandManager;
31 30
 import com.dmdirc.commandparser.CommandType;
32 31
 import com.dmdirc.commandparser.commands.Command;
33 32
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -111,11 +110,10 @@ public class Help extends Command implements IntelligentCommand {
111 110
             final String name) {
112 111
         Map.Entry<CommandInfo, Command> command = null;
113 112
 
114
-        if (name.length() > 0 && name.charAt(0)
115
-                == CommandManager.getCommandManager().getCommandChar()) {
116
-            command = CommandManager.getCommandManager().getCommand(name.substring(1));
113
+        if (name.length() > 0 && name.charAt(0) == getController().getCommandChar()) {
114
+            command = getController().getCommand(name.substring(1));
117 115
         } else {
118
-            command = CommandManager.getCommandManager().getCommand(name);
116
+            command = getController().getCommand(name);
119 117
         }
120 118
 
121 119
         if (command == null) {

+ 1
- 2
src/com/dmdirc/commandparser/commands/global/Set.java Переглянути файл

@@ -27,7 +27,6 @@ import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.commandparser.BaseCommandInfo;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.CommandInfo;
30
-import com.dmdirc.commandparser.CommandManager;
31 30
 import com.dmdirc.commandparser.CommandType;
32 31
 import com.dmdirc.commandparser.commands.Command;
33 32
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -163,7 +162,7 @@ public class Set extends Command implements IntelligentCommand {
163 162
         final StringBuffer output = new StringBuffer(67);
164 163
 
165 164
         output.append("Valid domains (use ");
166
-        output.append(CommandManager.getCommandManager().getCommandChar());
165
+        output.append(getController().getCommandChar());
167 166
         output.append("set <domain> to see options within a domain): ");
168 167
 
169 168
         for (String domain : manager.getDomains()) {

+ 1
- 2
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Переглянути файл

@@ -29,7 +29,6 @@ import com.dmdirc.WritableFrameContainer;
29 29
 import com.dmdirc.commandparser.BaseCommandInfo;
30 30
 import com.dmdirc.commandparser.CommandArguments;
31 31
 import com.dmdirc.commandparser.CommandInfo;
32
-import com.dmdirc.commandparser.CommandManager;
33 32
 import com.dmdirc.commandparser.CommandType;
34 33
 import com.dmdirc.commandparser.commands.Command;
35 34
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -65,7 +64,7 @@ public class OpenQuery extends Command implements IntelligentCommand,
65 64
             sendLine(origin, args.isSilent(), FORMAT_ERROR, "You can't open a query "
66 65
                     + "with a channel; maybe you meant " + Styliser.CODE_FIXED
67 66
                     + Styliser.CODE_BOLD
68
-                    + CommandManager.getCommandManager().getCommandChar()
67
+                    + getController().getCommandChar()
69 68
                     + (args.getArguments().length > 1 ? "msg" : "join") + " "
70 69
                     + args.getArgumentsAsString()
71 70
                     + Styliser.CODE_BOLD + Styliser.CODE_FIXED + "?");

+ 15
- 4
src/com/dmdirc/commandparser/validators/CommandNameValidator.java Переглянути файл

@@ -36,14 +36,25 @@ import java.util.regex.Pattern;
36 36
 public class CommandNameValidator extends ValidatorChain<String> {
37 37
 
38 38
     /**
39
-     * Instantiates a new command name validator.
39
+     * Instantiates a new command name validator, using the command char
40
+     * provided by the default Command Manager.
40 41
      */
41
-    @SuppressWarnings("unchecked")
42 42
     public CommandNameValidator() {
43
+        this(CommandManager.getCommandManager().getCommandChar());
44
+    }
45
+
46
+    /**
47
+     * Instantiates a new command name validator using the given command char.
48
+     *
49
+     * @param commandChar the character commands start with (which is therefore
50
+     * disallowed at the start of a command name).
51
+     */
52
+    @SuppressWarnings("unchecked")
53
+    public CommandNameValidator(final char commandChar) {
43 54
         super(new RegexStringValidator("^[^\\s]*$", "Cannot contain spaces"),
44 55
                 new RegexStringValidator("^[^"
45
-                + Pattern.quote(String.valueOf(CommandManager.getCommandManager().getCommandChar()))
46
-                + "].*$", "Cannot start with a " + CommandManager.getCommandManager().getCommandChar()));
56
+                + Pattern.quote(String.valueOf(commandChar))
57
+                + "].*$", "Cannot start with a " + commandChar));
47 58
     }
48 59
 
49 60
 }

+ 39
- 35
test/com/dmdirc/commandparser/CommandArgumentsTest.java Переглянути файл

@@ -22,43 +22,47 @@
22 22
 
23 23
 package com.dmdirc.commandparser;
24 24
 
25
-import com.dmdirc.config.IdentityManager;
26
-import com.dmdirc.config.InvalidIdentityFileException;
25
+import com.dmdirc.interfaces.CommandController;
27 26
 
28 27
 import java.util.Arrays;
29 28
 
30
-import org.junit.BeforeClass;
29
+import org.junit.Before;
31 30
 import org.junit.Test;
32 31
 
33 32
 import static org.junit.Assert.*;
33
+import static org.mockito.Mockito.*;
34 34
 
35 35
 public class CommandArgumentsTest {
36 36
 
37
-    @BeforeClass
38
-    public static void beforeClass() throws InvalidIdentityFileException {
39
-        IdentityManager.getIdentityManager().initialise();
37
+    private CommandController controller;
38
+
39
+    @Before
40
+    public void setUp() {
41
+        this.controller = mock(CommandController.class);
42
+        when(this.controller.getCommandChar()).thenReturn('/');
43
+        when(this.controller.getSilenceChar()).thenReturn('.');
40 44
     }
41 45
 
42 46
     /** Ensures the ctor which takes a collection builds the 'line' property. */
43 47
     @Test
44 48
     public void testCollectionCtorCreatesLine() {
45
-        final CommandArguments args = new CommandArguments(Arrays.asList(
46
-                "/command", "arg1", "arg2"));
49
+        final CommandArguments args = new CommandArguments(controller,
50
+                Arrays.asList("/command", "arg1", "arg2"));
47 51
         assertEquals("/command arg1 arg2", args.getLine());
48 52
     }
49 53
 
50 54
     /** Ensures the ctor works with an empty collection. */
51 55
     @Test
52 56
     public void testCollectionCtorWithEmpty() {
53
-        final CommandArguments args = new CommandArguments(Arrays.asList(
54
-                new String[0]));
57
+        final CommandArguments args = new CommandArguments(
58
+                controller, Arrays.asList(new String[0]));
55 59
         assertEquals("", args.getLine());
56 60
     }
57 61
 
58 62
     /** Ensures that getStrippedLine returns non-command lines as-is. */
59 63
     @Test
60 64
     public void testGetStrippedLineNormal() {
61
-        final CommandArguments args = new CommandArguments("blah blah");
65
+        final CommandArguments args = new CommandArguments(controller, "blah blah");
62 66
         assertEquals("blah blah", args.getStrippedLine());
63 67
     }
64 68
 
@@ -68,7 +72,7 @@ public class CommandArgumentsTest {
68 72
      */
69 73
     @Test
70 74
     public void testGetStrippedLineCommand() {
71
-        final CommandArguments args = new CommandArguments("/blah blah");
75
+        final CommandArguments args = new CommandArguments(controller, "/blah blah");
72 76
         assertEquals("blah blah", args.getStrippedLine());
73 77
     }
74 78
 
@@ -78,41 +82,41 @@ public class CommandArgumentsTest {
78 82
      */
79 83
     @Test
80 84
     public void testGetStrippedLineSilenced() {
81
-        final CommandArguments args = new CommandArguments("/.blah blah");
85
+        final CommandArguments args = new CommandArguments(controller, "/.blah blah");
82 86
         assertEquals("blah blah", args.getStrippedLine());
83 87
     }
84 88
 
85 89
     @Test
86 90
     public void testIsCommand() {
87
-        assertTrue(new CommandArguments(CommandManager.getCommandManager().getCommandChar() + "").isCommand());
88
-        assertTrue(new CommandArguments(CommandManager.getCommandManager().getCommandChar() + "foo bar").isCommand());
89
-        assertFalse(new CommandArguments(" " + CommandManager.getCommandManager().getCommandChar()).isCommand());
90
-        assertFalse(new CommandArguments("").isCommand());
91
-        assertFalse(new CommandArguments("foo").isCommand());
91
+        assertTrue(new CommandArguments(controller, "/").isCommand());
92
+        assertTrue(new CommandArguments(controller, "/foo bar").isCommand());
93
+        assertFalse(new CommandArguments(controller, " /").isCommand());
94
+        assertFalse(new CommandArguments(controller, "").isCommand());
95
+        assertFalse(new CommandArguments(controller, "foo").isCommand());
92 96
     }
93 97
 
94 98
     @Test
95 99
     public void testIsSilent() {
96
-        final char c = CommandManager.getCommandManager().getCommandChar();
97
-        final char s = CommandManager.getCommandManager().getSilenceChar();
98
-
99
-        assertTrue(new CommandArguments(c + "" + s).isSilent());
100
-        assertFalse(new CommandArguments("f" + s).isSilent());
101
-        assertTrue(new CommandArguments(c + "" + s + "foo").isSilent());
102
-        assertFalse(new CommandArguments("").isSilent());
103
-        assertFalse(new CommandArguments("foo").isSilent());
100
+        final char c = '/';
101
+        final char s = '.';
102
+
103
+        assertTrue(new CommandArguments(controller, c + "" + s).isSilent());
104
+        assertFalse(new CommandArguments(controller, "f" + s).isSilent());
105
+        assertTrue(new CommandArguments(controller, c + "" + s + "foo").isSilent());
106
+        assertFalse(new CommandArguments(controller, "").isSilent());
107
+        assertFalse(new CommandArguments(controller, "foo").isSilent());
104 108
     }
105 109
 
106 110
     @Test
107 111
     public void testGetLine() {
108
-        assertEquals("foo", new CommandArguments("foo").getLine());
109
-        assertEquals("foo  bar", new CommandArguments("foo  bar").getLine());
110
-        assertEquals("", new CommandArguments("").getLine());
112
+        assertEquals("foo", new CommandArguments(controller, "foo").getLine());
113
+        assertEquals("foo  bar", new CommandArguments(controller, "foo  bar").getLine());
114
+        assertEquals("", new CommandArguments(controller, "").getLine());
111 115
     }
112 116
 
113 117
     @Test
114 118
     public void testGetWords() {
115
-        final CommandArguments args = new CommandArguments("a\tb    c d e");
119
+        final CommandArguments args = new CommandArguments(controller, "a\tb    c d e");
116 120
 
117 121
         assertEquals(5, args.getWords().length);
118 122
         assertEquals("a", args.getWords()[0]);
@@ -124,7 +128,7 @@ public class CommandArgumentsTest {
124 128
 
125 129
     @Test
126 130
     public void testGetArguments() {
127
-        final CommandArguments args = new CommandArguments("a\tb    c d e");
131
+        final CommandArguments args = new CommandArguments(controller, "a\tb    c d e");
128 132
 
129 133
         assertEquals(4, args.getArguments().length);
130 134
         assertEquals("b", args.getArguments()[0]);
@@ -135,10 +139,10 @@ public class CommandArgumentsTest {
135 139
 
136 140
     @Test
137 141
     public void testGetArgumentsAsString() {
138
-        assertEquals("b\tc  d", new CommandArguments("a b\tc  d").getArgumentsAsString());
139
-        assertEquals("", new CommandArguments("a").getArgumentsAsString());
140
-        assertEquals("", new CommandArguments("a\t  \t   \t").getArgumentsAsString());
141
-        assertEquals("b", new CommandArguments("a\t  \t   \tb").getArgumentsAsString());
142
+        assertEquals("b\tc  d", new CommandArguments(controller, "a b\tc  d").getArgumentsAsString());
143
+        assertEquals("", new CommandArguments(controller, "a").getArgumentsAsString());
144
+        assertEquals("", new CommandArguments(controller, "a\t  \t   \t").getArgumentsAsString());
145
+        assertEquals("b", new CommandArguments(controller, "a\t  \t   \tb").getArgumentsAsString());
142 146
     }
143 147
 
144 148
 }

+ 3
- 1
test/com/dmdirc/commandparser/commands/channel/ModeTest.java Переглянути файл

@@ -39,7 +39,7 @@ import static org.mockito.Mockito.*;
39 39
 
40 40
 public class ModeTest {
41 41
 
42
-    private final Mode command = new Mode();
42
+    private Mode command;
43 43
     private IRCChannelInfo channelinfo;
44 44
     private Channel channel;
45 45
     private Server server;
@@ -59,6 +59,8 @@ public class ModeTest {
59 59
         when(channel.getChannelInfo()).thenReturn(channelinfo);
60 60
         when(channelinfo.getModes()).thenReturn("my mode string!");
61 61
         when(channelinfo.toString()).thenReturn("#chan");
62
+
63
+        command = new Mode();
62 64
     }
63 65
 
64 66
     @Test

+ 3
- 1
test/com/dmdirc/commandparser/commands/channel/NamesTest.java Переглянути файл

@@ -38,7 +38,7 @@ import static org.mockito.Mockito.*;
38 38
 
39 39
 public class NamesTest {
40 40
 
41
-    private final Names command = new Names();
41
+    private Names command;
42 42
     private IRCChannelInfo channelinfo;
43 43
     private Channel channel;
44 44
     private Server server;
@@ -57,6 +57,8 @@ public class NamesTest {
57 57
         when(server.getParser()).thenReturn(parser);
58 58
         when(channel.getChannelInfo()).thenReturn(channelinfo);
59 59
         when(channelinfo.getName()).thenReturn("#chan");
60
+
61
+        command = new Names();
60 62
     }
61 63
 
62 64
     @Test

+ 3
- 1
test/com/dmdirc/commandparser/commands/channel/PartTest.java Переглянути файл

@@ -37,7 +37,7 @@ import static org.mockito.Mockito.*;
37 37
 
38 38
 public class PartTest {
39 39
 
40
-    private final Part command = new Part();
40
+    private Part command;
41 41
     private Channel channel;
42 42
     private FrameContainer origin;
43 43
     private ConfigManager manager;
@@ -52,6 +52,8 @@ public class PartTest {
52 52
 
53 53
         when(origin.getConfigManager()).thenReturn(manager);
54 54
         when(manager.getOption("general", "partmessage")).thenReturn("config part message");
55
+
56
+        command = new Part();
55 57
     }
56 58
 
57 59
     @Test

Завантаження…
Відмінити
Зберегти