You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PopupMenuItemTest.java 3.3KB

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