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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  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.interfaces.actions.ActionComponent;
  25. import org.junit.Before;
  26. import org.junit.Test;
  27. import org.junit.runner.RunWith;
  28. import org.mockito.Mock;
  29. import org.mockito.runners.MockitoJUnitRunner;
  30. import static org.junit.Assert.*;
  31. import static org.mockito.Mockito.*;
  32. @RunWith(MockitoJUnitRunner.class)
  33. public class ActionComponentChainTest {
  34. @Mock private ActionManager actionManager;
  35. @Before
  36. public void setUp() throws Exception {
  37. when(actionManager.getComponent("SERVER_NAME"))
  38. .thenReturn(CoreActionComponent.SERVER_NAME);
  39. when(actionManager.getComponent("SERVER_NETWORK"))
  40. .thenReturn(CoreActionComponent.SERVER_NETWORK);
  41. when(actionManager.getComponent("STRING_LENGTH"))
  42. .thenReturn(CoreActionComponent.STRING_LENGTH);
  43. when(actionManager.getComponent("STRING_STRING"))
  44. .thenReturn(CoreActionComponent.STRING_STRING);
  45. when(actionManager.getComponent("USER_MODES"))
  46. .thenReturn(CoreActionComponent.USER_MODES);
  47. // TODO: Testing for this behaviour here is odd - ActionComponentChain
  48. // should probably do its own validation and throw a more
  49. // appropriate exception.
  50. when(actionManager.getComponent(""))
  51. .thenThrow(new AssertionError());
  52. }
  53. @Test
  54. public void testSingle() {
  55. final ActionComponentChain chain = new ActionComponentChain(String.class, "STRING_STRING", actionManager);
  56. assertEquals("foo bar baz", chain.get("foo bar baz"));
  57. assertEquals("STRING_STRING", chain.toString());
  58. }
  59. @Test
  60. public void testDouble() {
  61. final ActionComponentChain chain = new ActionComponentChain(String.class,
  62. "STRING_STRING.STRING_STRING", actionManager);
  63. assertEquals("foo bar baz", chain.get("foo bar baz"));
  64. assertEquals("STRING_STRING.STRING_STRING", chain.toString());
  65. }
  66. @Test(expected=IllegalArgumentException.class)
  67. public void testInvalidName() {
  68. new ActionComponentChain(String.class, "STRONG_STRING", actionManager);
  69. }
  70. @Test(expected=IllegalArgumentException.class)
  71. public void testInvalidType() {
  72. new ActionComponentChain(String.class, "USER_MODES.STRING_STRING", actionManager);
  73. }
  74. @Test(expected=IllegalArgumentException.class)
  75. public void testInvalidLink() {
  76. new ActionComponentChain(String.class, "STRING_STRING.USER_MODES", actionManager);
  77. }
  78. @Test
  79. public void testAppliesTo() {
  80. final ActionComponent chain = new ActionComponentChain(String.class,
  81. "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
  82. assertSame(String.class, chain.appliesTo());
  83. }
  84. @Test
  85. public void testGetType() {
  86. final ActionComponent chain = new ActionComponentChain(String.class,
  87. "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
  88. assertSame(Integer.class, chain.getType());
  89. }
  90. @Test
  91. public void testGetName() {
  92. final ActionComponent chain = new ActionComponentChain(String.class,
  93. "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
  94. assertTrue(chain.getName().contains(CoreActionComponent.STRING_STRING.getName()));
  95. assertTrue(chain.getName().contains(CoreActionComponent.STRING_LENGTH.getName()));
  96. }
  97. @Test(expected=AssertionError.class)
  98. public void testEmptyAppliesTo() {
  99. final ActionComponent chain = new ActionComponentChain(String.class, "", actionManager);
  100. chain.appliesTo();
  101. }
  102. @Test(expected=AssertionError.class)
  103. public void testEmptyGetType() {
  104. final ActionComponent chain = new ActionComponentChain(String.class, "", actionManager);
  105. chain.getType();
  106. }
  107. @Test(expected=AssertionError.class)
  108. public void testEmptyGetName() {
  109. final ActionComponent chain = new ActionComponentChain(String.class, "", actionManager);
  110. chain.getName();
  111. }
  112. @SuppressWarnings("ResultOfMethodCallIgnored")
  113. @Test(expected=AssertionError.class)
  114. public void testEmptyToString() {
  115. final ActionComponentChain chain = new ActionComponentChain(String.class, "", actionManager);
  116. chain.toString();
  117. }
  118. @Test
  119. public void testRequiresConnection1() {
  120. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  121. "SERVER_NETWORK", actionManager);
  122. assertTrue(chain.requiresConnection());
  123. }
  124. @Test
  125. public void testRequiresConnection2() {
  126. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  127. "SERVER_NETWORK.STRING_LENGTH", actionManager);
  128. assertTrue(chain.requiresConnection());
  129. }
  130. @Test
  131. public void testRequiresConnection3() {
  132. final ActionComponentChain chain = new ActionComponentChain(Server.class,
  133. "SERVER_NAME.STRING_LENGTH", actionManager);
  134. assertFalse(chain.requiresConnection());
  135. }
  136. }