|
@@ -1,144 +0,0 @@
|
1
|
|
-package com.dmdirc;
|
2
|
|
-
|
3
|
|
-import com.dmdirc.actions.ActionFactory;
|
4
|
|
-import com.dmdirc.actions.ActionGroup;
|
5
|
|
-import com.dmdirc.actions.ActionManager;
|
6
|
|
-import com.dmdirc.commandline.CommandLineParser;
|
7
|
|
-import com.dmdirc.commandparser.CommandManager;
|
8
|
|
-import com.dmdirc.config.IdentityManager;
|
9
|
|
-import com.dmdirc.config.InvalidIdentityFileException;
|
10
|
|
-import com.dmdirc.interfaces.ActionController;
|
11
|
|
-import com.dmdirc.interfaces.CommandController.CommandDetails;
|
12
|
|
-import com.dmdirc.interfaces.config.IdentityController;
|
13
|
|
-import com.dmdirc.plugins.PluginManager;
|
14
|
|
-import com.dmdirc.updater.manager.UpdateManager;
|
15
|
|
-import com.dmdirc.util.URLBuilder;
|
16
|
|
-
|
17
|
|
-import java.io.File;
|
18
|
|
-import java.io.IOException;
|
19
|
|
-import java.util.Collections;
|
20
|
|
-
|
21
|
|
-import javax.inject.Provider;
|
22
|
|
-import static org.mockito.Mockito.*;
|
23
|
|
-
|
24
|
|
-/**
|
25
|
|
- * Main subclass to init things needed for testing.
|
26
|
|
- *
|
27
|
|
- * @deprecated Tests shouldn't need the entire universe created.
|
28
|
|
- */
|
29
|
|
-@Deprecated
|
30
|
|
-public class TestMain extends Main {
|
31
|
|
-
|
32
|
|
- private static Main instance;
|
33
|
|
-
|
34
|
|
- private final IdentityManager identityManager;
|
35
|
|
- private final PluginManager pluginManager;
|
36
|
|
- private final CommandManager commandManager;
|
37
|
|
-
|
38
|
|
- public TestMain(final IdentityManager identityManager,
|
39
|
|
- final ServerManager serverManager,
|
40
|
|
- final ActionManager actionManager,
|
41
|
|
- final CommandLineParser commandLineParser,
|
42
|
|
- final PluginManager pluginManager,
|
43
|
|
- final CommandManager commandManager,
|
44
|
|
- final CorePluginExtractor corePluginExtractor) {
|
45
|
|
- super(identityManager, serverManager, actionManager, commandLineParser,
|
46
|
|
- pluginManager, commandManager, null, null, corePluginExtractor,
|
47
|
|
- mock(URLBuilder.class), Collections.<CommandDetails>emptySet());
|
48
|
|
- this.identityManager = identityManager;
|
49
|
|
- this.pluginManager = pluginManager;
|
50
|
|
- this.commandManager = commandManager;
|
51
|
|
- }
|
52
|
|
-
|
53
|
|
- /** {@inheritDoc} */
|
54
|
|
- @Override
|
55
|
|
- public void init() {
|
56
|
|
- try {
|
57
|
|
- identityManager.initialise();
|
58
|
|
- } catch (InvalidIdentityFileException ex) {
|
59
|
|
- // If a bad config dir exists, try to continue anyway, maybe the
|
60
|
|
- // test doesn't need it.
|
61
|
|
- // DON'T do anything to the user's configuration... (so no calls
|
62
|
|
- // to handleInvalidConfigFile(); here)
|
63
|
|
- }
|
64
|
|
-
|
65
|
|
- pluginManager.refreshPlugins();
|
66
|
|
- commandManager.initialise(identityManager.getGlobalConfiguration());
|
67
|
|
- CommandManager.setCommandManager(commandManager);
|
68
|
|
-
|
69
|
|
- ActionManager.getActionManager().initialise();
|
70
|
|
- }
|
71
|
|
-
|
72
|
|
- /**
|
73
|
|
- * Singleton method for convenience so that we don't need to init a billion
|
74
|
|
- * TestMain instances to run tests.
|
75
|
|
- *
|
76
|
|
- * Separate instances of TestMain are available, but probably pointless as
|
77
|
|
- * long as IdentityManager, PluginManager and ConfigManater are still
|
78
|
|
- * singletons.
|
79
|
|
- *
|
80
|
|
- * @return A Singleton instance of TestMain
|
81
|
|
- */
|
82
|
|
- public static Main getTestMain() {
|
83
|
|
- if (instance == null) {
|
84
|
|
- try {
|
85
|
|
- File tempFile = File.createTempFile("dmdirc", "test");
|
86
|
|
- tempFile.delete();
|
87
|
|
- tempFile.mkdir();
|
88
|
|
- tempFile.deleteOnExit();
|
89
|
|
-
|
90
|
|
- final String configDirectory = tempFile.getAbsolutePath() + File.separator;
|
91
|
|
- final String pluginDirectory = configDirectory + "plugins" + File.separator;
|
92
|
|
- final String actionsDirectory = configDirectory + "actions" + File.separator;
|
93
|
|
-
|
94
|
|
- // TODO: Tests probably shouldn't rely on a config dir... Who knows
|
95
|
|
- // what the user has done with their config.
|
96
|
|
- final IdentityManager identityManager = new IdentityManager(configDirectory);
|
97
|
|
- IdentityManager.setIdentityManager(identityManager);
|
98
|
|
- IdentityManager.getIdentityManager().loadVersionIdentity();
|
99
|
|
-
|
100
|
|
- final ServerManager serverManager = mock(ServerManager.class);
|
101
|
|
- final CommandManager commandManager = new CommandManager(serverManager);
|
102
|
|
-
|
103
|
|
- final ActionFactory actionFactory = new ActionFactory(
|
104
|
|
- new DummyProvider<>(mock(ActionController.class)),
|
105
|
|
- new DummyProvider<IdentityController>(identityManager),
|
106
|
|
- actionsDirectory);
|
107
|
|
- final ActionManager actionManager = new ActionManager(
|
108
|
|
- serverManager, identityManager, actionFactory,
|
109
|
|
- new DummyProvider<>(Collections.<ActionGroup>emptySet()));
|
110
|
|
- ActionManager.setActionManager(actionManager);
|
111
|
|
-
|
112
|
|
- final PluginManager pluginManager = new PluginManager(
|
113
|
|
- identityManager, actionManager,
|
114
|
|
- mock(UpdateManager.class),
|
115
|
|
- mock(Provider.class),
|
116
|
|
- pluginDirectory);
|
117
|
|
- final CorePluginExtractor corePluginExtractor =
|
118
|
|
- new CorePluginExtractor(pluginManager, pluginDirectory);
|
119
|
|
-
|
120
|
|
- instance = new TestMain(identityManager, serverManager,
|
121
|
|
- actionManager, null, pluginManager, commandManager,
|
122
|
|
- corePluginExtractor);
|
123
|
|
- instance.init();
|
124
|
|
- } catch (IOException ex) {
|
125
|
|
- // Blargh.
|
126
|
|
- }
|
127
|
|
- }
|
128
|
|
- return instance;
|
129
|
|
- }
|
130
|
|
-
|
131
|
|
- private static class DummyProvider<T> implements Provider<T> {
|
132
|
|
-
|
133
|
|
- private final T value;
|
134
|
|
-
|
135
|
|
- public DummyProvider(T value) {
|
136
|
|
- this.value = value;
|
137
|
|
- }
|
138
|
|
-
|
139
|
|
- @Override
|
140
|
|
- public T get() {
|
141
|
|
- return value;
|
142
|
|
- }
|
143
|
|
- }
|
144
|
|
-}
|