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

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