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.

ActionComponentChainTest.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2010 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.Server;
  24. import com.dmdirc.config.IdentityManager;
  25. import org.junit.BeforeClass;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. public class ActionComponentChainTest {
  29. @BeforeClass
  30. public static void setUp() throws Exception {
  31. IdentityManager.load();
  32. ActionManager.init();
  33. }
  34. @Test
  35. public void testSingle() {
  36. final ActionComponentChain chain = new ActionComponentChain(String.class, "STRING_STRING");
  37. assertEquals(chain.get("foo bar baz"), "foo bar baz");
  38. assertEquals("STRING_STRING", chain.toString());
  39. }
  40. @Test
  41. public void testDouble() {
  42. final ActionComponentChain chain = new ActionComponentChain(String.class,
  43. "STRING_STRING.STRING_STRING");
  44. assertEquals(chain.get("foo bar baz"), "foo bar baz");
  45. assertEquals("STRING_STRING.STRING_STRING", chain.toString());
  46. }
  47. @Test(expected=IllegalArgumentException.class)
  48. public void testInvalidName() {
  49. new ActionComponentChain(String.class, "STRONG_STRING");
  50. }
  51. @Test(expected=IllegalArgumentException.class)
  52. public void testInvalidType() {
  53. new ActionComponentChain(String.class, "USER_MODES.STRING_STRING");
  54. }
  55. @Test(expected=IllegalArgumentException.class)
  56. public void testInvalidLink() {
  57. new ActionComponentChain(String.class, "STRING_STRING.USER_MODES");
  58. }
  59. @Test
  60. public void testAppliesTo() {
  61. final ActionComponentChain chain = new ActionComponentChain(String.class,
  62. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  63. assertEquals(String.class, chain.appliesTo());
  64. }
  65. @Test
  66. public void testGetType() {
  67. final ActionComponentChain chain = new ActionComponentChain(String.class,
  68. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  69. assertEquals(Integer.class, chain.getType());
  70. }
  71. @Test
  72. public void testGetName() {
  73. final ActionComponentChain chain = new ActionComponentChain(String.class,
  74. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  75. assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_STRING.getName()) > -1);
  76. assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_LENGTH.getName()) > -1);
  77. }
  78. @Test(expected=AssertionError.class)
  79. public void testEmptyAppliesTo() {
  80. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  81. chain.appliesTo();
  82. }
  83. @Test(expected=AssertionError.class)
  84. public void testEmptyGetType() {
  85. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  86. chain.getType();
  87. }
  88. @Test(expected=AssertionError.class)
  89. public void testEmptyGetName() {
  90. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  91. chain.getName();
  92. }
  93. @Test(expected=AssertionError.class)
  94. public void testEmptyToString() {
  95. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  96. chain.toString();
  97. }
  98. @Test()
  99. public void testRequiresConnection1() {
  100. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  101. "SERVER_NETWORK");
  102. assertTrue(chain.requiresConnection());
  103. }
  104. @Test()
  105. public void testRequiresConnection2() {
  106. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  107. "SERVER_NETWORK.STRING_LENGTH");
  108. assertTrue(chain.requiresConnection());
  109. }
  110. @Test()
  111. public void testRequiresConnection3() {
  112. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  113. "SERVER_NAME.STRING_LENGTH");
  114. assertFalse(chain.requiresConnection());
  115. }
  116. }