Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ActionConditionTest.java 5.6KB

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