소스 검색

Remove more usages of Server.

This adds a sendLine method to Connection, which is a bit icky,
but is useful when the end-user is supplying lines to pass
directly to the underlying connection.
pull/242/head
Chris Smith 9 년 전
부모
커밋
d661e1efb0

+ 5
- 2
src/com/dmdirc/FrameContainerComparator.java 파일 보기

@@ -22,6 +22,9 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.interfaces.Connection;
26
+import com.dmdirc.interfaces.GroupChat;
27
+
25 28
 import java.io.Serializable;
26 29
 import java.util.Comparator;
27 30
 
@@ -108,11 +111,11 @@ public class FrameContainerComparator implements Comparator<FrameContainer>, Ser
108 111
     private static int getPosition(final FrameContainer item) {
109 112
         if (item instanceof GlobalWindow) {
110 113
             return 0;
111
-        } else if (item instanceof Server) {
114
+        } else if (item instanceof Connection) {
112 115
             return 1;
113 116
         } else if (item instanceof Raw) {
114 117
             return 2;
115
-        } else if (item instanceof Channel) {
118
+        } else if (item instanceof GroupChat) {
116 119
             return 3;
117 120
         } else if (item instanceof Query) {
118 121
             return 4;

+ 3
- 4
src/com/dmdirc/commandparser/parsers/ChannelCommandParser.java 파일 보기

@@ -25,7 +25,6 @@ package com.dmdirc.commandparser.parsers;
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.DMDircMBassador;
27 27
 import com.dmdirc.FrameContainer;
28
-import com.dmdirc.Server;
29 28
 import com.dmdirc.commandparser.CommandArguments;
30 29
 import com.dmdirc.commandparser.CommandInfo;
31 30
 import com.dmdirc.commandparser.CommandType;
@@ -51,13 +50,13 @@ public class ChannelCommandParser extends ChatCommandParser {
51 50
     /**
52 51
      * Creates a new instance of ChannelCommandParser.
53 52
      *
54
-     * @param server            The server this parser's query belongs to
53
+     * @param owner            The container this parser's query belongs to
55 54
      * @param commandController The controller to load commands from.
56 55
      * @param eventBus          Event bus to post events on
57 56
      */
58
-    public ChannelCommandParser(final Server server, final CommandController commandController,
57
+    public ChannelCommandParser(final FrameContainer owner, final CommandController commandController,
59 58
             final DMDircMBassador eventBus) {
60
-        super(server, commandController, eventBus);
59
+        super(owner, commandController, eventBus);
61 60
     }
62 61
 
63 62
     @Override

+ 4
- 5
src/com/dmdirc/commandparser/parsers/ChatCommandParser.java 파일 보기

@@ -25,7 +25,6 @@ package com.dmdirc.commandparser.parsers;
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.MessageTarget;
28
-import com.dmdirc.Server;
29 28
 import com.dmdirc.commandparser.CommandArguments;
30 29
 import com.dmdirc.commandparser.CommandInfo;
31 30
 import com.dmdirc.commandparser.CommandType;
@@ -51,14 +50,14 @@ public class ChatCommandParser extends ServerCommandParser {
51 50
     /**
52 51
      * Creates a new chat command parser that belongs to a child of the specified server.
53 52
      *
54
-     * @param server            The server which owns this parser's container
53
+     * @param owner             The container which owns this parser's container
55 54
      * @param commandController The controller to load commands from.
56 55
      * @param eventBus          Event but to post events on
57 56
      */
58
-    public ChatCommandParser(final Server server, final CommandController commandController,
57
+    public ChatCommandParser(final FrameContainer owner, final CommandController commandController,
59 58
             final DMDircMBassador eventBus) {
60
-        super(server.getConfigManager(), commandController, eventBus);
61
-        super.setOwner(server);
59
+        super(owner.getConfigManager(), commandController, eventBus);
60
+        super.setOwner(owner);
62 61
     }
63 62
 
64 63
     @Override

+ 1
- 2
src/com/dmdirc/commandparser/parsers/CommandParser.java 파일 보기

@@ -24,7 +24,6 @@ package com.dmdirc.commandparser.parsers;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27
-import com.dmdirc.Server;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29 28
 import com.dmdirc.commandparser.CommandInfo;
30 29
 import com.dmdirc.commandparser.CommandInfoPair;
@@ -216,7 +215,7 @@ public abstract class CommandParser implements Serializable {
216 215
 
217 216
                     if (actCommand != null && actCommand.getValue() instanceof ExternalCommand) {
218 217
                         ((ExternalCommand) actCommand.getValue()).execute(
219
-                                origin, (Server) server, channel, silent,
218
+                                origin, server, channel, silent,
220 219
                                 new CommandArguments(commandManager, newCommandString));
221 220
                     }
222 221
                 }

+ 3
- 4
src/com/dmdirc/commandparser/parsers/QueryCommandParser.java 파일 보기

@@ -25,7 +25,6 @@ package com.dmdirc.commandparser.parsers;
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.Query;
28
-import com.dmdirc.Server;
29 28
 import com.dmdirc.commandparser.CommandArguments;
30 29
 import com.dmdirc.commandparser.CommandInfo;
31 30
 import com.dmdirc.commandparser.CommandType;
@@ -52,13 +51,13 @@ public class QueryCommandParser extends ChatCommandParser {
52 51
     /**
53 52
      * Creates a new instance of QueryCommandParser.
54 53
      *
55
-     * @param server            The server this parser's query belongs to
54
+     * @param owner            The container this parser's query belongs to
56 55
      * @param commandController The controller to load commands from.
57 56
      * @param eventBus          Event bus to post events on
58 57
      */
59
-    public QueryCommandParser(final Server server, final CommandController commandController,
58
+    public QueryCommandParser(final FrameContainer owner, final CommandController commandController,
60 59
             final DMDircMBassador eventBus) {
61
-        super(server, commandController, eventBus);
60
+        super(owner, commandController, eventBus);
62 61
     }
63 62
 
64 63
     @Override

+ 4
- 4
src/com/dmdirc/commandparser/parsers/ServerCommandParser.java 파일 보기

@@ -24,7 +24,6 @@ package com.dmdirc.commandparser.parsers;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27
-import com.dmdirc.Server;
28 27
 import com.dmdirc.ServerState;
29 28
 import com.dmdirc.commandparser.CommandArguments;
30 29
 import com.dmdirc.commandparser.CommandInfo;
@@ -33,6 +32,7 @@ import com.dmdirc.commandparser.commands.Command;
33 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
34 33
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
35 34
 import com.dmdirc.interfaces.CommandController;
35
+import com.dmdirc.interfaces.Connection;
36 36
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
37 37
 
38 38
 import javax.annotation.Nonnull;
@@ -61,12 +61,12 @@ public class ServerCommandParser extends GlobalCommandParser {
61 61
     /**
62 62
      * The server instance that this parser is attached to.
63 63
      */
64
-    private Server server;
64
+    private Connection server;
65 65
 
66 66
     @Override
67 67
     public void setOwner(final FrameContainer owner) {
68
-        if (server == null && owner instanceof Server) {
69
-            server = (Server) owner;
68
+        if (server == null && owner instanceof Connection) {
69
+            server = (Connection) owner;
70 70
         }
71 71
 
72 72
         super.setOwner(owner);

+ 7
- 0
src/com/dmdirc/interfaces/Connection.java 파일 보기

@@ -496,4 +496,11 @@ public interface Connection {
496 496
      */
497 497
     FrameContainer getWindowModel();
498 498
 
499
+    /**
500
+     * Sends a raw line to the underlying connection.
501
+     *
502
+     * @param line The line to be sent
503
+     */
504
+    void sendLine(String line);
505
+
499 506
 }

+ 6
- 6
test/com/dmdirc/commandparser/commands/channel/ModeTest.java 파일 보기

@@ -24,11 +24,11 @@ package com.dmdirc.commandparser.commands.channel;
24 24
 
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.FrameContainer;
27
-import com.dmdirc.Server;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29 28
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
30 29
 import com.dmdirc.config.InvalidIdentityFileException;
31 30
 import com.dmdirc.interfaces.CommandController;
31
+import com.dmdirc.interfaces.Connection;
32 32
 import com.dmdirc.parser.interfaces.ChannelInfo;
33 33
 import com.dmdirc.parser.interfaces.Parser;
34 34
 
@@ -50,14 +50,14 @@ public class ModeTest {
50 50
     @Mock private CommandController controller;
51 51
     @Mock private ChannelInfo channelinfo;
52 52
     @Mock private Channel channel;
53
-    @Mock private Server server;
53
+    @Mock private Connection connection;
54 54
     @Mock private Parser parser;
55 55
     private Mode command;
56 56
 
57 57
     @Before
58 58
     public void setUp() throws InvalidIdentityFileException {
59
-        when(channel.getConnection()).thenReturn(Optional.of(server));
60
-        when(server.getParser()).thenReturn(Optional.of(parser));
59
+        when(channel.getConnection()).thenReturn(Optional.of(connection));
60
+        when(connection.getParser()).thenReturn(Optional.of(parser));
61 61
         when(channel.getChannelInfo()).thenReturn(channelinfo);
62 62
         when(channelinfo.getModes()).thenReturn("my mode string!");
63 63
         when(channelinfo.toString()).thenReturn("#chan");
@@ -83,7 +83,7 @@ public class ModeTest {
83 83
 
84 84
     @Test
85 85
     public void testExternalWithArgs() {
86
-        command.execute(origin, server, "#chan", false,
86
+        command.execute(origin, connection, "#chan", false,
87 87
                 new CommandArguments(controller, "/mode +hello -bye"));
88 88
 
89 89
         verify(parser).sendRawMessage("MODE #chan +hello -bye");
@@ -91,7 +91,7 @@ public class ModeTest {
91 91
 
92 92
     @Test
93 93
     public void testExternalWithoutArgs() {
94
-        command.execute(origin, server, "#chan", false,
94
+        command.execute(origin, connection, "#chan", false,
95 95
                 new CommandArguments(controller, "/mode"));
96 96
 
97 97
         verify(parser).sendRawMessage("MODE #chan");

+ 5
- 5
test/com/dmdirc/commandparser/commands/channel/NamesTest.java 파일 보기

@@ -23,11 +23,11 @@
23 23
 package com.dmdirc.commandparser.commands.channel;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.Server;
27 26
 import com.dmdirc.commandparser.CommandArguments;
28 27
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
29 28
 import com.dmdirc.config.InvalidIdentityFileException;
30 29
 import com.dmdirc.interfaces.CommandController;
30
+import com.dmdirc.interfaces.Connection;
31 31
 import com.dmdirc.parser.interfaces.ChannelInfo;
32 32
 import com.dmdirc.parser.interfaces.Parser;
33 33
 
@@ -48,15 +48,15 @@ public class NamesTest {
48 48
     @Mock private CommandController controller;
49 49
     @Mock private ChannelInfo channelinfo;
50 50
     @Mock private Channel channel;
51
-    @Mock private Server server;
51
+    @Mock private Connection connection;
52 52
     @Mock private Parser parser;
53 53
 
54 54
     private Names command;
55 55
 
56 56
     @Before
57 57
     public void setUp() throws InvalidIdentityFileException {
58
-        when(channel.getConnection()).thenReturn(Optional.of(server));
59
-        when(server.getParser()).thenReturn(Optional.of(parser));
58
+        when(channel.getConnection()).thenReturn(Optional.of(connection));
59
+        when(connection.getParser()).thenReturn(Optional.of(parser));
60 60
         when(channel.getChannelInfo()).thenReturn(channelinfo);
61 61
         when(channelinfo.getName()).thenReturn("#chan");
62 62
 
@@ -73,7 +73,7 @@ public class NamesTest {
73 73
 
74 74
     @Test
75 75
     public void testExternal() {
76
-        command.execute(null, server, "#chan", false,
76
+        command.execute(null, connection, "#chan", false,
77 77
                 new CommandArguments(controller, "/names #chan"));
78 78
 
79 79
         verify(parser).sendRawMessage("NAMES #chan");

+ 13
- 13
test/com/dmdirc/commandparser/commands/server/ChangeServerTest.java 파일 보기

@@ -22,11 +22,11 @@
22 22
 package com.dmdirc.commandparser.commands.server;
23 23
 
24 24
 import com.dmdirc.FrameContainer;
25
-import com.dmdirc.Server;
26 25
 import com.dmdirc.commandparser.CommandArguments;
27 26
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
28 27
 import com.dmdirc.config.profiles.Profile;
29 28
 import com.dmdirc.interfaces.CommandController;
29
+import com.dmdirc.interfaces.Connection;
30 30
 import com.dmdirc.logger.ErrorManager;
31 31
 import com.dmdirc.util.URIParser;
32 32
 
@@ -53,19 +53,19 @@ public class ChangeServerTest {
53 53
     @Mock private CommandController controller;
54 54
     @Mock private FrameContainer tiw;
55 55
     @Mock private Profile profile;
56
-    @Mock private Server server;
56
+    @Mock private Connection connection;
57 57
     private ChangeServer command;
58 58
 
59 59
     @Before
60 60
     public void setUp() {
61
-        when(server.getProfile()).thenReturn(profile);
61
+        when(connection.getProfile()).thenReturn(profile);
62 62
         command = new ChangeServer(controller, new URIParser());
63 63
     }
64 64
 
65 65
     @Test
66 66
     public void testUsageNoArgs() {
67 67
         command.execute(tiw, new CommandArguments(controller, "/server"),
68
-                new ServerCommandContext(null, ChangeServer.INFO, server));
68
+                new ServerCommandContext(null, ChangeServer.INFO, connection));
69 69
 
70 70
         verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
71 71
     }
@@ -73,7 +73,7 @@ public class ChangeServerTest {
73 73
     @Test
74 74
     public void testInvalidPort() {
75 75
         command.execute(tiw, new CommandArguments(controller, "/server foo:abc"),
76
-                new ServerCommandContext(null, ChangeServer.INFO, server));
76
+                new ServerCommandContext(null, ChangeServer.INFO, connection));
77 77
 
78 78
         verify(tiw).addLine(eq("commandError"), anyString());
79 79
     }
@@ -81,7 +81,7 @@ public class ChangeServerTest {
81 81
     @Test
82 82
     public void testOutOfRangePort1() {
83 83
         command.execute(tiw, new CommandArguments(controller, "/server foo:0"),
84
-                new ServerCommandContext(null, ChangeServer.INFO, server));
84
+                new ServerCommandContext(null, ChangeServer.INFO, connection));
85 85
 
86 86
         verify(tiw).addLine(eq("commandError"), anyString());
87 87
     }
@@ -89,7 +89,7 @@ public class ChangeServerTest {
89 89
     @Test
90 90
     public void testOutOfRangePort2() {
91 91
         command.execute(tiw, new CommandArguments(controller, "/server foo:65537"),
92
-                new ServerCommandContext(null, ChangeServer.INFO, server));
92
+                new ServerCommandContext(null, ChangeServer.INFO, connection));
93 93
 
94 94
         verify(tiw).addLine(eq("commandError"), anyString());
95 95
     }
@@ -97,25 +97,25 @@ public class ChangeServerTest {
97 97
     @Test
98 98
     public void testExecuteBasic() throws URISyntaxException {
99 99
         command.execute(tiw, new CommandArguments(controller, "/server foo:1234"),
100
-                new ServerCommandContext(null, ChangeServer.INFO, server));
100
+                new ServerCommandContext(null, ChangeServer.INFO, connection));
101 101
 
102
-        verify(server).connect(eq(new URI("irc://foo:1234")), same(profile));
102
+        verify(connection).connect(eq(new URI("irc://foo:1234")), same(profile));
103 103
     }
104 104
 
105 105
     @Test
106 106
     public void testExecuteNoPort() throws URISyntaxException {
107 107
         command.execute(tiw, new CommandArguments(controller, "/server foo"),
108
-                new ServerCommandContext(null, ChangeServer.INFO, server));
108
+                new ServerCommandContext(null, ChangeServer.INFO, connection));
109 109
 
110
-        verify(server).connect(eq(new URI("irc://foo")), same(profile));
110
+        verify(connection).connect(eq(new URI("irc://foo")), same(profile));
111 111
     }
112 112
 
113 113
     @Test
114 114
     public void testExecuteComplex() throws URISyntaxException {
115 115
         command.execute(tiw, new CommandArguments(controller, "/server foo:+1234 password"),
116
-                new ServerCommandContext(null, ChangeServer.INFO, server));
116
+                new ServerCommandContext(null, ChangeServer.INFO, connection));
117 117
 
118
-        verify(server).connect(eq(new URI("ircs://password@foo:1234")), same(profile));
118
+        verify(connection).connect(eq(new URI("ircs://password@foo:1234")), same(profile));
119 119
     }
120 120
 
121 121
 }

+ 4
- 4
test/com/dmdirc/ui/messages/IntelligentLinkingTest.java 파일 보기

@@ -22,7 +22,7 @@
22 22
 package com.dmdirc.ui.messages;
23 23
 
24 24
 import com.dmdirc.DMDircMBassador;
25
-import com.dmdirc.Server;
25
+import com.dmdirc.interfaces.Connection;
26 26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 27
 
28 28
 import java.util.Arrays;
@@ -49,10 +49,10 @@ public class IntelligentLinkingTest {
49 49
         this.expected = expected;
50 50
 
51 51
         final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
52
-        final Server server = mock(Server.class);
53
-        when(server.getChannelPrefixes()).thenReturn("#&+");
52
+        final Connection connection = mock(Connection.class);
53
+        when(connection.getChannelPrefixes()).thenReturn("#&+");
54 54
 
55
-        styliser = new Styliser(server, manager, new ColourManager(manager,
55
+        styliser = new Styliser(connection, manager, new ColourManager(manager,
56 56
                 mock(DMDircMBassador.class)));
57 57
     }
58 58
 

Loading…
취소
저장