You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestMain.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.dmdirc;
  2. import com.dmdirc.actions.ActionManager;
  3. import com.dmdirc.commandparser.CommandManager;
  4. import com.dmdirc.config.IdentityManager;
  5. import com.dmdirc.config.InvalidIdentityFileException;
  6. import com.dmdirc.plugins.PluginManager;
  7. /**
  8. * Main subclass to init things needed for testing.
  9. */
  10. public class TestMain extends Main {
  11. private static Main instance;
  12. public TestMain() { }
  13. /** {@inheritDoc} */
  14. @Override
  15. public void init(final String[] args) {
  16. // TODO: Tests probably shouldn't rely on a config dir... Who knows
  17. // what the user has done with their config.
  18. IdentityManager.getIdentityManager().loadVersionIdentity();
  19. try {
  20. IdentityManager.getIdentityManager().initialise(getConfigDir());
  21. } catch (InvalidIdentityFileException ex) {
  22. // If a bad config dir exists, try to continue anyway, maybe the
  23. // test doesn't need it.
  24. // DON'T do anything to the user's configuration... (so no calls
  25. // to handleInvalidConfigFile(); here)
  26. }
  27. serverManager = new ServerManager(this);
  28. ActionManager.initActionManager(this, serverManager, IdentityManager.getIdentityManager());
  29. pluginManager = new PluginManager(IdentityManager.getIdentityManager(), this);
  30. pluginManager.refreshPlugins();
  31. CommandManager.initCommandManager(IdentityManager.getIdentityManager(), this);
  32. ActionManager.getActionManager().initialise();
  33. }
  34. /**
  35. * Singleton method for convenience so that we don't need to init a billion
  36. * TestMain instances to run tests.
  37. *
  38. * Separate instances of TestMain are available, but probably pointless as
  39. * long as IdentityManager, PluginManager and ConfigManater are still
  40. * singletons.
  41. *
  42. * @return A Singleton instance of TestMain
  43. */
  44. public static Main getTestMain() {
  45. if (instance == null) {
  46. instance = new TestMain();
  47. instance.init(new String[0]);
  48. }
  49. return instance;
  50. }
  51. }