Преглед изворни кода

Fix various deprecated uses.

Change-Id: I0bb97a8946d1c217de82fe2a9b8f35b7d49eae06
pull/210/head
Chris Smith пре 9 година
родитељ
комит
31a78eb743
28 измењених фајлова са 85 додато и 46 уклоњено
  1. 1
    0
      src/com/dmdirc/Channel.java
  2. 1
    0
      src/com/dmdirc/CustomWindow.java
  3. 1
    0
      src/com/dmdirc/GlobalWindow.java
  4. 1
    0
      src/com/dmdirc/Query.java
  5. 1
    0
      src/com/dmdirc/Raw.java
  6. 1
    0
      src/com/dmdirc/Server.java
  7. 2
    1
      src/com/dmdirc/commandparser/aliases/Alias.java
  8. 6
    1
      src/com/dmdirc/commandparser/commands/context/ChatCommandContext.java
  9. 1
    1
      src/com/dmdirc/commandparser/commands/global/Clear.java
  10. 8
    5
      src/com/dmdirc/commandparser/commands/global/Echo.java
  11. 6
    2
      src/com/dmdirc/commandparser/commands/global/OpenWindow.java
  12. 7
    4
      src/com/dmdirc/commandparser/commands/global/SetCommand.java
  13. 2
    2
      src/com/dmdirc/commandparser/commands/server/Ignore.java
  14. 2
    2
      src/com/dmdirc/commandparser/commands/server/JoinChannelCommand.java
  15. 1
    1
      src/com/dmdirc/commandparser/commands/server/Message.java
  16. 2
    6
      src/com/dmdirc/commandparser/commands/server/OpenQuery.java
  17. 3
    1
      src/com/dmdirc/events/ErrorEvent.java
  18. 1
    1
      src/com/dmdirc/ui/messages/sink/AllMessageSink.java
  19. 4
    2
      src/com/dmdirc/ui/messages/sink/ChannelMessageSink.java
  20. 4
    2
      src/com/dmdirc/ui/messages/sink/CommonChannelsMessageSink.java
  21. 5
    3
      src/com/dmdirc/ui/messages/sink/CustomWindowMessageSink.java
  22. 7
    6
      src/com/dmdirc/ui/messages/sink/LastCommandMessageSink.java
  23. 1
    1
      src/com/dmdirc/ui/messages/sink/ServerMessageSink.java
  24. 0
    1
      test/com/dmdirc/actions/ActionSubstitutorTest.java
  25. 4
    0
      test/com/dmdirc/commandparser/commands/channel/BanTest.java
  26. 8
    0
      test/com/dmdirc/commandparser/commands/channel/KickReasonTest.java
  27. 4
    4
      test/com/dmdirc/commandparser/parsers/CommandParserTest.java
  28. 1
    0
      test/com/dmdirc/harness/TestWritableFrameContainer.java

+ 1
- 0
src/com/dmdirc/Channel.java Прегледај датотеку

@@ -550,6 +550,7 @@ public class Channel extends MessageTarget implements GroupChat {
550 550
     }
551 551
 
552 552
     @Override
553
+    @Deprecated
553 554
     @Nonnull
554 555
     public Connection getConnection() {
555 556
         return server;

+ 1
- 0
src/com/dmdirc/CustomWindow.java Прегледај датотеку

@@ -65,6 +65,7 @@ public class CustomWindow extends FrameContainer {
65 65
     }
66 66
 
67 67
     @Override
68
+    @Deprecated
68 69
     public Connection getConnection() {
69 70
         return getOptionalConnection().orElse(null);
70 71
     }

+ 1
- 0
src/com/dmdirc/GlobalWindow.java Прегледај датотеку

@@ -64,6 +64,7 @@ public class GlobalWindow extends FrameContainer {
64 64
     }
65 65
 
66 66
     @Override
67
+    @Deprecated
67 68
     public Connection getConnection() {
68 69
         return null;
69 70
     }

+ 1
- 0
src/com/dmdirc/Query.java Прегледај датотеку

@@ -288,6 +288,7 @@ public class Query extends MessageTarget implements PrivateActionListener,
288 288
 
289 289
     @Nonnull
290 290
     @Override
291
+    @Deprecated
291 292
     public Connection getConnection() {
292 293
         return server;
293 294
     }

+ 1
- 0
src/com/dmdirc/Raw.java Прегледај датотеку

@@ -114,6 +114,7 @@ public class Raw extends FrameContainer implements DataInListener, DataOutListen
114 114
     }
115 115
 
116 116
     @Nonnull
117
+    @Deprecated
117 118
     @Override
118 119
     public Connection getConnection() {
119 120
         return server;

+ 1
- 0
src/com/dmdirc/Server.java Прегледај датотеку

@@ -1039,6 +1039,7 @@ public class Server extends FrameContainer implements ConfigChangeListener,
1039 1039
     }
1040 1040
 
1041 1041
     @Nonnull
1042
+    @Deprecated
1042 1043
     @Override
1043 1044
     public Connection getConnection() {
1044 1045
         return this;

+ 2
- 1
src/com/dmdirc/commandparser/aliases/Alias.java Прегледај датотеку

@@ -25,6 +25,7 @@ package com.dmdirc.commandparser.aliases;
25 25
 import com.dmdirc.commandparser.CommandInfo;
26 26
 import com.dmdirc.commandparser.CommandType;
27 27
 
28
+import com.google.common.base.MoreObjects;
28 29
 import com.google.common.base.Objects;
29 30
 
30 31
 /**
@@ -94,7 +95,7 @@ public class Alias implements CommandInfo {
94 95
 
95 96
     @Override
96 97
     public String toString() {
97
-        return Objects.toStringHelper(this)
98
+        return MoreObjects.toStringHelper(this)
98 99
                 .add("name", name)
99 100
                 .add("minargs", minArguments)
100 101
                 .add("substitution", substitution)

+ 6
- 1
src/com/dmdirc/commandparser/commands/context/ChatCommandContext.java Прегледај датотеку

@@ -26,6 +26,8 @@ import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.MessageTarget;
27 27
 import com.dmdirc.commandparser.CommandInfo;
28 28
 
29
+import java.util.Optional;
30
+
29 31
 /**
30 32
  * A command context specific to chat windows.
31 33
  *
@@ -45,7 +47,10 @@ public class ChatCommandContext extends ServerCommandContext {
45 47
      */
46 48
     public ChatCommandContext(final FrameContainer source,
47 49
             final CommandInfo commandInfo, final MessageTarget chat) {
48
-        super(source, commandInfo, chat.getConnection());
50
+        super(source, commandInfo,
51
+                Optional.ofNullable(source)
52
+                        .flatMap(FrameContainer::getOptionalConnection)
53
+                        .orElse(null));
49 54
         this.chat = chat;
50 55
     }
51 56
 

+ 1
- 1
src/com/dmdirc/commandparser/commands/global/Clear.java Прегледај датотеку

@@ -59,7 +59,7 @@ public class Clear extends Command implements IntelligentCommand {
59 59
     @Override
60 60
     public void execute(@Nonnull final FrameContainer origin,
61 61
             final CommandArguments args, final CommandContext context) {
62
-        origin.getDocument().clear();
62
+        origin.getBackBuffer().getDocument().clear();
63 63
     }
64 64
 
65 65
     @Override

+ 8
- 5
src/com/dmdirc/commandparser/commands/global/Echo.java Прегледај датотеку

@@ -36,10 +36,12 @@ import com.dmdirc.commandparser.commands.flags.CommandFlag;
36 36
 import com.dmdirc.commandparser.commands.flags.CommandFlagHandler;
37 37
 import com.dmdirc.commandparser.commands.flags.CommandFlagResult;
38 38
 import com.dmdirc.interfaces.CommandController;
39
+import com.dmdirc.interfaces.Connection;
39 40
 import com.dmdirc.ui.WindowManager;
40 41
 import com.dmdirc.ui.input.AdditionalTabTargets;
41 42
 
42 43
 import java.util.ArrayList;
44
+import java.util.Collection;
43 45
 import java.util.Date;
44 46
 import java.util.List;
45 47
 import java.util.Optional;
@@ -138,16 +140,17 @@ public class Echo extends Command implements IntelligentCommand {
138 140
                 || (arg == 3 && context.getPreviousArgs().get(2).equals("--target")
139 141
                 && context.getPreviousArgs().get(0).equals("--ts"))) {
140 142
 
141
-            final List<FrameContainer> windowList = new ArrayList<>();
142
-            final Server currentServer = (Server) context.getWindow().getConnection();
143
+            final Collection<FrameContainer> windowList = new ArrayList<>();
144
+            final Optional<Connection> connection = context.getWindow().getOptionalConnection();
143 145
 
144 146
             //Active window's Children
145 147
             windowList.addAll(context.getWindow().getChildren());
146 148
 
147 149
             //Children of Current Window's server
148
-            if (currentServer != null) {
149
-                windowList.addAll(currentServer.getChildren());
150
-            }
150
+            connection
151
+                    .map(c -> (Server) c)
152
+                    .map(Server::getChildren)
153
+                    .ifPresent(windowList::addAll);
151 154
 
152 155
             //Global Windows
153 156
             windowList.addAll(windowManager.getRootWindows());

+ 6
- 2
src/com/dmdirc/commandparser/commands/global/OpenWindow.java Прегледај датотеку

@@ -34,12 +34,15 @@ import com.dmdirc.commandparser.commands.Command;
34 34
 import com.dmdirc.commandparser.commands.IntelligentCommand;
35 35
 import com.dmdirc.commandparser.commands.context.CommandContext;
36 36
 import com.dmdirc.interfaces.CommandController;
37
+import com.dmdirc.interfaces.Connection;
37 38
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
38 39
 import com.dmdirc.ui.WindowManager;
39 40
 import com.dmdirc.ui.messages.BackBufferFactory;
40 41
 import com.dmdirc.ui.input.AdditionalTabTargets;
41 42
 import com.dmdirc.util.URLBuilder;
42 43
 
44
+import java.util.Optional;
45
+
43 46
 import javax.annotation.Nonnull;
44 47
 import javax.inject.Inject;
45 48
 
@@ -91,13 +94,14 @@ public class OpenWindow extends Command implements IntelligentCommand {
91 94
         FrameContainer parent = null;
92 95
 
93 96
         if (args.getArguments().length > 0 && "--server".equals(args.getArguments()[0])) {
94
-            if (origin.getConnection() == null) {
97
+            final Optional<Connection> connection = origin.getOptionalConnection();
98
+            if (!connection.isPresent()) {
95 99
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
96 100
                         "This window doesn't have an associated server.");
97 101
                 return;
98 102
             }
99 103
 
100
-            parent = (FrameContainer) origin.getConnection();
104
+            parent = connection.get().getWindowModel();
101 105
             start = 1;
102 106
         } else if (args.getArguments().length > 0 && "--child".equals(args.getArguments()[0])) {
103 107
             parent = origin;

+ 7
- 4
src/com/dmdirc/commandparser/commands/global/SetCommand.java Прегледај датотеку

@@ -36,6 +36,7 @@ import com.dmdirc.commandparser.commands.flags.CommandFlag;
36 36
 import com.dmdirc.commandparser.commands.flags.CommandFlagHandler;
37 37
 import com.dmdirc.commandparser.commands.flags.CommandFlagResult;
38 38
 import com.dmdirc.interfaces.CommandController;
39
+import com.dmdirc.interfaces.Connection;
39 40
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
40 41
 import com.dmdirc.interfaces.config.ConfigProvider;
41 42
 import com.dmdirc.interfaces.config.IdentityController;
@@ -44,6 +45,7 @@ import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
44 45
 import com.dmdirc.ui.input.AdditionalTabTargets;
45 46
 
46 47
 import java.util.List;
48
+import java.util.Optional;
47 49
 
48 50
 import javax.annotation.Nonnull;
49 51
 import javax.annotation.Nullable;
@@ -112,16 +114,17 @@ public class SetCommand extends Command implements IntelligentCommand {
112 114
 
113 115
         ConfigProvider identity = identityController.getUserSettings();
114 116
         AggregateConfigProvider manager = identityController.getGlobalConfiguration();
117
+        final Optional<Connection> connection = origin.getOptionalConnection();
115 118
 
116 119
         if (res.hasFlag(serverFlag)) {
117
-            if (origin.getConnection() == null) {
120
+            if (!connection.isPresent()) {
118 121
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
119 122
                         "Cannot use --server in this context");
120 123
                 return;
121 124
             }
122 125
 
123
-            identity = origin.getConnection().getServerIdentity();
124
-            manager = ((FrameContainer) origin.getConnection()).getConfigManager();
126
+            identity = connection.get().getServerIdentity();
127
+            manager = connection.get().getWindowModel().getConfigManager();
125 128
         }
126 129
 
127 130
         if (res.hasFlag(channelFlag)) {
@@ -133,7 +136,7 @@ public class SetCommand extends Command implements IntelligentCommand {
133 136
 
134 137
             final Channel channel = ((ChannelCommandContext) context).getChannel();
135 138
             identity = identityFactory.createChannelConfig(
136
-                    origin.getConnection().getNetwork(), channel.getName());
139
+                    connection.get().getNetwork(), channel.getName());
137 140
             manager = channel.getConfigManager();
138 141
         }
139 142
 

+ 2
- 2
src/com/dmdirc/commandparser/commands/server/Ignore.java Прегледај датотеку

@@ -185,8 +185,8 @@ public class Ignore extends Command implements IntelligentCommand {
185 185
             targets.include(TabCompletionType.CHANNEL_NICK);
186 186
             targets.include(TabCompletionType.QUERY_NICK);
187 187
         } else if (arg == 1 && "--remove".equals(context.getPreviousArgs().get(0))) {
188
-            final IgnoreList ignoreList = context.getWindow().getConnection()
189
-                    .getIgnoreList();
188
+            final IgnoreList ignoreList = context.getWindow().getOptionalConnection()
189
+                    .get().getIgnoreList();
190 190
             if (ignoreList.canConvert()) {
191 191
                 targets.addAll(ignoreList.getSimpleList().stream().collect(Collectors.toList()));
192 192
             }

+ 2
- 2
src/com/dmdirc/commandparser/commands/server/JoinChannelCommand.java Прегледај датотеку

@@ -105,7 +105,7 @@ public class JoinChannelCommand extends Command implements IntelligentCommand {
105 105
 
106 106
     @Handler
107 107
     public void handleClientLineAdded(final ClientLineAddedEvent event) {
108
-        final String[] parts = event.getFrameContainer().getStyliser()
108
+        final String[] parts = event.getFrameContainer().getBackBuffer().getStyliser()
109 109
                 .doLinks(event.getLine())
110 110
                 .split(Character.toString(Styliser.CODE_CHANNEL));
111 111
 
@@ -119,7 +119,7 @@ public class JoinChannelCommand extends Command implements IntelligentCommand {
119 119
     public AdditionalTabTargets getSuggestions(final int arg,
120 120
             final IntelligentCommandContext context) {
121 121
         final FrameContainer source = context.getWindow();
122
-        final Connection connection = source.getConnection();
122
+        final Connection connection = source.getOptionalConnection().get();
123 123
         final List<String> results = checkSource(source, true, true);
124 124
 
125 125
         final AdditionalTabTargets targets = new AdditionalTabTargets().excludeAll();

+ 1
- 1
src/com/dmdirc/commandparser/commands/server/Message.java Прегледај датотеку

@@ -116,7 +116,7 @@ public class Message extends Command implements IntelligentCommand,
116 116
     public int getLineCount(final FrameContainer origin, final CommandArguments arguments) {
117 117
         if (arguments.getArguments().length >= 2) {
118 118
             final String target = arguments.getArguments()[0];
119
-            return origin.getConnection().getWindowModel().getNumLines(
119
+            return origin.getOptionalConnection().get().getWindowModel().getNumLines(
120 120
                     "PRIVMSG " + target + " :" + arguments.getArgumentsAsString(1));
121 121
         } else {
122 122
             return 1;

+ 2
- 6
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Прегледај датотеку

@@ -89,11 +89,7 @@ public class OpenQuery extends Command implements IntelligentCommand,
89 89
             query.sendLine(args.getArgumentsAsString(1), args.getArguments()[0]);
90 90
         }
91 91
 
92
-        if (!args.isSilent()) {
93
-            //TODO how are we going to handle focusing an existing query?
94
-            //context.getSource().getController().requestWindowFocus(query);
95
-            return; //NOPMD
96
-        }
92
+        // TODO: Focus if the command isn't silent
97 93
     }
98 94
 
99 95
     @Override
@@ -113,7 +109,7 @@ public class OpenQuery extends Command implements IntelligentCommand,
113 109
     public int getLineCount(final FrameContainer origin, final CommandArguments arguments) {
114 110
         if (arguments.getArguments().length >= 2) {
115 111
             final String target = arguments.getArguments()[0];
116
-            return origin.getConnection().getWindowModel().getNumLines("PRIVMSG "
112
+            return origin.getOptionalConnection().get().getWindowModel().getNumLines("PRIVMSG "
117 113
                     + target + " :" + arguments.getArgumentsAsString(1));
118 114
         } else {
119 115
             return 1;

+ 3
- 1
src/com/dmdirc/events/ErrorEvent.java Прегледај датотеку

@@ -24,6 +24,7 @@ package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.logger.ErrorLevel;
26 26
 
27
+import com.google.common.base.MoreObjects;
27 28
 import com.google.common.base.Objects;
28 29
 
29 30
 public abstract class ErrorEvent extends DMDircEvent {
@@ -69,8 +70,9 @@ public abstract class ErrorEvent extends DMDircEvent {
69 70
         this.handled = true;
70 71
     }
71 72
 
73
+    @Override
72 74
     public String toString() {
73
-        return Objects.toStringHelper(getClass())
75
+        return MoreObjects.toStringHelper(getClass())
74 76
                 .add("Level", getLevel())
75 77
                 .add("Message", getMessage())
76 78
                 .add("Details", getDetails())

+ 1
- 1
src/com/dmdirc/ui/messages/sink/AllMessageSink.java Прегледај датотеку

@@ -51,7 +51,7 @@ public class AllMessageSink implements MessageSink {
51 51
             final FrameContainer source,
52 52
             final String[] patternMatches, final Date date,
53 53
             final String messageType, final Object... args) {
54
-        source.getConnection().addLineToAll(messageType, date, args);
54
+        source.getOptionalConnection().get().addLineToAll(messageType, date, args);
55 55
     }
56 56
 
57 57
 }

+ 4
- 2
src/com/dmdirc/ui/messages/sink/ChannelMessageSink.java Прегледај датотеку

@@ -24,6 +24,7 @@ package com.dmdirc.ui.messages.sink;
24 24
 
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.FrameContainer;
27
+import com.dmdirc.interfaces.Connection;
27 28
 
28 29
 import java.util.Date;
29 30
 import java.util.regex.Pattern;
@@ -57,8 +58,9 @@ public class ChannelMessageSink implements MessageSink {
57 58
         final String user = String.format(patternMatches[0], args);
58 59
         boolean found = false;
59 60
 
60
-        for (String channelName : source.getConnection().getChannels()) {
61
-            final Channel channel = source.getConnection().getChannel(channelName);
61
+        final Connection connection = source.getOptionalConnection().get();
62
+        for (String channelName : connection.getChannels()) {
63
+            final Channel channel = connection.getChannel(channelName);
62 64
             if (channel.getChannelInfo().getChannelClient(user) != null) {
63 65
                 channel.addLine(messageType, date, args);
64 66
                 found = true;

+ 4
- 2
src/com/dmdirc/ui/messages/sink/CommonChannelsMessageSink.java Прегледај датотеку

@@ -24,6 +24,7 @@ package com.dmdirc.ui.messages.sink;
24 24
 
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.FrameContainer;
27
+import com.dmdirc.interfaces.Connection;
27 28
 
28 29
 import java.util.Date;
29 30
 import java.util.regex.Pattern;
@@ -56,10 +57,11 @@ public class CommonChannelsMessageSink implements MessageSink {
56 57
             final String[] patternMatches, final Date date,
57 58
             final String messageType, final Object... args) {
58 59
         final String user = String.format(patternMatches[0], args);
60
+        final Connection connection = source.getOptionalConnection().get();
59 61
         boolean found = false;
60 62
 
61
-        for (String channelName : source.getConnection().getChannels()) {
62
-            final Channel channel = source.getConnection().getChannel(channelName);
63
+        for (String channelName : connection.getChannels()) {
64
+            final Channel channel = connection.getChannel(channelName);
63 65
             if (channel.getChannelInfo().getChannelClient(user) != null) {
64 66
                 channel.addLine(messageType, date, args);
65 67
                 found = true;

+ 5
- 3
src/com/dmdirc/ui/messages/sink/CustomWindowMessageSink.java Прегледај датотеку

@@ -71,13 +71,15 @@ public class CustomWindowMessageSink implements MessageSink {
71 71
             final FrameContainer source,
72 72
             final String[] patternMatches, final Date date,
73 73
             final String messageType, final Object... args) {
74
+        final FrameContainer connectionContainer = source.getOptionalConnection()
75
+                .get().getWindowModel();
74 76
         FrameContainer targetWindow = windowManager
75
-                .findCustomWindow((Server) source.getConnection(), patternMatches[0]);
77
+                .findCustomWindow(connectionContainer, patternMatches[0]);
76 78
 
77 79
         if (targetWindow == null) {
78 80
             targetWindow = new CustomWindow(patternMatches[0], patternMatches[0],
79
-                    (Server) source.getConnection(), urlBuilder, backBufferFactory);
80
-            windowManager.addWindow((Server) source.getConnection(), targetWindow);
81
+                    connectionContainer, urlBuilder, backBufferFactory);
82
+            windowManager.addWindow(connectionContainer, targetWindow);
81 83
         }
82 84
 
83 85
         targetWindow.addLine(messageType, date, args);

+ 7
- 6
src/com/dmdirc/ui/messages/sink/LastCommandMessageSink.java Прегледај датотеку

@@ -23,11 +23,10 @@
23 23
 package com.dmdirc.ui.messages.sink;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.Server;
27 26
 
28 27
 import java.util.ArrayList;
28
+import java.util.Collection;
29 29
 import java.util.Date;
30
-import java.util.List;
31 30
 import java.util.regex.Pattern;
32 31
 
33 32
 import javax.inject.Inject;
@@ -64,13 +63,15 @@ public class LastCommandMessageSink implements MessageSink {
64 63
         final String command = String.format(patternMatches[0], escapedargs);
65 64
 
66 65
         FrameContainer best = source;
67
-        long besttime = 0;
68 66
 
69
-        final List<FrameContainer> containers = new ArrayList<>();
67
+        final Collection<FrameContainer> containers = new ArrayList<>();
70 68
 
71
-        containers.add((Server) source.getConnection());
72
-        containers.addAll(((Server) source.getConnection()).getChildren());
69
+        final FrameContainer connectionContainer = source.getOptionalConnection()
70
+                .get().getWindowModel();
71
+        containers.add(connectionContainer);
72
+        containers.addAll(connectionContainer.getChildren());
73 73
 
74
+        long besttime = 0;
74 75
         for (FrameContainer container : containers) {
75 76
             if (!container.isWritable()) {
76 77
                 continue;

+ 1
- 1
src/com/dmdirc/ui/messages/sink/ServerMessageSink.java Прегледај датотеку

@@ -52,7 +52,7 @@ public class ServerMessageSink implements MessageSink {
52 52
             final FrameContainer source,
53 53
             final String[] patternMatches, final Date date,
54 54
             final String messageType, final Object... args) {
55
-        ((Server) source.getConnection()).addLine(messageType, date, args);
55
+        source.getOptionalConnection().get().getWindowModel().addLine(messageType, date, args);
56 56
     }
57 57
 
58 58
 }

+ 0
- 1
test/com/dmdirc/actions/ActionSubstitutorTest.java Прегледај датотеку

@@ -75,7 +75,6 @@ public class ActionSubstitutorTest {
75 75
 
76 76
         final ChannelClientInfo clientInfo = mock(ChannelClientInfo.class);
77 77
 
78
-        when(channel.getConnection()).thenReturn(server);
79 78
         when(channel.getOptionalConnection()).thenReturn(Optional.of(server));
80 79
         when(channel.getConfigManager()).thenReturn(manager);
81 80
         when(server.getState()).thenReturn(ServerState.DISCONNECTED);

+ 4
- 0
test/com/dmdirc/commandparser/commands/channel/BanTest.java Прегледај датотеку

@@ -31,6 +31,8 @@ import com.dmdirc.parser.interfaces.ChannelClientInfo;
31 31
 import com.dmdirc.parser.interfaces.ChannelInfo;
32 32
 import com.dmdirc.parser.interfaces.ClientInfo;
33 33
 
34
+import java.util.Optional;
35
+
34 36
 import org.junit.Before;
35 37
 import org.junit.Test;
36 38
 import org.junit.runner.RunWith;
@@ -75,6 +77,7 @@ public class BanTest {
75 77
         when(channelInfo.getChannelClient("user")).thenReturn(ccInfo);
76 78
         when(ccInfo.getClient()).thenReturn(clientInfo);
77 79
         when(clientInfo.getHostname()).thenReturn("my.host.name");
80
+        when(container.getOptionalConnection()).thenReturn(Optional.empty());
78 81
 
79 82
         command.execute(container, new CommandArguments(controller, "/ban user"),
80 83
                 new ChannelCommandContext(null, Ban.INFO, channel));
@@ -91,6 +94,7 @@ public class BanTest {
91 94
         final Channel channel = mock(Channel.class);
92 95
 
93 96
         when(channel.getChannelInfo()).thenReturn(channelInfo);
97
+        when(container.getOptionalConnection()).thenReturn(Optional.empty());
94 98
 
95 99
         command.execute(container, new CommandArguments(controller, "/ban *!*@my.host.name"),
96 100
                 new ChannelCommandContext(null, Ban.INFO, channel));

+ 8
- 0
test/com/dmdirc/commandparser/commands/channel/KickReasonTest.java Прегледај датотеку

@@ -31,6 +31,8 @@ import com.dmdirc.interfaces.config.AggregateConfigProvider;
31 31
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
32 32
 import com.dmdirc.parser.interfaces.ChannelInfo;
33 33
 
34
+import java.util.Optional;
35
+
34 36
 import org.junit.Before;
35 37
 import org.junit.Test;
36 38
 import org.junit.runner.RunWith;
@@ -62,6 +64,9 @@ public class KickReasonTest {
62 64
     public void testUsage() {
63 65
         final FrameContainer tiw = mock(FrameContainer.class);
64 66
         final Channel channel = mock(Channel.class);
67
+
68
+        when(tiw.getOptionalConnection()).thenReturn(Optional.empty());
69
+
65 70
         command.execute(tiw, new CommandArguments(controller, "/kick"),
66 71
                 new ChannelCommandContext(null, KickReason.INFO, channel));
67 72
 
@@ -76,6 +81,7 @@ public class KickReasonTest {
76 81
 
77 82
         when(channel.getChannelInfo()).thenReturn(channelInfo);
78 83
         when(channelInfo.getChannelClient(anyString())).thenReturn(null);
84
+        when(tiw.getOptionalConnection()).thenReturn(Optional.empty());
79 85
 
80 86
         command.execute(tiw, new CommandArguments(controller, "/kick user1"),
81 87
                 new ChannelCommandContext(null, KickReason.INFO, channel));
@@ -92,6 +98,7 @@ public class KickReasonTest {
92 98
 
93 99
         when(channel.getChannelInfo()).thenReturn(channelInfo);
94 100
         when(channelInfo.getChannelClient("user1")).thenReturn(cci);
101
+        when(tiw.getOptionalConnection()).thenReturn(Optional.empty());
95 102
 
96 103
         command.execute(tiw, new CommandArguments(controller, "/kick user1 reason here"),
97 104
                 new ChannelCommandContext(null, KickReason.INFO, channel));
@@ -111,6 +118,7 @@ public class KickReasonTest {
111 118
         when(channel.getChannelInfo()).thenReturn(channelInfo);
112 119
         when(channelInfo.getChannelClient("user1")).thenReturn(cci);
113 120
         when(manager.getOption("general", "kickmessage")).thenReturn("reason here");
121
+        when(tiw.getOptionalConnection()).thenReturn(Optional.empty());
114 122
 
115 123
         command.execute(tiw, new CommandArguments(controller, "/kick user1"),
116 124
                 new ChannelCommandContext(null, KickReason.INFO, channel));

+ 4
- 4
test/com/dmdirc/commandparser/parsers/CommandParserTest.java Прегледај датотеку

@@ -191,7 +191,7 @@ public class CommandParserTest {
191 191
 
192 192
     @Test
193 193
     public void testParseChannelCommandWithArguments() {
194
-        when(container.getConnection()).thenReturn(connection);
194
+        when(container.getOptionalConnection()).thenReturn(Optional.of(connection));
195 195
         commandParser.parseCommand(container, "/channel #channel1 this is a test");
196 196
 
197 197
         assertNull(channelCommandParser.nonCommandLine);
@@ -203,7 +203,7 @@ public class CommandParserTest {
203 203
 
204 204
     @Test
205 205
     public void testParseChannelCommandWithoutArguments() {
206
-        when(container.getConnection()).thenReturn(connection);
206
+        when(container.getOptionalConnection()).thenReturn(Optional.of(connection));
207 207
         commandParser.parseCommand(container, "/channel #channel1");
208 208
 
209 209
         assertNull(channelCommandParser.nonCommandLine);
@@ -215,7 +215,7 @@ public class CommandParserTest {
215 215
 
216 216
     @Test
217 217
     public void testParseSilencedChannelCommandWithArguments() {
218
-        when(container.getConnection()).thenReturn(connection);
218
+        when(container.getOptionalConnection()).thenReturn(Optional.of(connection));
219 219
         commandParser.parseCommand(container, "/.channel #channel1 this is a test");
220 220
 
221 221
         assertNull(channelCommandParser.nonCommandLine);
@@ -227,7 +227,7 @@ public class CommandParserTest {
227 227
 
228 228
     @Test
229 229
     public void testParseSilencedChannelCommandWithoutArguments() {
230
-        when(container.getConnection()).thenReturn(connection);
230
+        when(container.getOptionalConnection()).thenReturn(Optional.of(connection));
231 231
         commandParser.parseCommand(container, "/.channel #channel1");
232 232
 
233 233
         assertNull(channelCommandParser.nonCommandLine);

+ 1
- 0
test/com/dmdirc/harness/TestWritableFrameContainer.java Прегледај датотеку

@@ -69,6 +69,7 @@ public class TestWritableFrameContainer extends FrameContainer {
69 69
     }
70 70
 
71 71
     @Override
72
+    @Deprecated
72 73
     public Connection getConnection() {
73 74
         return null;
74 75
     }

Loading…
Откажи
Сачувај