Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AliasFactoryTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.commandparser.aliases;
  23. import com.dmdirc.interfaces.CommandController;
  24. import org.junit.Before;
  25. import org.junit.Test;
  26. import org.junit.runner.RunWith;
  27. import org.mockito.Mock;
  28. import org.mockito.runners.MockitoJUnitRunner;
  29. import static org.junit.Assert.assertEquals;
  30. import static org.mockito.Mockito.when;
  31. @RunWith(MockitoJUnitRunner.class)
  32. public class AliasFactoryTest {
  33. private static final String COMMAND_CHAR = "!";
  34. private static final String SILENCE_CHAR = "_";
  35. @Mock
  36. private CommandController commandController;
  37. private AliasFactory factory;
  38. @Before
  39. public void setup() {
  40. factory = new AliasFactory(commandController);
  41. when(commandController.getCommandChar()).thenReturn(COMMAND_CHAR.charAt(0));
  42. when(commandController.getSilenceChar()).thenReturn(SILENCE_CHAR.charAt(0));
  43. }
  44. @Test
  45. public void testSimpleAlias() {
  46. final Alias alias = factory.createAlias("name", 2, "response");
  47. assertEquals("name", alias.getName());
  48. assertEquals(2, alias.getMinArguments());
  49. assertEquals("response", alias.getSubstitution());
  50. }
  51. @Test
  52. public void testCommandChars() {
  53. final Alias alias = factory.createAlias(COMMAND_CHAR + "name", 2,
  54. COMMAND_CHAR + "response");
  55. assertEquals("name", alias.getName());
  56. assertEquals(2, alias.getMinArguments());
  57. assertEquals("response", alias.getSubstitution());
  58. }
  59. @Test
  60. public void testSilenceChars() {
  61. final Alias alias = factory.createAlias(SILENCE_CHAR + "name", 2,
  62. SILENCE_CHAR + "response");
  63. assertEquals(SILENCE_CHAR + "name", alias.getName());
  64. assertEquals(2, alias.getMinArguments());
  65. assertEquals(SILENCE_CHAR + "response", alias.getSubstitution());
  66. }
  67. @Test
  68. public void testCommandAndSilenceChars() {
  69. final Alias alias = factory.createAlias(COMMAND_CHAR + SILENCE_CHAR + "name", 2,
  70. COMMAND_CHAR + SILENCE_CHAR + "response");
  71. assertEquals("name", alias.getName());
  72. assertEquals(2, alias.getMinArguments());
  73. assertEquals("response", alias.getSubstitution());
  74. }
  75. @Test
  76. public void testMultilineResponse() {
  77. final Alias alias = factory.createAlias("name", 2,
  78. "response1\n"
  79. + "response2\r\n"
  80. + COMMAND_CHAR + "response3\r"
  81. + COMMAND_CHAR + SILENCE_CHAR + "response4\r\n\r\n"
  82. + SILENCE_CHAR + "response5\n\n\n");
  83. assertEquals("name", alias.getName());
  84. assertEquals(2, alias.getMinArguments());
  85. assertEquals("response1\r\nresponse2\r\nresponse3\r\nresponse4\r\n"
  86. + SILENCE_CHAR + "response5", alias.getSubstitution());
  87. }
  88. }