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.

ActionManagerTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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. package com.dmdirc.actions;
  23. import com.dmdirc.actions.interfaces.ActionType;
  24. import java.io.File;
  25. import java.util.ArrayList;
  26. import org.junit.AfterClass;
  27. import org.junit.BeforeClass;
  28. import org.junit.Test;
  29. import static org.junit.Assert.*;
  30. public class ActionManagerTest extends junit.framework.TestCase {
  31. @BeforeClass
  32. public void setUpClass() throws Exception {
  33. ActionManager.init();
  34. tearDownClass();
  35. }
  36. @AfterClass
  37. public void tearDownClass() throws Exception {
  38. if (ActionManager.getGroups().containsKey("unit-test")) {
  39. ActionManager.removeGroup("unit-test");
  40. }
  41. if (ActionManager.getGroups().containsKey("unit-test-two")) {
  42. ActionManager.removeGroup("unit-test-two");
  43. }
  44. }
  45. @Test
  46. public void testMakeGroup() {
  47. ActionManager.makeGroup("unit-test");
  48. assertTrue("makeGroup must create the group directory",
  49. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  50. }
  51. @Test
  52. public void testGetGroup() {
  53. final ActionGroup group = ActionManager.getGroup("unit-test");
  54. assertEquals("getGroup must return an ActionGroup with the right name",
  55. "unit-test", group.getName());
  56. }
  57. @Test
  58. public void testRenameGroup() {
  59. ActionManager.renameGroup("unit-test", "unit-test-two");
  60. assertFalse("renameGroup must unlink the old directory",
  61. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  62. assertTrue("renameGroup must create the target directory",
  63. new File(ActionManager.getDirectory() + "unit-test-two").isDirectory());
  64. }
  65. @Test
  66. public void testRenameGroupWithAction() {
  67. final Action action = new Action("unit-test-two", "test1", new ActionType[0],
  68. new String[0], new ArrayList<ActionCondition>(), null);
  69. assertSame("Creating a new action must add it to the correct group",
  70. action, ActionManager.getGroup("unit-test-two").get(0));
  71. ActionManager.renameGroup("unit-test-two", "unit-test");
  72. assertFalse("renameGroup must unlink the old directory",
  73. new File(ActionManager.getDirectory() + "unit-test-two").isDirectory());
  74. assertTrue("renameGroup must create the target directory",
  75. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  76. assertSame("renameGroup must move actions to new group",
  77. action, ActionManager.getGroup("unit-test").get(0));
  78. assertEquals("renameGroup must remove actions from old group",
  79. 0, ActionManager.getGroup("unit-test-two").size());
  80. }
  81. @Test
  82. public void testRemoveGroup() {
  83. ActionManager.removeGroup("unit-test");
  84. assertFalse("removeGroup must unlink directory",
  85. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  86. ActionManager.saveActions();
  87. assertFalse("saveActions must not restore removed groups",
  88. new File(ActionManager.getDirectory() + "unit-test").isDirectory());
  89. }
  90. }