Skip to content

Commit

Permalink
Added tests for custom parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed Jan 23, 2024
1 parent a7c5728 commit 912eccb
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setUp() {
@Test
void testCommandRegistration() {
CommandFramework commandFramework = createCommandFramework();
assertEquals(2, commandFramework.getCommands().size());
assertEquals(3, commandFramework.getCommands().size());
}

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

// no command arguments
player.performCommand("nocommandargs");

// custom parameters
player.performCommand("customargs test");
player.assertSaid("First parameter is test");
}

@AfterEach
Expand All @@ -97,6 +102,7 @@ public void tearDown() {
private CommandFramework createCommandFramework() {
CommandFramework commandFramework = new CommandFrameworkMock(plugin);
commandFramework.registerCommands(new ExampleCommand());
commandFramework.addCustomParameter(String.class, arguments -> arguments.getArgument(0));
return commandFramework;
}

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

@Command(
name = "customargs",
min = 1
)
// Do not forget to annotate with @CustomParameters; otherwise, the method won't be registered.
@CustomParameters
public void customParamCommand(String firstParameter, CommandArguments arguments) {
CommandSender sender = arguments.getSender();
// Check if arguments are empty; otherwise, firstParameter will return null.
// CommandArguments parameter can be added to anywhere in method as a parameter.
sender.sendMessage("First parameter is " + firstParameter);
}

@Completer(
name = "example"
, aliases = {"firstAlias", "secondAlias"}
name = "example",
aliases = {"firstAlias", "secondAlias"}
)
public List<String> exampleCommandCompletion(CommandArguments arguments) {
return Arrays.asList("first", "second", "third");
Expand Down

0 comments on commit 912eccb

Please sign in to comment.