Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ActionComponentChainTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 extends junit.framework.TestCase {
  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
  45. public void testInvalidName() {
  46. boolean iaed = false;
  47. try {
  48. final ActionComponentChain chain = new ActionComponentChain(String.class,
  49. "STRONG_STRING");
  50. } catch (IllegalArgumentException iae) {
  51. iaed = true;
  52. }
  53. assertTrue("Should throw an IAE", iaed);
  54. }
  55. @Test
  56. public void testInvalidType() {
  57. boolean iaed = false;
  58. try {
  59. final ActionComponentChain chain = new ActionComponentChain(String.class,
  60. "USER_MODES.STRING_STRING");
  61. } catch (IllegalArgumentException iae) {
  62. iaed = true;
  63. }
  64. assertTrue("Should throw an IAE", iaed);
  65. }
  66. @Test
  67. public void testInvalidLink() {
  68. boolean iaed = false;
  69. try {
  70. final ActionComponentChain chain = new ActionComponentChain(String.class,
  71. "STRING_STRING.USER_MODES");
  72. } catch (IllegalArgumentException iae) {
  73. iaed = true;
  74. }
  75. assertTrue("Should throw an IAE", iaed);
  76. }
  77. @Test
  78. public void testAppliesTo() {
  79. final ActionComponentChain chain = new ActionComponentChain(String.class,
  80. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  81. assertEquals(String.class, chain.appliesTo());
  82. }
  83. @Test
  84. public void testGetType() {
  85. final ActionComponentChain chain = new ActionComponentChain(String.class,
  86. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  87. assertEquals(Integer.class, chain.getType());
  88. }
  89. @Test
  90. public void testGetName() {
  91. final ActionComponentChain chain = new ActionComponentChain(String.class,
  92. "STRING_STRING.STRING_STRING.STRING_LENGTH");
  93. assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_STRING.getName()) > -1);
  94. assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_LENGTH.getName()) > -1);
  95. }
  96. }