Skip to content

Commit 912eccb

Browse files
committed
Added tests for custom parameters
1 parent a7c5728 commit 912eccb

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/test/java/me/despical/commandframework/test/CommandRegistrationTest.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void setUp() {
4848
@Test
4949
void testCommandRegistration() {
5050
CommandFramework commandFramework = createCommandFramework();
51-
assertEquals(2, commandFramework.getCommands().size());
51+
assertEquals(3, commandFramework.getCommands().size());
5252
}
5353

5454
/**
@@ -82,7 +82,12 @@ void testCommandExecutionByPlayer() {
8282
player.performCommand("secondAlias");
8383
player.assertSaid("§cRequired argument length is less or greater than needed!");
8484

85+
// no command arguments
8586
player.performCommand("nocommandargs");
87+
88+
// custom parameters
89+
player.performCommand("customargs test");
90+
player.assertSaid("First parameter is test");
8691
}
8792

8893
@AfterEach
@@ -97,6 +102,7 @@ public void tearDown() {
97102
private CommandFramework createCommandFramework() {
98103
CommandFramework commandFramework = new CommandFrameworkMock(plugin);
99104
commandFramework.registerCommands(new ExampleCommand());
105+
commandFramework.addCustomParameter(String.class, arguments -> arguments.getArgument(0));
100106
return commandFramework;
101107
}
102108

@@ -130,9 +136,22 @@ public void noCommandArgsTest() {
130136
Logger.getLogger(this.getClass().getSimpleName()).info("This command is annotated with @NoCommandArguments to run without required parameters.");
131137
}
132138

139+
@Command(
140+
name = "customargs",
141+
min = 1
142+
)
143+
// Do not forget to annotate with @CustomParameters; otherwise, the method won't be registered.
144+
@CustomParameters
145+
public void customParamCommand(String firstParameter, CommandArguments arguments) {
146+
CommandSender sender = arguments.getSender();
147+
// Check if arguments are empty; otherwise, firstParameter will return null.
148+
// CommandArguments parameter can be added to anywhere in method as a parameter.
149+
sender.sendMessage("First parameter is " + firstParameter);
150+
}
151+
133152
@Completer(
134-
name = "example"
135-
, aliases = {"firstAlias", "secondAlias"}
153+
name = "example",
154+
aliases = {"firstAlias", "secondAlias"}
136155
)
137156
public List<String> exampleCommandCompletion(CommandArguments arguments) {
138157
return Arrays.asList("first", "second", "third");

0 commit comments

Comments
 (0)