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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2006-2008 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 org.junit.Before;
  24. import org.junit.Test;
  25. import static org.junit.Assert.*;
  26. public class ActionComponentChainTest {
  27. @Before
  28. public void setUp() throws Exception {
  29. ActionManager.init();
  30. }
  31. @Test
  32. public void testSingle() {
  33. final ActionComponentChain chain = new ActionComponentChain(String.class, "STRING_STRING");
  34. assertEquals(chain.get("foo bar baz"), "foo bar baz");
  35. assertEquals("STRING_STRING", chain.toString());
  36. }
  37. @Test
  38. public void testDouble() {
  39. final ActionComponentChain chain = new ActionComponentChain(String.class,
  40. "STRING_STRING.STRING_STRING");
  41. assertEquals(chain.get("foo bar baz"), "foo bar baz");
  42. assertEquals("STRING_STRING.STRING_STRING", chain.toString());
  43. }
  44. @Test(expected=IllegalArgumentException.class)
  45. public void testInvalidName() {
  46. final ActionComponentChain chain = new ActionComponentChain(String.class,
  47. "STRONG_STRING");
  48. }
  49. @Test(expected=IllegalArgumentException.class)
  50. public void testInvalidType() {
  51. final ActionComponentChain chain = new ActionComponentChain(String.class,
  52. "USER_MODES.STRING_STRING");
  53. }
  54. @Test(expected=IllegalArgumentException.class)
  55. public void testInvalidLink() {
  56. final ActionComponentChain chain = new ActionComponentChain(String.class,
  57. "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. public static junit.framework.Test suite() {
  99. return new junit.framework.JUnit4TestAdapter(ActionComponentChainTest.class);
  100. }
  101. }