Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

PopupMenuItemTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2006-2015 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;
  23. import com.dmdirc.interfaces.CommandController;
  24. import org.junit.Before;
  25. import org.junit.Test;
  26. import static org.junit.Assert.*;
  27. import static org.mockito.Mockito.*;
  28. public class PopupMenuItemTest {
  29. private CommandController manager;
  30. @Before
  31. public void setup() {
  32. manager = mock(CommandController.class);
  33. when(manager.getCommandChar()).thenReturn('_');
  34. }
  35. /**
  36. * Tests a command which doesn't define an arity gets args substituted
  37. * for a single target.
  38. */
  39. @Test
  40. public void testUnaryCommandWithSingle() {
  41. final PopupMenuItem item = new PopupMenuItem(manager, null, 1, "foo %s");
  42. assertEquals("_foo bar", item.getCommand(new Object[][]{{"bar"}}));
  43. }
  44. /**
  45. * Tests a command which doesn't define an arity gets args substituted
  46. * for multiple targets.
  47. */
  48. @Test
  49. public void testUnaryCommandWithMultiple() {
  50. final PopupMenuItem item = new PopupMenuItem(manager, null, 1, "foo %s");
  51. assertEquals("_foo bar\n_foo b\n_foo 2",
  52. item.getCommand(new Object[][]{
  53. {"bar"}, {"b"}, {"2"},
  54. }));
  55. }
  56. /**
  57. * Tests a command which defines its arity as 1 gets args substituted
  58. * for a single target.
  59. */
  60. @Test
  61. public void testExplicitUnaryCommandWithSingle() {
  62. final PopupMenuItem item = new PopupMenuItem(manager, null, 1, "1:foo %s");
  63. assertEquals("_foo bar", item.getCommand(new Object[][]{{"bar"}}));
  64. }
  65. /**
  66. * Tests a command which defines its arity as 1 gets args substituted
  67. * for multiple targets.
  68. */
  69. @Test
  70. public void testExplicitUnaryCommandWithMultiple() {
  71. final PopupMenuItem item = new PopupMenuItem(manager, null, 1, "1:foo %s");
  72. assertEquals("_foo bar\n_foo a\n_foo 1",
  73. item.getCommand(new Object[][]{
  74. {"bar"}, {"a"}, {"1"},
  75. }));
  76. }
  77. /**
  78. * Tests a command which takes multiple arguments.
  79. */
  80. @Test
  81. public void testMultipleCommand() {
  82. final PopupMenuItem item = new PopupMenuItem(manager, null, 2, "4:foo %s %s %s %s");
  83. assertEquals("_foo 1 2 a b\n_foo bar baz",
  84. item.getCommand(new Object[][]{
  85. {"1", "2"}, {"a", "b"}, {"bar", "baz"},
  86. }).trim());
  87. }
  88. }