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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. final ActionComponentChain chain = new ActionComponentChain(String.class,
  50. "STRONG_STRING");
  51. }
  52. @Test(expected=IllegalArgumentException.class)
  53. public void testInvalidType() {
  54. final ActionComponentChain chain = new ActionComponentChain(String.class,
  55. "USER_MODES.STRING_STRING");
  56. }
  57. @Test(expected=IllegalArgumentException.class)
  58. public void testInvalidLink() {
  59. final ActionComponentChain chain = new ActionComponentChain(String.class,
  60. "STRING_STRING.USER_MODES");
  61. }
  62. @Test
  63. public void testAppliesTo() {
  64. final ActionComponentChain chain = new ActionComponentChain(String.class,
  65. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  66. assertEquals(String.class, chain.appliesTo());
  67. }
  68. @Test
  69. public void testGetType() {
  70. final ActionComponentChain chain = new ActionComponentChain(String.class,
  71. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  72. assertEquals(Integer.class, chain.getType());
  73. }
  74. @Test
  75. public void testGetName() {
  76. final ActionComponentChain chain = new ActionComponentChain(String.class,
  77. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  78. assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_STRING.getName()) > -1);
  79. assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_LENGTH.getName()) > -1);
  80. }
  81. @Test(expected=AssertionError.class)
  82. public void testEmptyAppliesTo() {
  83. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  84. chain.appliesTo();
  85. }
  86. @Test(expected=AssertionError.class)
  87. public void testEmptyGetType() {
  88. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  89. chain.getType();
  90. }
  91. @Test(expected=AssertionError.class)
  92. public void testEmptyGetName() {
  93. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  94. chain.getName();
  95. }
  96. @Test(expected=AssertionError.class)
  97. public void testEmptyToString() {
  98. final ActionComponentChain chain = new ActionComponentChain(String.class, "");
  99. chain.toString();
  100. }
  101. @Test()
  102. public void testRequiresConnection1() {
  103. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  104. "SERVER_NETWORK");
  105. assertTrue(chain.requiresConnection());
  106. }
  107. @Test()
  108. public void testRequiresConnection2() {
  109. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  110. "SERVER_NETWORK.STRING_LENGTH");
  111. assertTrue(chain.requiresConnection());
  112. }
  113. @Test()
  114. public void testRequiresConnection3() {
  115. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  116. "SERVER_NAME.STRING_LENGTH");
  117. assertFalse(chain.requiresConnection());
  118. }
  119. }