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.

ActionConditionTest.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 org.junit.Before;
  24. import org.junit.Test;
  25. import static org.junit.Assert.*;
  26. public class ActionConditionTest extends junit.framework.TestCase {
  27. @Before
  28. public void setUp() throws Exception {
  29. ActionManager.init();
  30. }
  31. @Test
  32. public void testConstructor1() {
  33. final ActionCondition ac = new ActionCondition(1, CoreActionComponent.STRING_STRING,
  34. CoreActionComparison.STRING_STARTSWITH, "foo");
  35. assertEquals(1, ac.getArg());
  36. assertEquals(CoreActionComponent.STRING_STRING, ac.getComponent());
  37. assertEquals(CoreActionComparison.STRING_STARTSWITH, ac.getComparison());
  38. assertEquals("foo", ac.getTarget());
  39. }
  40. @Test
  41. public void testConstructor2() {
  42. final ActionCondition ac = new ActionCondition("foobarbaz",
  43. CoreActionComparison.STRING_STARTSWITH, "foo");
  44. assertEquals("foobarbaz", ac.getStarget());
  45. assertEquals(CoreActionComparison.STRING_STARTSWITH, ac.getComparison());
  46. assertEquals("foo", ac.getTarget());
  47. }
  48. @Test
  49. public void testTest1() {
  50. final ActionCondition ac = new ActionCondition(0, CoreActionComponent.STRING_STRING,
  51. CoreActionComparison.STRING_STARTSWITH, "foo");
  52. assertTrue(ac.test(new ActionSubstitutor(CoreActionType.CLIENT_CLOSED), "foo bar"));
  53. }
  54. @Test
  55. public void testTest2() {
  56. final ActionCondition ac = new ActionCondition("foobarbaz",
  57. CoreActionComparison.STRING_STARTSWITH, "foo");
  58. assertTrue(ac.test(new ActionSubstitutor(CoreActionType.CLIENT_CLOSED)));
  59. }
  60. @Test
  61. public void testSetters() {
  62. final ActionCondition ac = new ActionCondition("foobarbaz",
  63. CoreActionComparison.STRING_STARTSWITH, "foo");
  64. assertEquals("foo", ac.getTarget());
  65. ac.setTarget("bar");
  66. assertEquals("bar", ac.getTarget());
  67. assertEquals("foobarbaz", ac.getStarget());
  68. ac.setStarget("bar");
  69. assertEquals("bar", ac.getStarget());
  70. assertEquals(CoreActionComparison.STRING_STARTSWITH, ac.getComparison());
  71. ac.setComparison(CoreActionComparison.STRING_EQUALS);
  72. assertEquals(CoreActionComparison.STRING_EQUALS, ac.getComparison());
  73. ac.setComponent(CoreActionComponent.STRING_STRING);
  74. assertEquals(CoreActionComponent.STRING_STRING, ac.getComponent());
  75. ac.setArg(0);
  76. assertEquals(0, ac.getArg());
  77. }
  78. @Test
  79. public void testToString() {
  80. final ActionCondition ac1 = new ActionCondition("foobarbaz",
  81. CoreActionComparison.STRING_STARTSWITH, "foo");
  82. assertTrue(ac1.toString().indexOf("foo") > -1);
  83. assertTrue(ac1.toString().indexOf("foobarbaz") > -1);
  84. assertTrue(ac1.toString().indexOf(CoreActionComparison.STRING_STARTSWITH.toString()) > -1);
  85. }
  86. @Test
  87. public void testEquals() {
  88. final ActionCondition ac1 = new ActionCondition("foobarbaz",
  89. CoreActionComparison.STRING_STARTSWITH, "foo");
  90. final ActionCondition ac2 = new ActionCondition("foobarbaz",
  91. CoreActionComparison.STRING_STARTSWITH, "foo");
  92. assertTrue(ac1.equals(ac2));
  93. assertTrue(ac2.equals(ac1));
  94. assertFalse(ac1.equals(null));
  95. assertFalse(ac1.equals("foo"));
  96. assertEquals(ac1.hashCode(), ac2.hashCode());
  97. ac2.setStarget("bar");
  98. assertFalse(ac2.equals(ac1));
  99. assertFalse(ac1.equals(ac2));
  100. ac2.setStarget("foobarbaz");
  101. ac2.setComponent(CoreActionComponent.STRING_STRING);
  102. ac2.setArg(1);
  103. assertFalse(ac2.equals(ac1));
  104. assertFalse(ac1.equals(ac2));
  105. ac1.setComponent(CoreActionComponent.STRING_STRING);
  106. ac1.setArg(1);
  107. assertTrue(ac1.equals(ac2));
  108. assertTrue(ac2.equals(ac1));
  109. assertEquals(ac1.hashCode(), ac2.hashCode());
  110. ac1.setComponent(CoreActionComponent.STRING_LENGTH);
  111. assertFalse(ac2.equals(ac1));
  112. assertFalse(ac1.equals(ac2));
  113. ac1.setComponent(CoreActionComponent.STRING_STRING);
  114. ac1.setComparison(CoreActionComparison.STRING_NCONTAINS);
  115. assertFalse(ac2.equals(ac1));
  116. assertFalse(ac1.equals(ac2));
  117. ac1.setComparison(CoreActionComparison.STRING_STARTSWITH);
  118. ac1.setTarget("flub");
  119. assertFalse(ac2.equals(ac1));
  120. assertFalse(ac1.equals(ac2));
  121. }
  122. }