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.3KB

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