123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- /*
- * Copyright (c) 2006-2014 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.commandparser.aliases;
-
- import com.dmdirc.interfaces.CommandController;
-
- import org.junit.Before;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.mockito.Mock;
- import org.mockito.runners.MockitoJUnitRunner;
-
- import static org.junit.Assert.assertEquals;
- import static org.mockito.Mockito.when;
-
- @RunWith(MockitoJUnitRunner.class)
- public class AliasFactoryTest {
-
- private static final String COMMAND_CHAR = "!";
- private static final String SILENCE_CHAR = "_";
-
- @Mock
- private CommandController commandController;
- private AliasFactory factory;
-
- @Before
- public void setup() {
- factory = new AliasFactory(commandController);
-
- when(commandController.getCommandChar()).thenReturn(COMMAND_CHAR.charAt(0));
- when(commandController.getSilenceChar()).thenReturn(SILENCE_CHAR.charAt(0));
- }
-
- @Test
- public void testSimpleAlias() {
- final Alias alias = factory.createAlias("name", 2, "response");
- assertEquals("name", alias.getName());
- assertEquals(2, alias.getMinArguments());
- assertEquals("response", alias.getSubstitution());
- }
-
- @Test
- public void testCommandChars() {
- final Alias alias = factory.createAlias(COMMAND_CHAR + "name", 2,
- COMMAND_CHAR + "response");
- assertEquals("name", alias.getName());
- assertEquals(2, alias.getMinArguments());
- assertEquals("response", alias.getSubstitution());
- }
-
- @Test
- public void testSilenceChars() {
- final Alias alias = factory.createAlias(SILENCE_CHAR + "name", 2,
- SILENCE_CHAR + "response");
- assertEquals(SILENCE_CHAR + "name", alias.getName());
- assertEquals(2, alias.getMinArguments());
- assertEquals(SILENCE_CHAR + "response", alias.getSubstitution());
- }
-
- @Test
- public void testCommandAndSilenceChars() {
- final Alias alias = factory.createAlias(COMMAND_CHAR + SILENCE_CHAR + "name", 2,
- COMMAND_CHAR + SILENCE_CHAR + "response");
- assertEquals("name", alias.getName());
- assertEquals(2, alias.getMinArguments());
- assertEquals("response", alias.getSubstitution());
- }
-
- @Test
- public void testMultilineResponse() {
- final Alias alias = factory.createAlias("name", 2,
- "response1\n"
- + "response2\r\n"
- + COMMAND_CHAR + "response3\r"
- + COMMAND_CHAR + SILENCE_CHAR + "response4\r\n\r\n"
- + SILENCE_CHAR + "response5\n\n\n");
- assertEquals("name", alias.getName());
- assertEquals(2, alias.getMinArguments());
- assertEquals("response1\r\nresponse2\r\nresponse3\r\nresponse4\r\n"
- + SILENCE_CHAR + "response5", alias.getSubstitution());
- }
-
- }
|