Kaynağa Gözat

De-singleton + unit test

Change-Id: Iadcf92d4390034828d005a9c9e92d9a8ba189c99
Depends-On: I17790a0e71a6c004a088a6eb51332293b23062a4
Reviewed-on: http://gerrit.dmdirc.com/2455
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 12 yıl önce
ebeveyn
işleme
ab45825e88

+ 2
- 1
src/com/dmdirc/GlobalWindow.java Dosyayı Görüntüle

@@ -136,7 +136,8 @@ public class GlobalWindow extends WritableFrameContainer {
136 136
             if (configManager.getOptionBool("general", "showglobalwindow")) {
137 137
                 if (globalWindow == null) {
138 138
                     globalWindow = new GlobalWindow(configManager,
139
-                            GlobalCommandParser.getGlobalCommandParser());
139
+                            new GlobalCommandParser(configManager,
140
+                            CommandManager.getCommandManager()));
140 141
                 }
141 142
             } else {
142 143
                 if (globalWindow != null) {

+ 1
- 1
src/com/dmdirc/Raw.java Dosyayı Görüntüle

@@ -53,7 +53,7 @@ public final class Raw extends WritableFrameContainer
53 53
      */
54 54
     public Raw(final Server newServer) {
55 55
         super("raw", "Raw", "(Raw log)", newServer.getConfigManager(),
56
-                new ServerCommandParser(),
56
+                new ServerCommandParser(newServer.getConfigManager()),
57 57
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
58 58
                 WindowComponent.INPUTFIELD.getIdentifier()));
59 59
 

+ 2
- 1
src/com/dmdirc/Server.java Dosyayı Görüntüle

@@ -194,7 +194,8 @@ public class Server extends WritableFrameContainer
194 194
     public Server(final URI uri, final Identity profile) {
195 195
         super("server-disconnected", getHost(uri), getHost(uri),
196 196
                 new ConfigManager(uri.getScheme(), "", "", uri.getHost()),
197
-                new ServerCommandParser(),
197
+                new ServerCommandParser(
198
+                new ConfigManager(uri.getScheme(), "", "", uri.getHost())),
198 199
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
199 200
                 WindowComponent.INPUTFIELD.getIdentifier(),
200 201
                 WindowComponent.CERTIFICATE_VIEWER.getIdentifier()));

+ 5
- 2
src/com/dmdirc/actions/ActionModel.java Dosyayı Görüntüle

@@ -25,8 +25,10 @@ package com.dmdirc.actions;
25 25
 import com.dmdirc.Precondition;
26 26
 import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.WritableFrameContainer;
28
+import com.dmdirc.commandparser.CommandManager;
28 29
 import com.dmdirc.commandparser.parsers.CommandParser;
29 30
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
31
+import com.dmdirc.config.IdentityManager;
30 32
 import com.dmdirc.interfaces.actions.ActionType;
31 33
 
32 34
 import java.util.ArrayList;
@@ -141,7 +143,7 @@ public class ActionModel {
141 143
         }
142 144
 
143 145
         WritableFrameContainer container = null;
144
-        CommandParser cp = null;
146
+        CommandParser cp;
145 147
 
146 148
         if (arguments.length > 0
147 149
                 && arguments[0] instanceof WritableFrameContainer) {
@@ -151,7 +153,8 @@ public class ActionModel {
151 153
         }
152 154
 
153 155
         if (container == null) {
154
-            cp = GlobalCommandParser.getGlobalCommandParser();
156
+            cp = new GlobalCommandParser(IdentityManager.getIdentityManager()
157
+                    .getGlobalConfiguration(), CommandManager.getCommandManager());
155 158
         } else {
156 159
             cp = container.getCommandParser();
157 160
         }

+ 1
- 1
src/com/dmdirc/commandparser/CommandArguments.java Dosyayı Görüntüle

@@ -72,7 +72,7 @@ public class CommandArguments {
72 72
         this.line = line;
73 73
     }
74 74
 
75
-   /**
75
+    /**
76 76
      * Creates a new command arguments parser for the specified words.
77 77
      *
78 78
      * @param words The words which form the line ot be parsed

+ 7
- 4
src/com/dmdirc/commandparser/CommandManager.java Dosyayı Görüntüle

@@ -50,8 +50,7 @@ import lombok.Getter;
50 50
 public class CommandManager implements CommandController {
51 51
 
52 52
     /** A singleton instance of the command manager. */
53
-    private static final CommandManager INSTANCE
54
-            = new CommandManager(IdentityManager.getIdentityManager().getGlobalConfiguration());
53
+    private static CommandManager instance;
55 54
 
56 55
     /** A list of commands that have been instantiated. */
57 56
     private final Map<CommandInfo, Command> commands
@@ -282,8 +281,12 @@ public class CommandManager implements CommandController {
282 281
      *
283 282
      * @return A singleton instance of the CommandManager.
284 283
      */
285
-    public static CommandManager getCommandManager() {
286
-        return INSTANCE;
284
+    public static synchronized CommandManager getCommandManager() {
285
+        if (instance == null) {
286
+            instance = new CommandManager(IdentityManager.getIdentityManager()
287
+                    .getGlobalConfiguration());
288
+        }
289
+        return instance;
287 290
     }
288 291
 
289 292
 }

+ 12
- 0
src/com/dmdirc/commandparser/commands/global/Echo.java Dosyayı Görüntüle

@@ -35,6 +35,7 @@ import com.dmdirc.commandparser.commands.context.CommandContext;
35 35
 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
+import com.dmdirc.interfaces.CommandController;
38 39
 import com.dmdirc.ui.WindowManager;
39 40
 import com.dmdirc.ui.input.AdditionalTabTargets;
40 41
 
@@ -69,6 +70,17 @@ public class Echo extends Command implements IntelligentCommand {
69 70
         handler = new CommandFlagHandler(timeStampFlag, targetFlag);
70 71
     }
71 72
 
73
+    /**
74
+     * Creates a new instance of Echo.
75
+     *
76
+     * @param controller Command controller
77
+     */
78
+    public Echo(final CommandController controller) {
79
+        super(controller);
80
+
81
+        handler = new CommandFlagHandler(timeStampFlag, targetFlag);
82
+    }
83
+
72 84
     /** {@inheritDoc} */
73 85
     @Override
74 86
     public void execute(final FrameContainer origin,

+ 4
- 2
src/com/dmdirc/commandparser/commands/global/Ifplugin.java Dosyayı Görüntüle

@@ -27,6 +27,7 @@ import com.dmdirc.WritableFrameContainer;
27 27
 import com.dmdirc.commandparser.BaseCommandInfo;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.CommandInfo;
30
+import com.dmdirc.commandparser.CommandManager;
30 31
 import com.dmdirc.commandparser.CommandType;
31 32
 import com.dmdirc.commandparser.commands.Command;
32 33
 import com.dmdirc.commandparser.commands.IntelligentCommand;
@@ -72,8 +73,9 @@ public class Ifplugin extends Command implements IntelligentCommand {
72 73
 
73 74
         if (result != negative) {
74 75
             if (origin == null) {
75
-                GlobalCommandParser.getGlobalCommandParser().parseCommand(null,
76
-                        args.getArgumentsAsString(1));
76
+                new GlobalCommandParser(origin.getConfigManager(),
77
+                        CommandManager.getCommandManager()).parseCommand(
78
+                        null, args.getArgumentsAsString(1));
77 79
             } else {
78 80
                 ((WritableFrameContainer) origin).getCommandParser()
79 81
                         .parseCommand(origin, args.getArgumentsAsString(1));

+ 1
- 0
src/com/dmdirc/commandparser/parsers/ChatCommandParser.java Dosyayı Görüntüle

@@ -56,6 +56,7 @@ public class ChatCommandParser extends ServerCommandParser {
56 56
      * @param server The server which owns this parser's container
57 57
      */
58 58
     public ChatCommandParser(final Server server) {
59
+        super(server.getConfigManager());
59 60
         super.setOwner(server);
60 61
     }
61 62
 

+ 10
- 6
src/com/dmdirc/commandparser/parsers/CommandParser.java Dosyayı Görüntüle

@@ -35,13 +35,15 @@ import com.dmdirc.commandparser.commands.Command;
35 35
 import com.dmdirc.commandparser.commands.CommandOptions;
36 36
 import com.dmdirc.commandparser.commands.ExternalCommand;
37 37
 import com.dmdirc.commandparser.commands.PreviousCommand;
38
-import com.dmdirc.config.IdentityManager;
38
+import com.dmdirc.config.ConfigManager;
39 39
 import com.dmdirc.util.collections.RollingList;
40 40
 
41 41
 import java.io.Serializable;
42 42
 import java.util.HashMap;
43 43
 import java.util.Map;
44 44
 
45
+import lombok.Getter;
46
+
45 47
 /**
46 48
  * Represents a generic command parser. A command parser takes a line of input
47 49
  * from the user, determines if it is an attempt at executing a command (based
@@ -67,14 +69,16 @@ public abstract class CommandParser implements Serializable {
67 69
     private final RollingList<PreviousCommand> history;
68 70
 
69 71
     /** Command manager to use. */
70
-    protected final CommandManager commandManager = CommandManager.getCommandManager();
72
+    @Getter
73
+    protected final CommandManager commandManager;
71 74
 
72 75
     /** Creates a new instance of CommandParser. */
73
-    protected CommandParser() {
76
+    protected CommandParser(final ConfigManager configManager,
77
+            final CommandManager commandManager) {
74 78
         commands = new HashMap<String, CommandInfoPair>();
75
-        history = new RollingList<PreviousCommand>(IdentityManager
76
-                .getIdentityManager().getGlobalConfiguration()
79
+        history = new RollingList<PreviousCommand>(configManager
77 80
                 .getOptionInt("general", "commandhistory"));
81
+        this.commandManager = commandManager;
78 82
         loadCommands();
79 83
     }
80 84
 
@@ -131,7 +135,7 @@ public abstract class CommandParser implements Serializable {
131 135
      */
132 136
     public final void parseCommand(final FrameContainer origin,
133 137
             final String line, final boolean parseChannel) {
134
-        final CommandArguments args = new CommandArguments(line);
138
+        final CommandArguments args = new CommandArguments(getCommandManager(), line);
135 139
 
136 140
         if (args.isCommand()) {
137 141
             if (handleChannelCommand(origin, args, parseChannel)) {

+ 10
- 14
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java Dosyayı Görüntüle

@@ -25,9 +25,11 @@ package com.dmdirc.commandparser.parsers;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandInfo;
28
+import com.dmdirc.commandparser.CommandManager;
28 29
 import com.dmdirc.commandparser.CommandType;
29 30
 import com.dmdirc.commandparser.commands.Command;
30 31
 import com.dmdirc.commandparser.commands.context.CommandContext;
32
+import com.dmdirc.config.ConfigManager;
31 33
 import com.dmdirc.logger.ErrorLevel;
32 34
 import com.dmdirc.logger.Logger;
33 35
 
@@ -44,9 +46,15 @@ public class GlobalCommandParser extends CommandParser {
44 46
     private static final long serialVersionUID = 1;
45 47
 
46 48
     /**
47
-     * The singleton instance of this command parser.
49
+     * Creates a new command parser for global commands.
50
+     *
51
+     * @param configManager Config manager to read settings from
52
+     * @param commandManager Command manager to load commands from
48 53
      */
49
-    private static GlobalCommandParser me;
54
+    public GlobalCommandParser(final ConfigManager configManager,
55
+            final CommandManager commandManager) {
56
+        super(configManager, commandManager);
57
+    }
50 58
 
51 59
     /** {@inheritDoc} */
52 60
     @Override
@@ -54,18 +62,6 @@ public class GlobalCommandParser extends CommandParser {
54 62
         // Don't care
55 63
     }
56 64
 
57
-    /**
58
-     * Retrieves a singleton instance of the global command parser.
59
-     * @return A GlobalCommandParser
60
-     */
61
-    public static synchronized GlobalCommandParser getGlobalCommandParser() {
62
-        if (me == null) {
63
-            me = new GlobalCommandParser();
64
-        }
65
-
66
-        return me;
67
-    }
68
-
69 65
     /** Loads the relevant commands into the parser. */
70 66
     @Override
71 67
     protected void loadCommands() {

+ 11
- 0
src/com/dmdirc/commandparser/parsers/ServerCommandParser.java Dosyayı Görüntüle

@@ -27,9 +27,11 @@ import com.dmdirc.Server;
27 27
 import com.dmdirc.ServerState;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.CommandInfo;
30
+import com.dmdirc.commandparser.CommandManager;
30 31
 import com.dmdirc.commandparser.CommandType;
31 32
 import com.dmdirc.commandparser.commands.Command;
32 33
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
34
+import com.dmdirc.config.ConfigManager;
33 35
 
34 36
 /**
35 37
  * A command parser used in the context of a server.
@@ -43,6 +45,15 @@ public class ServerCommandParser extends GlobalCommandParser {
43 45
      */
44 46
     private static final long serialVersionUID = 1;
45 47
 
48
+    /**
49
+     * Creates a new command parser for server commands.
50
+     *
51
+     * @param configManager Config manager to read settings from
52
+     */
53
+    public ServerCommandParser(final ConfigManager configManager) {
54
+        super(configManager, CommandManager.getCommandManager());
55
+    }
56
+
46 57
     /**
47 58
      * The server instance that this parser is attached to.
48 59
      */

+ 18
- 7
test/com/dmdirc/WritableFrameContainerTest.java Dosyayı Görüntüle

@@ -22,28 +22,39 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
-import com.dmdirc.config.IdentityManager;
25
+import com.dmdirc.commandparser.CommandManager;
26
+import com.dmdirc.config.ConfigBinder;
27
+import com.dmdirc.config.ConfigManager;
26 28
 import com.dmdirc.config.InvalidIdentityFileException;
27 29
 import com.dmdirc.harness.TestWritableFrameContainer;
28 30
 
29 31
 import java.util.Arrays;
30 32
 
31
-import org.junit.BeforeClass;
33
+import org.junit.Before;
32 34
 import org.junit.Test;
33 35
 
34 36
 import static org.junit.Assert.*;
37
+import static org.mockito.Mockito.*;
35 38
 
36 39
 public class WritableFrameContainerTest {
37 40
 
38
-    @BeforeClass
39
-    public static void setupClass() throws InvalidIdentityFileException {
40
-        IdentityManager.getIdentityManager().initialise();
41
+    private ConfigManager cm;
42
+    private CommandManager commands;
43
+
44
+    @Before
45
+    public void setup() throws InvalidIdentityFileException {
46
+        cm = mock(ConfigManager.class);
47
+        when(cm.getOption("general", "silencechar")).thenReturn(".");
48
+        when(cm.getOption("general", "commandchar")).thenReturn("/");
49
+        final ConfigBinder binder = new ConfigBinder(cm);
50
+        when(cm.getBinder()).thenReturn(binder);
51
+        commands = new CommandManager(cm);
41 52
     }
42 53
 
43 54
     @Test
44 55
     public void testGetNumLines() {
45 56
         final WritableFrameContainer container10
46
-                = new TestWritableFrameContainer(10);
57
+                = new TestWritableFrameContainer(10, cm, commands);
47 58
 
48 59
         final int res0a = container10.getNumLines("");
49 60
         final int res0b = container10.getNumLines("\r");
@@ -73,7 +84,7 @@ public class WritableFrameContainerTest {
73 84
     @Test
74 85
     public void testSplitLine() {
75 86
         final WritableFrameContainer container10
76
-                = new TestWritableFrameContainer(10);
87
+                = new TestWritableFrameContainer(10, cm, commands);
77 88
         final String[][][] tests = new String[][][]{
78 89
             {{""}, {""}},
79 90
             {{"0123456789"}, {"0123456789"}},

+ 27
- 15
test/com/dmdirc/commandparser/parsers/CommandParserTest.java Dosyayı Görüntüle

@@ -23,25 +23,37 @@ package com.dmdirc.commandparser.parsers;
23 23
 
24 24
 import com.dmdirc.commandparser.CommandManager;
25 25
 import com.dmdirc.commandparser.commands.global.Echo;
26
-import com.dmdirc.config.IdentityManager;
26
+import com.dmdirc.config.ConfigBinder;
27
+import com.dmdirc.config.ConfigManager;
28
+import com.dmdirc.config.InvalidIdentityFileException;
27 29
 import com.dmdirc.harness.TestCommandParser;
28 30
 
29
-import org.junit.BeforeClass;
31
+import org.junit.Before;
30 32
 import org.junit.Test;
31 33
 
32 34
 import static org.junit.Assert.*;
35
+import static org.mockito.Mockito.*;
33 36
 
34 37
 public class CommandParserTest {
35 38
 
36
-    @BeforeClass
37
-    public static void setUpClass() throws Exception {
38
-        IdentityManager.getIdentityManager().initialise();
39
-        CommandManager.getCommandManager().registerCommand(new Echo(), Echo.INFO);
39
+    private ConfigManager cm;
40
+    private CommandManager commands;
41
+
42
+    @Before
43
+    public void setup() throws InvalidIdentityFileException {
44
+        cm = mock(ConfigManager.class);
45
+        when(cm.getOptionChar("general", "silencechar")).thenReturn('.');
46
+        when(cm.getOptionInt("general", "commandhistory")).thenReturn(10);
47
+        when(cm.getOptionChar("general", "commandchar")).thenReturn('/');
48
+        final ConfigBinder binder = new ConfigBinder(cm);
49
+        when(cm.getBinder()).thenReturn(binder);
50
+        commands = new CommandManager(cm);
51
+        commands.registerCommand(new Echo(commands), Echo.INFO);
40 52
     }
41 53
 
42 54
     @Test
43 55
     public void testBasicCommand() {
44
-        final TestCommandParser tcp = new TestCommandParser();
56
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
45 57
         tcp.parseCommand(null, "/echo this is a test");
46 58
 
47 59
         assertNull(tcp.nonCommandLine);
@@ -53,7 +65,7 @@ public class CommandParserTest {
53 65
 
54 66
     @Test
55 67
     public void testBasicNoArgs() {
56
-        final TestCommandParser tcp = new TestCommandParser();
68
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
57 69
         tcp.parseCommand(null, "/echo");
58 70
 
59 71
         assertNull(tcp.nonCommandLine);
@@ -65,7 +77,7 @@ public class CommandParserTest {
65 77
 
66 78
     @Test
67 79
     public void testSilentNoArgs() {
68
-        final TestCommandParser tcp = new TestCommandParser();
80
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
69 81
         tcp.parseCommand(null, "/.echo");
70 82
 
71 83
         assertNull(tcp.nonCommandLine);
@@ -77,7 +89,7 @@ public class CommandParserTest {
77 89
 
78 90
     @Test
79 91
     public void testSilentCommand() {
80
-        final TestCommandParser tcp = new TestCommandParser();
92
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
81 93
         tcp.parseCommand(null, "/.echo this is a test");
82 94
 
83 95
         assertNull(tcp.nonCommandLine);
@@ -89,7 +101,7 @@ public class CommandParserTest {
89 101
 
90 102
     @Test
91 103
     public void testNonExistantCommand() {
92
-        final TestCommandParser tcp = new TestCommandParser();
104
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
93 105
         tcp.parseCommand(null, "/foobar moo bar");
94 106
 
95 107
         assertNull(tcp.nonCommandLine);
@@ -101,7 +113,7 @@ public class CommandParserTest {
101 113
 
102 114
     @Test
103 115
     public void testEmptyCommand() {
104
-        final TestCommandParser tcp = new TestCommandParser();
116
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
105 117
         tcp.parseCommand(null, "/ moo bar");
106 118
 
107 119
         assertNull(tcp.nonCommandLine);
@@ -113,7 +125,7 @@ public class CommandParserTest {
113 125
 
114 126
     @Test
115 127
     public void testEmptySilentCommand() {
116
-        final TestCommandParser tcp = new TestCommandParser();
128
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
117 129
         tcp.parseCommand(null, "/. moo bar");
118 130
 
119 131
         assertNull(tcp.nonCommandLine);
@@ -125,7 +137,7 @@ public class CommandParserTest {
125 137
 
126 138
     @Test
127 139
     public void testNonCommand() {
128
-        final TestCommandParser tcp = new TestCommandParser();
140
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
129 141
         tcp.parseCommand(null, "Foobar baz");
130 142
 
131 143
         assertNotNull(tcp.nonCommandLine);
@@ -137,7 +149,7 @@ public class CommandParserTest {
137 149
 
138 150
     @Test
139 151
     public void testCommandHistory() {
140
-        final TestCommandParser tcp = new TestCommandParser();
152
+        final TestCommandParser tcp = new TestCommandParser(cm, commands);
141 153
         tcp.parseCommand(null, "/echo this is a test");
142 154
 
143 155
         final long time1 = tcp.getCommandTime("echo this is a test");

+ 0
- 48
test/com/dmdirc/commandparser/parsers/GlobalCommandParserTest.java Dosyayı Görüntüle

@@ -1,48 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2012 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.commandparser.parsers;
24
-
25
-import com.dmdirc.config.IdentityManager;
26
-
27
-import org.junit.BeforeClass;
28
-import org.junit.Test;
29
-
30
-import static org.junit.Assert.*;
31
-
32
-public class GlobalCommandParserTest {
33
-
34
-    @BeforeClass
35
-    public static void setUp() throws Exception {
36
-        IdentityManager.getIdentityManager().initialise();
37
-    }
38
-
39
-    @Test
40
-    public void testGetGlobalCommandParser() {
41
-        final GlobalCommandParser p1 = GlobalCommandParser.getGlobalCommandParser();
42
-
43
-        final GlobalCommandParser p2 = GlobalCommandParser.getGlobalCommandParser();
44
-
45
-        assertSame(p1, p2);
46
-    }
47
-
48
-}

+ 12
- 1
test/com/dmdirc/harness/TestCommandParser.java Dosyayı Görüntüle

@@ -29,10 +29,15 @@ import com.dmdirc.commandparser.CommandManager;
29 29
 import com.dmdirc.commandparser.CommandType;
30 30
 import com.dmdirc.commandparser.commands.Command;
31 31
 import com.dmdirc.commandparser.parsers.*;
32
+import com.dmdirc.config.ConfigManager;
33
+
34
+import lombok.ToString;
32 35
 
33 36
 public class TestCommandParser extends CommandParser {
34 37
     private static final long serialVersionUID = 7073002401375438532L;
35 38
 
39
+    private final ConfigManager configManager;
40
+
36 41
     public String nonCommandLine;
37 42
 
38 43
     public Command executedCommand;
@@ -43,9 +48,15 @@ public class TestCommandParser extends CommandParser {
43 48
 
44 49
     public String invalidCommand;
45 50
 
51
+    public TestCommandParser(final ConfigManager configManager,
52
+            final CommandManager commandManager) {
53
+        super(configManager, commandManager);
54
+        this.configManager = configManager;
55
+    }
56
+
46 57
     @Override
47 58
     protected void loadCommands() {
48
-        CommandManager.getCommandManager().loadCommands(this, CommandType.TYPE_GLOBAL);
59
+        commandManager.loadCommands(this, CommandType.TYPE_GLOBAL);
49 60
     }
50 61
 
51 62
     @Override

+ 5
- 9
test/com/dmdirc/harness/TestWritableFrameContainer.java Dosyayı Görüntüle

@@ -24,9 +24,9 @@ package com.dmdirc.harness;
24 24
 
25 25
 import com.dmdirc.Server;
26 26
 import com.dmdirc.WritableFrameContainer;
27
+import com.dmdirc.commandparser.CommandManager;
27 28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
28 29
 import com.dmdirc.config.ConfigManager;
29
-import com.dmdirc.config.IdentityManager;
30 30
 import com.dmdirc.ui.input.TabCompleter;
31 31
 
32 32
 import java.util.Collections;
@@ -36,18 +36,14 @@ public class TestWritableFrameContainer extends WritableFrameContainer {
36 36
     private final int lineLength;
37 37
 
38 38
     public TestWritableFrameContainer(final int lineLength,
39
-            final ConfigManager cm) {
39
+            final ConfigManager cm, final CommandManager commandManager) {
40 40
         super("raw", "Raw", "(Raw)", cm,
41
-                GlobalCommandParser.getGlobalCommandParser(),
41
+                new GlobalCommandParser(cm, commandManager),
42 42
                 Collections.<String>emptySet());
43 43
 
44 44
         this.lineLength = lineLength;
45 45
     }
46 46
 
47
-    public TestWritableFrameContainer(final int lineLength) {
48
-        this(lineLength, IdentityManager.getIdentityManager().getGlobalConfiguration());
49
-    }
50
-
51 47
     @Override
52 48
     public void sendLine(final String line) {
53 49
         // Do nothing
@@ -60,12 +56,12 @@ public class TestWritableFrameContainer extends WritableFrameContainer {
60 56
 
61 57
     @Override
62 58
     public void windowClosing() {
63
-        System.out.println("windowClosing");
59
+        // Do nothing
64 60
     }
65 61
 
66 62
     @Override
67 63
     public void windowClosed() {
68
-        // DO nothing
64
+        // Do nothing
69 65
     }
70 66
 
71 67
     @Override

+ 21
- 13
test/com/dmdirc/ui/WindowManagerTest.java Dosyayı Görüntüle

@@ -24,7 +24,9 @@ package com.dmdirc.ui;
24 24
 import com.dmdirc.CustomWindow;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.addons.ui_dummy.DummyInputWindow;
27
-import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.config.ConfigBinder;
29
+import com.dmdirc.config.ConfigManager;
28 30
 import com.dmdirc.config.InvalidIdentityFileException;
29 31
 import com.dmdirc.harness.TestWritableFrameContainer;
30 32
 import com.dmdirc.interfaces.ui.FrameListener;
@@ -33,7 +35,7 @@ import com.dmdirc.interfaces.ui.Window;
33 35
 import java.util.Arrays;
34 36
 import java.util.Collection;
35 37
 
36
-import org.junit.BeforeClass;
38
+import org.junit.Before;
37 39
 import org.junit.Test;
38 40
 
39 41
 import static org.junit.Assert.*;
@@ -41,16 +43,22 @@ import static org.mockito.Mockito.*;
41 43
 
42 44
 public class WindowManagerTest {
43 45
 
44
-    @BeforeClass
45
-    public static void setupClass() throws InvalidIdentityFileException {
46
-        IdentityManager.getIdentityManager().initialise();
46
+    private ConfigManager cm;
47
+    private CommandManager commands;
48
+
49
+    @Before
50
+    public void setup() throws InvalidIdentityFileException {
51
+        cm = mock(ConfigManager.class);
52
+        final ConfigBinder binder = new ConfigBinder(cm);
53
+        when(cm.getBinder()).thenReturn(binder);
54
+        commands = new CommandManager(cm);
47 55
     }
48 56
 
49 57
     @Test
50 58
     public void testAddRoot() {
51 59
         final WindowManager manager = new WindowManager();
52 60
         final FrameListener tfm = mock(FrameListener.class);
53
-        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512));
61
+        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
54 62
 
55 63
         manager.addListener(tfm);
56 64
 
@@ -67,8 +75,8 @@ public class WindowManagerTest {
67 75
     public void testAddChild() {
68 76
         final WindowManager manager = new WindowManager();
69 77
         final FrameListener tfm = mock(FrameListener.class);
70
-        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512));
71
-        final Window child = new DummyInputWindow(new TestWritableFrameContainer(512));
78
+        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
79
+        final Window child = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
72 80
         manager.addWindow(parent.getContainer());
73 81
         manager.addListener(tfm);
74 82
 
@@ -82,7 +90,7 @@ public class WindowManagerTest {
82 90
     public void testRemoveRoot() {
83 91
         final WindowManager manager = new WindowManager();
84 92
         final FrameListener tfm = mock(FrameListener.class);
85
-        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512));
93
+        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
86 94
         manager.addWindow(parent.getContainer());
87 95
         manager.addListener(tfm);
88 96
 
@@ -95,8 +103,8 @@ public class WindowManagerTest {
95 103
     public void testRemoveChild() {
96 104
         final WindowManager manager = new WindowManager();
97 105
         final FrameListener tfm = mock(FrameListener.class);
98
-        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512));
99
-        final Window child = new DummyInputWindow(new TestWritableFrameContainer(512));
106
+        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
107
+        final Window child = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
100 108
         manager.addWindow(parent.getContainer());
101 109
         manager.addWindow(parent.getContainer(), child.getContainer());
102 110
         manager.addListener(tfm);
@@ -113,8 +121,8 @@ public class WindowManagerTest {
113 121
     public void testRemoveFrameManager() {
114 122
         final WindowManager manager = new WindowManager();
115 123
         final FrameListener tfm = mock(FrameListener.class);
116
-        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512));
117
-        final Window child = new DummyInputWindow(new TestWritableFrameContainer(512));
124
+        final Window parent = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
125
+        final Window child = new DummyInputWindow(new TestWritableFrameContainer(512, cm, commands));
118 126
         manager.addWindow(parent.getContainer());
119 127
 
120 128
         manager.addListener(tfm);

Loading…
İptal
Kaydet