Bläddra i källkod

Merge pull request #614 from csmith/tidying

Remove most deprecated methods in commands
pull/615/head
Greg Holmes 8 år sedan
förälder
incheckning
2b264da6fd
32 ändrade filer med 191 tillägg och 155 borttagningar
  1. 0
    1
      res/com/dmdirc/ui/messages/format.yml
  2. 3
    3
      src/com/dmdirc/commandparser/aliases/AliasCommandHandler.java
  3. 35
    7
      src/com/dmdirc/commandparser/commands/Command.java
  4. 2
    4
      src/com/dmdirc/commandparser/commands/channel/Invite.java
  5. 1
    2
      src/com/dmdirc/commandparser/commands/channel/KickReason.java
  6. 4
    4
      src/com/dmdirc/commandparser/commands/channel/SetNickColour.java
  7. 11
    11
      src/com/dmdirc/commandparser/commands/flags/CommandFlagHandler.java
  8. 4
    7
      src/com/dmdirc/commandparser/commands/global/AliasCommand.java
  9. 3
    4
      src/com/dmdirc/commandparser/commands/global/Echo.java
  10. 10
    10
      src/com/dmdirc/commandparser/commands/global/Help.java
  11. 5
    9
      src/com/dmdirc/commandparser/commands/global/LoadPlugin.java
  12. 2
    3
      src/com/dmdirc/commandparser/commands/global/OpenWindow.java
  13. 1
    2
      src/com/dmdirc/commandparser/commands/global/ReloadIdentities.java
  14. 3
    3
      src/com/dmdirc/commandparser/commands/global/ReloadPlugin.java
  15. 1
    2
      src/com/dmdirc/commandparser/commands/global/SaveConfig.java
  16. 9
    13
      src/com/dmdirc/commandparser/commands/global/SetCommand.java
  17. 3
    3
      src/com/dmdirc/commandparser/commands/global/UnloadPlugin.java
  18. 18
    21
      src/com/dmdirc/commandparser/commands/server/Ignore.java
  19. 1
    2
      src/com/dmdirc/commandparser/commands/server/Message.java
  20. 1
    1
      src/com/dmdirc/commandparser/commands/server/OpenQuery.java
  21. 1
    1
      src/com/dmdirc/commandparser/commands/server/Umode.java
  22. 1
    1
      src/com/dmdirc/commandparser/commands/server/Whois.java
  23. 14
    2
      test/com/dmdirc/commandparser/aliases/AliasCommandHandlerTest.java
  24. 6
    4
      test/com/dmdirc/commandparser/commands/channel/BanTest.java
  25. 12
    7
      test/com/dmdirc/commandparser/commands/channel/KickReasonTest.java
  26. 14
    7
      test/com/dmdirc/commandparser/commands/channel/SetNickColourTest.java
  27. 6
    5
      test/com/dmdirc/commandparser/commands/chat/MeTest.java
  28. 3
    0
      test/com/dmdirc/commandparser/commands/flags/CommandFlagHandlerTest.java
  29. 7
    5
      test/com/dmdirc/commandparser/commands/global/AliasCommandTest.java
  30. 8
    7
      test/com/dmdirc/commandparser/commands/global/IfpluginTest.java
  31. 1
    1
      test/com/dmdirc/commandparser/commands/global/NewServerTest.java
  32. 1
    3
      test/com/dmdirc/commandparser/commands/server/ChangeServerTest.java

+ 0
- 1
res/com/dmdirc/ui/messages/format.yml Visa fil

@@ -217,7 +217,6 @@ CommandOutputEvent:
217 217
 #  commandOutput=%1$s
218 218
 #  actionTooLong=Warning: action too long to be sent
219 219
 #  tabCompletion=14Multiple possibilities: %1$s
220
-#  commandUsage=7Usage: %1$s%2$s %3$s
221 220
 #  numeric_006=%4$s
222 221
 #  numeric_007=%4$s
223 222
 #  numeric_015=%4$s

+ 3
- 3
src/com/dmdirc/commandparser/aliases/AliasCommandHandler.java Visa fil

@@ -50,9 +50,9 @@ public class AliasCommandHandler extends Command {
50 50
                 origin.getCommandParser().parseCommand(origin, getSubstituteCommand(line, args));
51 51
             }
52 52
         } else {
53
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, alias.getName() + " requires at least "
53
+            showError(origin, args.isSilent(), alias.getName() + " requires at least "
54 54
                     + alias.getMinArguments() + " argument"
55
-                    + (alias.getMinArguments() == 1 ? "" : "s") + ".");
55
+                    + (alias.getMinArguments() == 1 ? "" : "s") + '.');
56 56
         }
57 57
     }
58 58
 
@@ -72,7 +72,7 @@ public class AliasCommandHandler extends Command {
72 72
 
73 73
         final String[] arguments = args.getArguments();
74 74
         for (int i = 0; i < arguments.length; i++) {
75
-            replaceAll(builder, "$" + (i + 1) + "-", args.getArgumentsAsString(i));
75
+            replaceAll(builder, "$" + (i + 1) + '-', args.getArgumentsAsString(i));
76 76
             replaceAll(builder, "$" + (i + 1), arguments[i]);
77 77
         }
78 78
 

+ 35
- 7
src/com/dmdirc/commandparser/commands/Command.java Visa fil

@@ -24,6 +24,8 @@ package com.dmdirc.commandparser.commands;
24 24
 
25 25
 import com.dmdirc.commandparser.CommandArguments;
26 26
 import com.dmdirc.commandparser.commands.context.CommandContext;
27
+import com.dmdirc.events.CommandErrorEvent;
28
+import com.dmdirc.events.CommandOutputEvent;
27 29
 import com.dmdirc.interfaces.CommandController;
28 30
 import com.dmdirc.interfaces.WindowModel;
29 31
 import com.dmdirc.ui.messages.Styliser;
@@ -36,10 +38,6 @@ import javax.annotation.Nullable;
36 38
  */
37 39
 public abstract class Command {
38 40
 
39
-    /** The format name used for command output. */
40
-    protected static final String FORMAT_OUTPUT = "commandOutput";
41
-    /** The format name used for command errors. */
42
-    protected static final String FORMAT_ERROR = "commandError";
43 41
     /** The controller this command is associated with. */
44 42
     private final CommandController controller;
45 43
 
@@ -59,6 +57,7 @@ public abstract class Command {
59 57
      * @param type     The type of message to send
60 58
      * @param args     The arguments of the message
61 59
      */
60
+    @Deprecated
62 61
     protected final void sendLine(@Nullable final WindowModel target,
63 62
             final boolean isSilent, final String type, final Object... args) {
64 63
         if (!isSilent && target != null) {
@@ -66,6 +65,34 @@ public abstract class Command {
66 65
         }
67 66
     }
68 67
 
68
+    /**
69
+     * Sends an output line, if appropriate, to the specified target.
70
+     *
71
+     * @param target   The command window to send the line to
72
+     * @param isSilent Whether this command is being silenced or not
73
+     * @param message  The output to send
74
+     */
75
+    protected final void showOutput(@Nullable final WindowModel target,
76
+            final boolean isSilent, final String message) {
77
+        if (!isSilent && target != null) {
78
+            target.getEventBus().publishAsync(new CommandOutputEvent(target, message));
79
+        }
80
+    }
81
+
82
+    /**
83
+     * Sends an error line, if appropriate, to the specified target.
84
+     *
85
+     * @param target   The command window to send the line to
86
+     * @param isSilent Whether this command is being silenced or not
87
+     * @param message  The error message to send
88
+     */
89
+    protected final void showError(@Nullable final WindowModel target,
90
+            final boolean isSilent, final String message) {
91
+        if (!isSilent && target != null) {
92
+            target.getEventBus().publishAsync(new CommandErrorEvent(target, message));
93
+        }
94
+    }
95
+
69 96
     /**
70 97
      * Sends a usage line, if appropriate, to the specified target.
71 98
      *
@@ -76,9 +103,10 @@ public abstract class Command {
76 103
      */
77 104
     protected final void showUsage(@Nullable final WindowModel target,
78 105
             final boolean isSilent, final String name, final String args) {
79
-        sendLine(target, isSilent, "commandUsage",
80
-                controller.getCommandChar(),
81
-                name, args);
106
+        if (!isSilent && target != null) {
107
+            target.getEventBus().publishAsync(new CommandErrorEvent(target,
108
+                    "Usage: " + controller.getCommandChar() + name + ' ' + args));
109
+        }
82 110
     }
83 111
 
84 112
     /**

+ 2
- 4
src/com/dmdirc/commandparser/commands/channel/Invite.java Visa fil

@@ -66,8 +66,7 @@ public class Invite extends Command implements ExternalCommand {
66 66
     public void execute(@Nonnull final WindowModel origin,
67 67
             final CommandArguments args, final CommandContext context) {
68 68
         if (args.getArguments().length < 1) {
69
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
70
-                    "Insufficient arguments: must specify user");
69
+            showError(origin, args.isSilent(), "Insufficient arguments: must specify user");
71 70
         } else {
72 71
             final GroupChat groupChat = ((ChannelCommandContext) context).getGroupChat();
73 72
             groupChat.getConnection().flatMap(Connection::getParser)
@@ -79,8 +78,7 @@ public class Invite extends Command implements ExternalCommand {
79 78
     public void execute(final WindowModel origin, final Connection connection,
80 79
             final String channel, final boolean isSilent, final CommandArguments args) {
81 80
         if (args.getArguments().length < 1) {
82
-            sendLine(origin, isSilent, FORMAT_ERROR,
83
-                    "Insufficient arguments: must specify user");
81
+            showError(origin, isSilent,  "Insufficient arguments: must specify user");
84 82
         } else {
85 83
             connection.getParser().get().sendInvite(channel, args.getArgumentsAsString());
86 84
         }

+ 1
- 2
src/com/dmdirc/commandparser/commands/channel/KickReason.java Visa fil

@@ -82,8 +82,7 @@ public class KickReason extends Command implements IntelligentCommand {
82 82
                     ? Optional.of(args.getArgumentsAsString(1))
83 83
                     : Optional.empty());
84 84
         } else {
85
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
86
-                    "User not found: " + args.getArguments()[0]);
85
+            showError(origin, args.isSilent(), "User not found: " + args.getArguments()[0]);
87 86
         }
88 87
     }
89 88
 

+ 4
- 4
src/com/dmdirc/commandparser/commands/channel/SetNickColour.java Visa fil

@@ -84,8 +84,8 @@ public class SetNickColour extends Command implements IntelligentCommand {
84 84
                 .getUser(args.getArguments()[0]));
85 85
 
86 86
         if (!target.isPresent()) {
87
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "No such nickname ("
88
-                    + args.getArguments()[0] + ")!");
87
+            showError(origin, args.isSilent(),
88
+                    "No such nickname (" + args.getArguments()[0] + ")!");
89 89
         } else if (args.getArguments().length == 1) {
90 90
             // We're removing the colour
91 91
             target.get().removeDisplayProperty(DisplayProperty.FOREGROUND_COLOUR);
@@ -95,8 +95,8 @@ public class SetNickColour extends Command implements IntelligentCommand {
95 95
             final Colour newColour = colourManagerFactory.getColourManager(origin.getConfigManager())
96 96
                     .getColourFromString(args.getArguments()[1], null);
97 97
             if (newColour == null) {
98
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Invalid colour specified ("
99
-                        + args.getArguments()[1] + ").");
98
+                showError(origin, args.isSilent(),
99
+                        "Invalid colour specified (" + args.getArguments()[1] + ").");
100 100
                 return;
101 101
             }
102 102
 

+ 11
- 11
src/com/dmdirc/commandparser/commands/flags/CommandFlagHandler.java Visa fil

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.commandparser.commands.flags;
24 24
 
25 25
 import com.dmdirc.commandparser.CommandArguments;
26
+import com.dmdirc.events.CommandErrorEvent;
26 27
 import com.dmdirc.interfaces.WindowModel;
27 28
 
28 29
 import java.util.ArrayList;
@@ -131,13 +132,13 @@ public class CommandFlagHandler {
131 132
                     }
132 133
                 } else if (disabledBy.containsKey(name)) {
133 134
                     // Disabled by another flag
134
-                    sendLine(origin, arguments.isSilent(), "commandError",
135
+                    sendError(origin, arguments.isSilent(),
135 136
                             "Cannot use flag --" + name
136 137
                             + " in conjunction with --" + disabledBy.get(name).getName());
137 138
                     return null;
138 139
                 } else {
139 140
                     // Disabled because not yet enabled
140
-                    sendLine(origin, arguments.isSilent(), "commandError",
141
+                    sendError(origin, arguments.isSilent(),
141 142
                             "Cannot use flag --" + name
142 143
                             + " without " + getEnablers(flag));
143 144
                     return null;
@@ -181,8 +182,8 @@ public class CommandFlagHandler {
181 182
         final int lastArg = argCount + offset - 1;
182 183
 
183 184
         if (arguments.getArguments().length <= lastArg) {
184
-            sendLine(origin, arguments.isSilent(),
185
-                    "commandError", "Flag --" + flag.getName() + " expects "
185
+            sendError(origin, arguments.isSilent(),
186
+                    "Flag --" + flag.getName() + " expects "
186 187
                     + argCount + " argument"
187 188
                     + (argCount == 1 ? "" : "s"));
188 189
             return -1;
@@ -244,17 +245,16 @@ public class CommandFlagHandler {
244 245
     }
245 246
 
246 247
     /**
247
-     * Convenience method to send a line to the specified frame container.
248
+     * Convenience method to send a command error event.
248 249
      *
249
-     * @param origin      The container to send the line to
250
+     * @param origin      The container to send the event to
250 251
      * @param isSilent    Whether the command is silenced or not
251
-     * @param messageType The type of the line to be sent
252
-     * @param args        The arguments for the specified messageType
252
+     * @param message     The error message
253 253
      */
254
-    protected static void sendLine(final WindowModel origin, final boolean isSilent,
255
-            final String messageType, final Object... args) {
254
+    private static void sendError(final WindowModel origin, final boolean isSilent,
255
+            final String message) {
256 256
         if (origin != null && !isSilent) {
257
-            origin.addLine(messageType, args);
257
+            origin.getEventBus().publishAsync(new CommandErrorEvent(origin, message));
258 258
         }
259 259
     }
260 260
 

+ 4
- 7
src/com/dmdirc/commandparser/commands/global/AliasCommand.java Visa fil

@@ -88,11 +88,9 @@ public class AliasCommand extends Command implements IntelligentCommand {
88 88
         if ("--remove".equalsIgnoreCase(args.getArguments()[0])) {
89 89
             final String name = removeCommandChar(args.getArguments()[1]);
90 90
             if (doRemove(name)) {
91
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Alias '"
92
-                        + name + "' removed.");
91
+                showOutput(origin, args.isSilent(), "Alias '" + name + "' removed.");
93 92
             } else {
94
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Alias '"
95
-                        + name + "' not found.");
93
+                showError(origin, args.isSilent(), "Alias '" + name + "' not found.");
96 94
             }
97 95
 
98 96
             return;
@@ -101,8 +99,7 @@ public class AliasCommand extends Command implements IntelligentCommand {
101 99
         final String name = removeCommandChar(args.getArguments()[0]);
102 100
 
103 101
         if (aliasManager.getAlias(name).isPresent()) {
104
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Alias '" + name
105
-                    + "' already exists.");
102
+            showError(origin, args.isSilent(), "Alias '" + name + "' already exists.");
106 103
             return;
107 104
         }
108 105
 
@@ -110,7 +107,7 @@ public class AliasCommand extends Command implements IntelligentCommand {
110 107
                 removeCommandChar(args.getArgumentsAsString(1)));
111 108
         aliasManager.addAlias(myAlias);
112 109
 
113
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Alias '" + name + "' created.");
110
+        showOutput(origin, args.isSilent(), "Alias '" + name + "' created.");
114 111
     }
115 112
 
116 113
     /**

+ 3
- 4
src/com/dmdirc/commandparser/commands/global/Echo.java Visa fil

@@ -97,14 +97,14 @@ public class Echo extends Command implements IntelligentCommand {
97 97
             try {
98 98
                 time = new Date(Long.parseLong(results.getArgumentsAsString(timeStampFlag)));
99 99
             } catch (NumberFormatException ex) {
100
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to process timestamp");
100
+                showError(origin, args.isSilent(), "Unable to process timestamp");
101 101
                 return;
102 102
             }
103 103
         }
104 104
 
105 105
         if (results.hasFlag(targetFlag)) {
106 106
             WindowModel frame = null;
107
-            Optional<WindowModel> target = Optional.ofNullable(origin);
107
+            Optional<WindowModel> target = Optional.of(origin);
108 108
 
109 109
             while (frame == null && target.isPresent()) {
110 110
                 frame = windowManager.findCustomWindow(target.get(),
@@ -117,8 +117,7 @@ public class Echo extends Command implements IntelligentCommand {
117 117
             }
118 118
 
119 119
             if (frame == null) {
120
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
121
-                        "Unable to find target window");
120
+                showError(origin, args.isSilent(), "Unable to find target window");
122 121
             } else if (!args.isSilent()) {
123 122
                 frame.getEventBus().publishAsync(new CommandOutputEvent(frame, time.getTime(),
124 123
                         results.getArgumentsAsString()));

+ 10
- 10
src/com/dmdirc/commandparser/commands/global/Help.java Visa fil

@@ -87,14 +87,14 @@ public class Help extends Command implements IntelligentCommand {
87 87
 
88 88
         Collections.sort(commands);
89 89
 
90
-        sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
90
+        showOutput(origin, isSilent, Styliser.CODE_FIXED
91 91
                 + "----------------------- Available commands -------");
92 92
 
93 93
         final StringBuilder builder = new StringBuilder();
94 94
 
95 95
         for (String command : commands) {
96 96
             if (builder.length() + command.length() + 1 > 50) {
97
-                sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED + builder.toString());
97
+                showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
98 98
                 builder.delete(0, builder.length());
99 99
             } else if (builder.length() > 0) {
100 100
                 builder.append(' ');
@@ -104,10 +104,10 @@ public class Help extends Command implements IntelligentCommand {
104 104
         }
105 105
 
106 106
         if (builder.length() > 0) {
107
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED + builder.toString());
107
+            showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
108 108
         }
109 109
 
110
-        sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
110
+        showOutput(origin, isSilent, Styliser.CODE_FIXED
111 111
                 + "--------------------------------------------------");
112 112
     }
113 113
 
@@ -129,17 +129,17 @@ public class Help extends Command implements IntelligentCommand {
129 129
         }
130 130
 
131 131
         if (command == null) {
132
-            sendLine(origin, isSilent, FORMAT_ERROR, "Command '" + name + "' not found.");
132
+            showError(origin, isSilent, "Command '" + name + "' not found.");
133 133
         } else {
134
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
134
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
135 135
                     + "---------------------- Command information -------");
136
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
136
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
137 137
                     + " Name: " + name);
138
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
138
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
139 139
                     + " Type: " + command.getKey().getType());
140
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
140
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
141 141
                     + "Usage: " + command.getKey().getHelp());
142
-            sendLine(origin, isSilent, FORMAT_OUTPUT, Styliser.CODE_FIXED
142
+            showOutput(origin, isSilent, Styliser.CODE_FIXED
143 143
                     + "--------------------------------------------------");
144 144
         }
145 145
     }

+ 5
- 9
src/com/dmdirc/commandparser/commands/global/LoadPlugin.java Visa fil

@@ -78,21 +78,17 @@ public class LoadPlugin extends Command implements IntelligentCommand {
78 78
         final PluginInfo plugin = pluginManager.getPluginInfo(args.getArgumentsAsString());
79 79
 
80 80
         if (plugin == null) {
81
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
82
-                    "Plugin loading failed");
81
+            showError(origin, args.isSilent(), "Plugin loading failed");
83 82
         } else if (plugin.isLoaded()) {
84
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
85
-                    "Plugin already loaded.");
83
+            showError(origin, args.isSilent(), "Plugin already loaded.");
86 84
         } else {
87 85
             plugin.loadPlugin();
88 86
             if (plugin.isLoaded()) {
89
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
90
-                        "Plugin loaded.");
87
+                showOutput(origin, args.isSilent(), "Plugin loaded.");
91 88
                 pluginManager.updateAutoLoad(plugin);
92 89
             } else {
93
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
94
-                        "Loading plugin failed. ("
95
-                        + plugin.getLastError() + ")");
90
+                showOutput(origin, args.isSilent(),
91
+                        "Loading plugin failed. (" + plugin.getLastError() + ')');
96 92
             }
97 93
         }
98 94
     }

+ 2
- 3
src/com/dmdirc/commandparser/commands/global/OpenWindow.java Visa fil

@@ -91,7 +91,7 @@ public class OpenWindow extends Command implements IntelligentCommand {
91 91
         if (args.getArguments().length > 0 && "--server".equals(args.getArguments()[0])) {
92 92
             final Optional<Connection> connection = origin.getConnection();
93 93
             if (!connection.isPresent()) {
94
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
94
+                showError(origin, args.isSilent(),
95 95
                         "This window doesn't have an associated server.");
96 96
                 return;
97 97
             }
@@ -130,8 +130,7 @@ public class OpenWindow extends Command implements IntelligentCommand {
130 130
                     windowManager.addWindow(parent, newWindow);
131 131
                 }
132 132
             } else {
133
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
134
-                        "A custom window by that name already exists.");
133
+                showError(origin, args.isSilent(), "A custom window by that name already exists.");
135 134
             }
136 135
         }
137 136
     }

+ 1
- 2
src/com/dmdirc/commandparser/commands/global/ReloadIdentities.java Visa fil

@@ -66,8 +66,7 @@ public class ReloadIdentities extends Command implements IntelligentCommand {
66 66
     public void execute(@Nonnull final WindowModel origin,
67 67
             final CommandArguments args, final CommandContext context) {
68 68
         identityController.loadUserIdentities();
69
-
70
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Identities reloaded.");
69
+        showOutput(origin, args.isSilent(), "Identities reloaded.");
71 70
     }
72 71
 
73 72
     @Override

+ 3
- 3
src/com/dmdirc/commandparser/commands/global/ReloadPlugin.java Visa fil

@@ -74,12 +74,12 @@ public class ReloadPlugin extends Command implements IntelligentCommand {
74 74
 
75 75
         final PluginInfo plugin = pluginManager.getPluginInfoByName(args.getArguments()[0]);
76 76
         if (plugin == null) {
77
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
77
+            showError(origin, args.isSilent(),
78 78
                     "Plugin Reloading failed - Plugin not loaded");
79 79
         } else if (pluginManager.reloadPlugin(plugin.getMetaData().getRelativeFilename())) {
80
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Plugin Reloaded.");
80
+            showOutput(origin, args.isSilent(), "Plugin Reloaded.");
81 81
         } else {
82
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Plugin Reloading failed");
82
+            showError(origin, args.isSilent(), "Plugin Reloading failed");
83 83
         }
84 84
     }
85 85
 

+ 1
- 2
src/com/dmdirc/commandparser/commands/global/SaveConfig.java Visa fil

@@ -66,8 +66,7 @@ public final class SaveConfig extends Command implements IntelligentCommand {
66 66
     public void execute(@Nonnull final WindowModel origin,
67 67
             final CommandArguments args, final CommandContext context) {
68 68
         identityController.saveAll();
69
-
70
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Configuration file saved.");
69
+        showOutput(origin, args.isSilent(), "Configuration file saved.");
71 70
     }
72 71
 
73 72
     @Override

+ 9
- 13
src/com/dmdirc/commandparser/commands/global/SetCommand.java Visa fil

@@ -118,8 +118,7 @@ public class SetCommand extends Command implements IntelligentCommand {
118 118
 
119 119
         if (res.hasFlag(serverFlag)) {
120 120
             if (!connection.isPresent()) {
121
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
122
-                        "Cannot use --server in this context");
121
+                showError(origin, args.isSilent(), "Cannot use --server in this context");
123 122
                 return;
124 123
             }
125 124
 
@@ -129,8 +128,7 @@ public class SetCommand extends Command implements IntelligentCommand {
129 128
 
130 129
         if (res.hasFlag(channelFlag)) {
131 130
             if (!(context instanceof ChannelCommandContext)) {
132
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
133
-                        "Cannot use --channel in this context");
131
+                showError(origin, args.isSilent(),"Cannot use --channel in this context");
134 132
                 return;
135 133
             }
136 134
 
@@ -193,7 +191,7 @@ public class SetCommand extends Command implements IntelligentCommand {
193 191
             output.append(", ");
194 192
         }
195 193
 
196
-        sendLine(origin, isSilent, FORMAT_OUTPUT, output.substring(0, output.length() - 2));
194
+        showOutput(origin, isSilent, output.substring(0, output.length() - 2));
197 195
     }
198 196
 
199 197
     /**
@@ -221,10 +219,9 @@ public class SetCommand extends Command implements IntelligentCommand {
221 219
         }
222 220
 
223 221
         if (found) {
224
-            sendLine(origin, isSilent, FORMAT_OUTPUT, output.substring(0, output.length() - 2));
222
+            showOutput(origin, isSilent, output.substring(0, output.length() - 2));
225 223
         } else {
226
-            sendLine(origin, isSilent, FORMAT_ERROR,
227
-                    "There are no options in the domain '" + domain + "'.");
224
+            showError(origin, isSilent, "There are no options in the domain '" + domain + "'.");
228 225
         }
229 226
     }
230 227
 
@@ -241,10 +238,10 @@ public class SetCommand extends Command implements IntelligentCommand {
241 238
             final boolean isSilent, final ReadOnlyConfigProvider manager,
242 239
             final String domain, final String option) {
243 240
         if (manager.hasOptionString(domain, option)) {
244
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "The current value of "
241
+            showOutput(origin, isSilent, "The current value of "
245 242
                     + domain + '.' + option + " is: " + manager.getOption(domain, option));
246 243
         } else {
247
-            sendLine(origin, isSilent, FORMAT_ERROR, "Option not found: " + domain + '.' + option);
244
+            showError(origin, isSilent, "Option not found: " + domain + '.' + option);
248 245
         }
249 246
     }
250 247
 
@@ -263,8 +260,7 @@ public class SetCommand extends Command implements IntelligentCommand {
263 260
             final String domain, final String option, final String newvalue) {
264 261
         identity.setOption(domain, option, newvalue);
265 262
 
266
-        sendLine(origin, isSilent, FORMAT_OUTPUT, domain + '.' + option
267
-                + " has been set to: " + newvalue);
263
+        showOutput(origin, isSilent, domain + '.' + option + " has been set to: " + newvalue);
268 264
     }
269 265
 
270 266
     /**
@@ -301,7 +297,7 @@ public class SetCommand extends Command implements IntelligentCommand {
301 297
             final String option) {
302 298
         identity.unsetOption(domain, option);
303 299
 
304
-        sendLine(origin, isSilent, FORMAT_OUTPUT, domain + '.' + option + " has been unset.");
300
+        showOutput(origin, isSilent, domain + '.' + option + " has been unset.");
305 301
     }
306 302
 
307 303
     @Override

+ 3
- 3
src/com/dmdirc/commandparser/commands/global/UnloadPlugin.java Visa fil

@@ -74,13 +74,13 @@ public class UnloadPlugin extends Command implements IntelligentCommand {
74 74
 
75 75
         final PluginInfo plugin = pluginManager.getPluginInfoByName(args.getArguments()[0]);
76 76
         if (plugin == null) {
77
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
77
+            showError(origin, args.isSilent(),
78 78
                     "Plugin unloading failed - Plugin not loaded");
79 79
         } else if (pluginManager.delPlugin(plugin.getMetaData().getRelativeFilename())) {
80
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Plugin Unloaded.");
80
+            showOutput(origin, args.isSilent(), "Plugin Unloaded.");
81 81
             pluginManager.updateAutoLoad(plugin);
82 82
         } else {
83
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Plugin Unloading failed");
83
+            showError(origin, args.isSilent(), "Plugin Unloading failed");
84 84
         }
85 85
     }
86 86
 

+ 18
- 21
src/com/dmdirc/commandparser/commands/server/Ignore.java Visa fil

@@ -71,23 +71,22 @@ public class Ignore extends Command implements IntelligentCommand {
71 71
         final Connection connection = ((ServerCommandContext) context).getConnection();
72 72
 
73 73
         if (args.getArguments().length == 0) {
74
-            executeView(origin, connection, args.isSilent(), args, false);
74
+            executeView(origin, connection, args, false);
75 75
         } else if ("--remove".equalsIgnoreCase(args.getArguments()[0])) {
76
-            executeRemove(origin, connection, args.isSilent(), args);
76
+            executeRemove(origin, connection, args);
77 77
         } else if ("--regex".equalsIgnoreCase(args.getArguments()[0])) {
78
-            executeRegex(origin, connection, args.isSilent(), args);
78
+            executeRegex(origin, connection, args);
79 79
         } else {
80
-            executeAdd(origin, connection, args.isSilent(), args);
80
+            executeAdd(origin, connection, args);
81 81
         }
82 82
     }
83 83
 
84 84
     protected void executeView(final WindowModel origin, final Connection connection,
85
-            final boolean isSilent, final CommandArguments args, final boolean forceRegex) {
85
+            final CommandArguments args, final boolean forceRegex) {
86 86
         final IgnoreList ignoreList = connection.getIgnoreList();
87 87
 
88 88
         if (ignoreList.count() == 0) {
89
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
90
-                    "No ignore list entries for this network.");
89
+            showError(origin, args.isSilent(), "No ignore list entries for this network.");
91 90
             return;
92 91
         }
93 92
 
@@ -96,7 +95,7 @@ public class Ignore extends Command implements IntelligentCommand {
96 95
             entries = ignoreList.getSimpleList();
97 96
         } else {
98 97
             if (!forceRegex) {
99
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
98
+                showError(origin, args.isSilent(),
100 99
                         "Unable to convert ignore list to simple format");
101 100
             }
102 101
             entries = ignoreList.getRegexList();
@@ -105,24 +104,24 @@ public class Ignore extends Command implements IntelligentCommand {
105 104
         int i = 0;
106 105
         for (String line : entries) {
107 106
             i++;
108
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, i + ". " + line);
107
+            showOutput(origin, args.isSilent(), i + ". " + line);
109 108
         }
110 109
     }
111 110
 
112 111
     protected void executeAdd(final WindowModel origin, final Connection connection,
113
-            final boolean isSilent, final CommandArguments args) {
112
+            final CommandArguments args) {
114 113
         final IgnoreList ignoreList = connection.getIgnoreList();
115 114
         final String target = args.getArgumentsAsString();
116 115
 
117 116
         ignoreList.addSimple(target);
118 117
         connection.saveIgnoreList();
119
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Added " + target + " to the ignore list.");
118
+        showOutput(origin, args.isSilent(), "Added " + target + " to the ignore list.");
120 119
     }
121 120
 
122 121
     protected void executeRegex(final WindowModel origin, final Connection connection,
123
-            final boolean isSilent, final CommandArguments args) {
122
+            final CommandArguments args) {
124 123
         if (args.getArguments().length == 1) {
125
-            executeView(origin, connection, args.isSilent(), args, true);
124
+            executeView(origin, connection, args, true);
126 125
             return;
127 126
         }
128 127
 
@@ -133,18 +132,17 @@ public class Ignore extends Command implements IntelligentCommand {
133 132
             //noinspection ResultOfMethodCallIgnored
134 133
             Pattern.compile(target);
135 134
         } catch (PatternSyntaxException ex) {
136
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to compile regex: "
137
-                    + ex.getDescription());
135
+            showError(origin, args.isSilent(), "Unable to compile regex: " + ex.getDescription());
138 136
             return;
139 137
         }
140 138
 
141 139
         ignoreList.add(target);
142 140
         connection.saveIgnoreList();
143
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Added " + target + " to the ignore list.");
141
+        showOutput(origin, args.isSilent(), "Added " + target + " to the ignore list.");
144 142
     }
145 143
 
146 144
     protected void executeRemove(final WindowModel origin, final Connection connection,
147
-            final boolean isSilent, final CommandArguments args) {
145
+            final CommandArguments args) {
148 146
         if (args.getArguments().length == 1) {
149 147
             showUsage(origin, args.isSilent(), "ignore", "--remove <host>");
150 148
             return;
@@ -156,7 +154,7 @@ public class Ignore extends Command implements IntelligentCommand {
156 154
         if (ignoreList.canConvert() && ignoreList.getSimpleList().contains(host)) {
157 155
             ignoreList.remove(ignoreList.getSimpleList().indexOf(host));
158 156
             connection.saveIgnoreList();
159
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Removed " + host
157
+            showOutput(origin, args.isSilent(), "Removed " + host
160 158
                     + " from the ignore list.");
161 159
             return;
162 160
         }
@@ -164,13 +162,12 @@ public class Ignore extends Command implements IntelligentCommand {
164 162
         if (ignoreList.getRegexList().contains(host)) {
165 163
             ignoreList.remove(ignoreList.getRegexList().indexOf(host));
166 164
             connection.saveIgnoreList();
167
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Removed " + host
165
+            showOutput(origin, args.isSilent(), "Removed " + host
168 166
                     + " from the ignore list.");
169 167
             return;
170 168
         }
171 169
 
172
-        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Ignore list doesn't contain '" + host
173
-                + "'.");
170
+        showError(origin, args.isSilent(), "Ignore list doesn't contain '" + host + "'.");
174 171
     }
175 172
 
176 173
     @Override

+ 1
- 2
src/com/dmdirc/commandparser/commands/server/Message.java Visa fil

@@ -94,8 +94,7 @@ public class Message extends Command implements IntelligentCommand,
94 94
                     // This can happen if the server gets disconnected after
95 95
                     // the command manager has checked the @CommandOptions
96 96
                     // annotation. Yay for concurrency.
97
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
98
-                            "You must be connected to use this command");
97
+                    showError(origin, args.isSilent(), "You must be connected to use this command");
99 98
                 }
100 99
             }
101 100
         }

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Visa fil

@@ -75,7 +75,7 @@ public class OpenQuery extends Command implements IntelligentCommand,
75 75
 
76 76
         final Connection connection = ((ServerCommandContext) context).getConnection();
77 77
         if (connection.getParser().get().isValidChannelName(args.getArguments()[0])) {
78
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "You can't open a query "
78
+            showError(origin, args.isSilent(), "You can't open a query "
79 79
                     + "with a channel; maybe you meant " + Styliser.CODE_FIXED
80 80
                     + Styliser.CODE_BOLD
81 81
                     + getController().getCommandChar()

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Umode.java Visa fil

@@ -64,7 +64,7 @@ public class Umode extends Command {
64 64
             final CommandArguments args, final CommandContext context) {
65 65
         final Connection connection = ((ServerCommandContext) context).getConnection();
66 66
         if (connection.getState() != ServerState.CONNECTED) {
67
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Not connected");
67
+            showError(origin, args.isSilent(), "Not connected");
68 68
             return;
69 69
         }
70 70
 

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Whois.java Visa fil

@@ -63,7 +63,7 @@ public class Whois extends Command {
63 63
             final CommandArguments args, final CommandContext context) {
64 64
         final Connection connection = ((ServerCommandContext) context).getConnection();
65 65
         if (connection.getState() != ServerState.CONNECTED) {
66
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Not connected");
66
+            showError(origin, args.isSilent(), "Not connected");
67 67
             return;
68 68
         }
69 69
 

+ 14
- 2
test/com/dmdirc/commandparser/aliases/AliasCommandHandlerTest.java Visa fil

@@ -22,20 +22,25 @@
22 22
 
23 23
 package com.dmdirc.commandparser.aliases;
24 24
 
25
+import com.dmdirc.DMDircMBassador;
25 26
 import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandType;
28 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
29 30
 import com.dmdirc.commandparser.parsers.CommandParser;
31
+import com.dmdirc.events.CommandErrorEvent;
30 32
 import com.dmdirc.interfaces.CommandController;
31 33
 import com.dmdirc.interfaces.WindowModel;
32 34
 
33 35
 import org.junit.Before;
34 36
 import org.junit.Test;
35 37
 import org.junit.runner.RunWith;
38
+import org.mockito.ArgumentCaptor;
39
+import org.mockito.Captor;
36 40
 import org.mockito.Mock;
37 41
 import org.mockito.runners.MockitoJUnitRunner;
38 42
 
43
+import static org.junit.Assert.assertEquals;
39 44
 import static org.mockito.Mockito.verify;
40 45
 import static org.mockito.Mockito.when;
41 46
 
@@ -47,6 +52,8 @@ public class AliasCommandHandlerTest {
47 52
     @Mock private CommandParser commandParser;
48 53
     @Mock private CommandContext context;
49 54
     @Mock private CommandInfo commandInfo;
55
+    @Mock private DMDircMBassador eventbus;
56
+    @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
50 57
 
51 58
     @Before
52 59
     public void setup() {
@@ -55,6 +62,7 @@ public class AliasCommandHandlerTest {
55 62
         when(commandController.getSilenceChar()).thenReturn('/');
56 63
         when(context.getSource()).thenReturn(container);
57 64
         when(context.getCommandInfo()).thenReturn(commandInfo);
65
+        when(container.getEventBus()).thenReturn(eventbus);
58 66
     }
59 67
 
60 68
     @Test
@@ -82,7 +90,9 @@ public class AliasCommandHandlerTest {
82 90
         final AliasCommandHandler handler = new AliasCommandHandler(commandController, alias);
83 91
         final CommandArguments arguments = new CommandArguments(commandController, "#test");
84 92
         handler.execute(container, arguments, context);
85
-        verify(container).addLine("commandError", "test requires at least 1 argument.");
93
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
94
+        assertEquals("test requires at least 1 argument.",
95
+                errorEventCaptor.getValue().getMessage());
86 96
     }
87 97
 
88 98
     @Test
@@ -91,7 +101,9 @@ public class AliasCommandHandlerTest {
91 101
         final AliasCommandHandler handler = new AliasCommandHandler(commandController, alias);
92 102
         final CommandArguments arguments = new CommandArguments(commandController, "#test agadoo");
93 103
         handler.execute(container, arguments, context);
94
-        verify(container).addLine("commandError", "test requires at least 2 arguments.");
104
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
105
+        assertEquals("test requires at least 2 arguments.",
106
+                errorEventCaptor.getValue().getMessage());
95 107
     }
96 108
 
97 109
     @Test

+ 6
- 4
test/com/dmdirc/commandparser/commands/channel/BanTest.java Visa fil

@@ -23,8 +23,10 @@
23 23
 package com.dmdirc.commandparser.commands.channel;
24 24
 
25 25
 import com.dmdirc.Channel;
26
+import com.dmdirc.DMDircMBassador;
26 27
 import com.dmdirc.commandparser.CommandArguments;
27 28
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
29
+import com.dmdirc.events.CommandErrorEvent;
28 30
 import com.dmdirc.interfaces.CommandController;
29 31
 import com.dmdirc.interfaces.Connection;
30 32
 import com.dmdirc.interfaces.GroupChatUser;
@@ -39,9 +41,7 @@ import org.junit.runner.RunWith;
39 41
 import org.mockito.Mock;
40 42
 import org.mockito.runners.MockitoJUnitRunner;
41 43
 
42
-import static org.mockito.Mockito.anyChar;
43
-import static org.mockito.Mockito.anyString;
44
-import static org.mockito.Mockito.eq;
44
+import static org.mockito.Matchers.isA;
45 45
 import static org.mockito.Mockito.verify;
46 46
 import static org.mockito.Mockito.when;
47 47
 
@@ -55,6 +55,7 @@ public class BanTest {
55 55
     @Mock private Channel channel;
56 56
     @Mock private CommandController controller;
57 57
     @Mock private WindowModel container;
58
+    @Mock private DMDircMBassador eventbus;
58 59
     private Ban command;
59 60
 
60 61
     @Before
@@ -67,6 +68,7 @@ public class BanTest {
67 68
         when(channel.getUser(user2)).thenReturn(Optional.empty());
68 69
         when(controller.getCommandChar()).thenReturn('/');
69 70
         when(controller.getSilenceChar()).thenReturn('.');
71
+        when(container.getEventBus()).thenReturn(eventbus);
70 72
         command = new Ban(controller);
71 73
     }
72 74
 
@@ -75,7 +77,7 @@ public class BanTest {
75 77
         command.execute(container, new CommandArguments(controller, "/ban"),
76 78
                 new ChannelCommandContext(null, Ban.INFO, channel));
77 79
 
78
-        verify(container).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
80
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
79 81
     }
80 82
 
81 83
     /** Tests that the ban command uses the correct hostname if given a user. */

+ 12
- 7
test/com/dmdirc/commandparser/commands/channel/KickReasonTest.java Visa fil

@@ -23,8 +23,10 @@
23 23
 package com.dmdirc.commandparser.commands.channel;
24 24
 
25 25
 import com.dmdirc.Channel;
26
+import com.dmdirc.DMDircMBassador;
26 27
 import com.dmdirc.commandparser.CommandArguments;
27 28
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
29
+import com.dmdirc.events.CommandErrorEvent;
28 30
 import com.dmdirc.interfaces.CommandController;
29 31
 import com.dmdirc.interfaces.Connection;
30 32
 import com.dmdirc.interfaces.GroupChatUser;
@@ -38,13 +40,13 @@ import java.util.Optional;
38 40
 import org.junit.Before;
39 41
 import org.junit.Test;
40 42
 import org.junit.runner.RunWith;
43
+import org.mockito.ArgumentCaptor;
44
+import org.mockito.Captor;
41 45
 import org.mockito.Mock;
42 46
 import org.mockito.runners.MockitoJUnitRunner;
43 47
 
44
-import static org.mockito.Mockito.anyChar;
45
-import static org.mockito.Mockito.anyString;
46
-import static org.mockito.Mockito.eq;
47
-import static org.mockito.Mockito.matches;
48
+import static org.junit.Assert.assertTrue;
49
+import static org.mockito.Matchers.isA;
48 50
 import static org.mockito.Mockito.verify;
49 51
 import static org.mockito.Mockito.when;
50 52
 
@@ -58,8 +60,10 @@ public class KickReasonTest {
58 60
     @Mock private Channel channel;
59 61
     @Mock private CommandController controller;
60 62
     @Mock private WindowModel container;
63
+    @Mock private DMDircMBassador eventbus;
61 64
     @Mock private ChannelInfo channelInfo;
62 65
     @Mock private AggregateConfigProvider configProvider;
66
+    @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
63 67
     private KickReason command;
64 68
 
65 69
     @Before
@@ -75,6 +79,7 @@ public class KickReasonTest {
75 79
         when(channel.getUser(user2)).thenReturn(Optional.empty());
76 80
         when(controller.getCommandChar()).thenReturn('/');
77 81
         when(controller.getSilenceChar()).thenReturn('.');
82
+        when(container.getEventBus()).thenReturn(eventbus);
78 83
         command = new KickReason(controller);
79 84
     }
80 85
 
@@ -82,8 +87,7 @@ public class KickReasonTest {
82 87
     public void testUsage() {
83 88
         command.execute(container, new CommandArguments(controller, "/kick"),
84 89
                 new ChannelCommandContext(null, KickReason.INFO, channel));
85
-
86
-        verify(container).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
90
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
87 91
     }
88 92
 
89 93
     @Test
@@ -91,7 +95,8 @@ public class KickReasonTest {
91 95
         command.execute(container, new CommandArguments(controller, "/kick user1"),
92 96
                 new ChannelCommandContext(null, KickReason.INFO, channel));
93 97
 
94
-        verify(container).addLine(eq("commandError"), matches(".*user1"));
98
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
99
+        assertTrue(errorEventCaptor.getValue().getMessage().matches(".*user1"));
95 100
     }
96 101
 
97 102
     @Test

+ 14
- 7
test/com/dmdirc/commandparser/commands/channel/SetNickColourTest.java Visa fil

@@ -22,8 +22,10 @@
22 22
 package com.dmdirc.commandparser.commands.channel;
23 23
 
24 24
 import com.dmdirc.Channel;
25
+import com.dmdirc.DMDircMBassador;
25 26
 import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
28
+import com.dmdirc.events.CommandErrorEvent;
27 29
 import com.dmdirc.events.DisplayProperty;
28 30
 import com.dmdirc.interfaces.CommandController;
29 31
 import com.dmdirc.interfaces.Connection;
@@ -39,12 +41,14 @@ import java.util.Optional;
39 41
 import org.junit.Before;
40 42
 import org.junit.Test;
41 43
 import org.junit.runner.RunWith;
44
+import org.mockito.ArgumentCaptor;
45
+import org.mockito.Captor;
42 46
 import org.mockito.Mock;
43 47
 import org.mockito.runners.MockitoJUnitRunner;
44 48
 
49
+import static org.junit.Assert.assertEquals;
45 50
 import static org.mockito.Matchers.any;
46
-import static org.mockito.Mockito.anyChar;
47
-import static org.mockito.Mockito.anyString;
51
+import static org.mockito.Matchers.isA;
48 52
 import static org.mockito.Mockito.eq;
49 53
 import static org.mockito.Mockito.never;
50 54
 import static org.mockito.Mockito.verify;
@@ -62,6 +66,8 @@ public class SetNickColourTest {
62 66
     @Mock private ColourManager colourManager;
63 67
     @Mock private CommandController controller;
64 68
     @Mock private WindowModel tiw;
69
+    @Mock private DMDircMBassador eventbus;
70
+    @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
65 71
     private SetNickColour command;
66 72
 
67 73
     @Before
@@ -76,14 +82,14 @@ public class SetNickColourTest {
76 82
         when(channel.getUser(user2)).thenReturn(Optional.empty());
77 83
         when(colourManagerFactory.getColourManager(any())).thenReturn(colourManager);
78 84
         when(colourManager.getColourFromString(eq("4"), any())).thenReturn(Colour.RED);
85
+        when(tiw.getEventBus()).thenReturn(eventbus);
79 86
     }
80 87
 
81 88
     @Test
82 89
     public void testUsageNoArgs() {
83 90
         command.execute(tiw, new CommandArguments(controller, "/foo"),
84 91
                 new ChannelCommandContext(null, SetNickColour.INFO, channel));
85
-
86
-        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
92
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
87 93
     }
88 94
 
89 95
     @Test
@@ -100,15 +106,16 @@ public class SetNickColourTest {
100 106
                 new ChannelCommandContext(null, SetNickColour.INFO, channel));
101 107
         verify(channel, never()).refreshClients();
102 108
         verify(groupChatUser, never()).removeDisplayProperty(DisplayProperty.FOREGROUND_COLOUR);
103
-        verify(tiw).addLine(eq("commandError"), eq("No such nickname (foo)!"));
109
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
110
+        assertEquals("No such nickname (foo)!", errorEventCaptor.getValue().getMessage());
104 111
     }
105 112
 
106 113
     @Test
107 114
     public void testUsageInvalidColour() {
108 115
         command.execute(tiw, new CommandArguments(controller, "/foo moo omg"),
109 116
                 new ChannelCommandContext(null, SetNickColour.INFO, channel));
110
-
111
-        verify(tiw).addLine(eq("commandError"), eq("Invalid colour specified (omg)."));
117
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
118
+        assertEquals("Invalid colour specified (omg).", errorEventCaptor.getValue().getMessage());
112 119
     }
113 120
 
114 121
     @Test

+ 6
- 5
test/com/dmdirc/commandparser/commands/chat/MeTest.java Visa fil

@@ -21,8 +21,10 @@
21 21
  */
22 22
 package com.dmdirc.commandparser.commands.chat;
23 23
 
24
+import com.dmdirc.DMDircMBassador;
24 25
 import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.commands.context.ChatCommandContext;
27
+import com.dmdirc.events.CommandErrorEvent;
26 28
 import com.dmdirc.interfaces.Chat;
27 29
 import com.dmdirc.interfaces.CommandController;
28 30
 import com.dmdirc.interfaces.WindowModel;
@@ -33,9 +35,7 @@ import org.junit.runner.RunWith;
33 35
 import org.mockito.Mock;
34 36
 import org.mockito.runners.MockitoJUnitRunner;
35 37
 
36
-import static org.mockito.Mockito.anyChar;
37
-import static org.mockito.Mockito.anyString;
38
-import static org.mockito.Mockito.eq;
38
+import static org.mockito.Matchers.isA;
39 39
 import static org.mockito.Mockito.verify;
40 40
 import static org.mockito.Mockito.when;
41 41
 
@@ -44,12 +44,14 @@ public class MeTest {
44 44
 
45 45
     @Mock private Chat chat;
46 46
     @Mock private WindowModel frameContainer;
47
+    @Mock private DMDircMBassador eventbus;
47 48
     @Mock private CommandController controller;
48 49
     private Me command;
49 50
 
50 51
     @Before
51 52
     public void setUp() {
52 53
         when(chat.getWindowModel()).thenReturn(frameContainer);
54
+        when(frameContainer.getEventBus()).thenReturn(eventbus);
53 55
         command = new Me(controller);
54 56
     }
55 57
 
@@ -57,8 +59,7 @@ public class MeTest {
57 59
     public void testUsage() {
58 60
         command.execute(frameContainer, new CommandArguments(controller, "/foo"),
59 61
                 new ChatCommandContext(null, Me.INFO, chat));
60
-
61
-        verify(frameContainer).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
62
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
62 63
     }
63 64
 
64 65
     @Test

+ 3
- 0
test/com/dmdirc/commandparser/commands/flags/CommandFlagHandlerTest.java Visa fil

@@ -21,6 +21,7 @@
21 21
  */
22 22
 package com.dmdirc.commandparser.commands.flags;
23 23
 
24
+import com.dmdirc.DMDircMBassador;
24 25
 import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.interfaces.CommandController;
26 27
 import com.dmdirc.interfaces.WindowModel;
@@ -72,9 +73,11 @@ public class CommandFlagHandlerTest {
72 73
     @Test
73 74
     public void testParse() {
74 75
         final WindowModel container = mock(WindowModel.class);
76
+        final DMDircMBassador eventBus = mock(DMDircMBassador.class);
75 77
         final CommandController controller = mock(CommandController.class);
76 78
         when(controller.getCommandChar()).thenReturn('/');
77 79
         when(controller.getSilenceChar()).thenReturn('.');
80
+        when(container.getEventBus()).thenReturn(eventBus);
78 81
 
79 82
         final Map<CommandFlag, Integer> results = handler.parse(container,
80 83
                 new CommandArguments(controller, input));

+ 7
- 5
test/com/dmdirc/commandparser/commands/global/AliasCommandTest.java Visa fil

@@ -21,10 +21,12 @@
21 21
  */
22 22
 package com.dmdirc.commandparser.commands.global;
23 23
 
24
+import com.dmdirc.DMDircMBassador;
24 25
 import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.aliases.AliasFactory;
26 27
 import com.dmdirc.commandparser.aliases.AliasManager;
27 28
 import com.dmdirc.commandparser.commands.context.CommandContext;
29
+import com.dmdirc.events.CommandErrorEvent;
28 30
 import com.dmdirc.interfaces.CommandController;
29 31
 import com.dmdirc.interfaces.WindowModel;
30 32
 import com.dmdirc.ui.input.TabCompleterUtils;
@@ -35,9 +37,7 @@ import org.junit.runner.RunWith;
35 37
 import org.mockito.Mock;
36 38
 import org.mockito.runners.MockitoJUnitRunner;
37 39
 
38
-import static org.mockito.Matchers.anyChar;
39
-import static org.mockito.Matchers.anyString;
40
-import static org.mockito.Matchers.eq;
40
+import static org.mockito.Matchers.isA;
41 41
 import static org.mockito.Mockito.verify;
42 42
 import static org.mockito.Mockito.when;
43 43
 
@@ -49,6 +49,7 @@ public class AliasCommandTest {
49 49
     @Mock private CommandController controller;
50 50
     @Mock private TabCompleterUtils tabCompleterUtils;
51 51
     @Mock private WindowModel tiw;
52
+    @Mock private DMDircMBassador eventbus;
52 53
     private AliasCommand command;
53 54
 
54 55
     @Before
@@ -56,6 +57,7 @@ public class AliasCommandTest {
56 57
         command = new AliasCommand(controller, aliasFactory, aliasManager, tabCompleterUtils);
57 58
         when(controller.getCommandChar()).thenReturn('/');
58 59
         when(controller.getSilenceChar()).thenReturn('.');
60
+        when(tiw.getEventBus()).thenReturn(eventbus);
59 61
     }
60 62
 
61 63
     @Test
@@ -63,7 +65,7 @@ public class AliasCommandTest {
63 65
         command.execute(tiw, new CommandArguments(controller, "/foo"),
64 66
                 new CommandContext(null, AliasCommand.INFO));
65 67
 
66
-        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
68
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
67 69
     }
68 70
 
69 71
     @Test
@@ -71,7 +73,7 @@ public class AliasCommandTest {
71 73
         command.execute(tiw, new CommandArguments(controller, "/foo --remove"),
72 74
                 new CommandContext(null, AliasCommand.INFO));
73 75
 
74
-        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
76
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
75 77
     }
76 78
 
77 79
 }

+ 8
- 7
test/com/dmdirc/commandparser/commands/global/IfpluginTest.java Visa fil

@@ -21,10 +21,12 @@
21 21
  */
22 22
 package com.dmdirc.commandparser.commands.global;
23 23
 
24
+import com.dmdirc.DMDircMBassador;
24 25
 import com.dmdirc.GlobalWindow;
25 26
 import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.commands.context.CommandContext;
27 28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
+import com.dmdirc.events.CommandErrorEvent;
28 30
 import com.dmdirc.interfaces.CommandController;
29 31
 import com.dmdirc.interfaces.WindowModel;
30 32
 import com.dmdirc.plugins.PluginManager;
@@ -38,10 +40,9 @@ import org.junit.runner.RunWith;
38 40
 import org.mockito.Mock;
39 41
 import org.mockito.runners.MockitoJUnitRunner;
40 42
 
41
-import static org.mockito.Matchers.anyChar;
42
-import static org.mockito.Matchers.anyString;
43
-import static org.mockito.Matchers.eq;
43
+import static org.mockito.Matchers.isA;
44 44
 import static org.mockito.Mockito.verify;
45
+import static org.mockito.Mockito.when;
45 46
 
46 47
 @RunWith(MockitoJUnitRunner.class)
47 48
 public class IfpluginTest {
@@ -52,10 +53,12 @@ public class IfpluginTest {
52 53
     @Mock private CommandController controller;
53 54
     @Mock private PluginManager pluginManager;
54 55
     @Mock private WindowModel tiw;
56
+    @Mock private DMDircMBassador eventbus;
55 57
     private Ifplugin command;
56 58
 
57 59
     @Before
58 60
     public void setUp() {
61
+        when(tiw.getEventBus()).thenReturn(eventbus);
59 62
         command = new Ifplugin(controller, pluginManager, gcpProvider, gwProvider,
60 63
                 tabCompleterUtils);
61 64
     }
@@ -64,16 +67,14 @@ public class IfpluginTest {
64 67
     public void testUsageNoArgs() {
65 68
         command.execute(tiw, new CommandArguments(controller, "/foo"),
66 69
                 new CommandContext(null, Ifplugin.INFO));
67
-
68
-        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
70
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
69 71
     }
70 72
 
71 73
     @Test
72 74
     public void testUsageOneArg() {
73 75
         command.execute(tiw, new CommandArguments(controller, "/foo bar"),
74 76
                 new CommandContext(null, Ifplugin.INFO));
75
-
76
-        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
77
+        verify(eventbus).publishAsync(isA(CommandErrorEvent.class));
77 78
     }
78 79
 
79 80
 }

+ 1
- 1
test/com/dmdirc/commandparser/commands/global/NewServerTest.java Visa fil

@@ -106,7 +106,7 @@ public class NewServerTest {
106 106
         command.execute(container, new CommandArguments(controller, "/foo"),
107 107
                 new CommandContext(null, NewServer.INFO));
108 108
 
109
-        verify(container).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
109
+        verify(eventBus).publishAsync(isA(CommandErrorEvent.class));
110 110
     }
111 111
 
112 112
     @Test

+ 1
- 3
test/com/dmdirc/commandparser/commands/server/ChangeServerTest.java Visa fil

@@ -41,8 +41,6 @@ import org.junit.runner.RunWith;
41 41
 import org.mockito.Mock;
42 42
 import org.mockito.runners.MockitoJUnitRunner;
43 43
 
44
-import static org.mockito.Matchers.anyChar;
45
-import static org.mockito.Matchers.anyString;
46 44
 import static org.mockito.Matchers.eq;
47 45
 import static org.mockito.Matchers.isA;
48 46
 import static org.mockito.Matchers.same;
@@ -73,7 +71,7 @@ public class ChangeServerTest {
73 71
         command.execute(tiw, new CommandArguments(controller, "/server"),
74 72
                 new ServerCommandContext(null, ChangeServer.INFO, connection));
75 73
 
76
-        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
74
+        verify(eventBus).publishAsync(isA(CommandErrorEvent.class));
77 75
     }
78 76
 
79 77
     @Test

Laddar…
Avbryt
Spara