#1035 Add optional constraints to onLogin and onFirstLogin commands for number of alt accounts
- Extend Command to add specific constraints - Currently doesn't work because of missing ConfigMe support
This commit is contained in:
@@ -17,6 +17,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -30,6 +31,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
/**
|
||||
* Test for {@link CommandManager}.
|
||||
*/
|
||||
// TODO #1035: Tests currently fail because ConfigMe can't handle Optional fields
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandManagerTest {
|
||||
|
||||
@@ -66,7 +68,7 @@ public class CommandManagerTest {
|
||||
initManager();
|
||||
|
||||
// when
|
||||
manager.runCommandsOnLogin(player);
|
||||
manager.runCommandsOnLogin(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(bukkitService).dispatchConsoleCommand("msg Bobby Welcome back");
|
||||
@@ -83,7 +85,7 @@ public class CommandManagerTest {
|
||||
initManager();
|
||||
|
||||
// when
|
||||
manager.runCommandsOnLogin(player);
|
||||
manager.runCommandsOnLogin(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(bukkitService).dispatchConsoleCommand("msg Bobby Welcome back, bob");
|
||||
@@ -114,7 +116,7 @@ public class CommandManagerTest {
|
||||
initManager();
|
||||
|
||||
// when
|
||||
manager.runCommandsOnFirstLogin(player);
|
||||
manager.runCommandsOnFirstLogin(player, Collections.emptyList());
|
||||
|
||||
// then
|
||||
verify(bukkitService).dispatchConsoleCommand("pay Bobby 30");
|
||||
|
||||
+7
-4
@@ -21,6 +21,7 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static fr.xephi.authme.settings.commandconfig.CommandConfigTestHelper.isCommand;
|
||||
import static java.util.Collections.emptyList;
|
||||
@@ -85,8 +86,10 @@ public class CommandMigrationServiceTest {
|
||||
List<String> onRegisterConsole = Arrays.asList("log %p registered", "whois %p");
|
||||
given(settingsMigrationService.getOnRegisterConsoleCommands()).willReturn(onRegisterConsole);
|
||||
|
||||
Map<String, Command> onLoginCommands = new LinkedHashMap<>();
|
||||
onLoginCommands.put("bcast", new Command("bcast %p returned", Executor.CONSOLE));
|
||||
Map<String, OnLoginCommand> onLoginCommands = new LinkedHashMap<>();
|
||||
OnLoginCommand existingCommand = new OnLoginCommand("helpop %p has many alts", Executor.CONSOLE);
|
||||
existingCommand.setNumberOfOtherAccountsAtLeast(Optional.of(2));
|
||||
onLoginCommands.put("alert_on_alts", existingCommand);
|
||||
commandConfig.setOnLogin(onLoginCommands);
|
||||
Map<String, Command> onRegisterCommands = new LinkedHashMap<>();
|
||||
onRegisterCommands.put("ex_cmd", new Command("existing", Executor.CONSOLE));
|
||||
@@ -99,9 +102,9 @@ public class CommandMigrationServiceTest {
|
||||
// then
|
||||
assertThat(result, equalTo(true));
|
||||
assertThat(commandConfig.getOnLogin(), sameInstance(onLoginCommands));
|
||||
Collection<Command> loginCmdList = onLoginCommands.values();
|
||||
Collection<OnLoginCommand> loginCmdList = onLoginCommands.values();
|
||||
assertThat(loginCmdList, contains(
|
||||
equalTo(onLoginCommands.get("bcast")),
|
||||
equalTo(existingCommand),
|
||||
isCommand("on login command", Executor.PLAYER),
|
||||
isCommand("cmd1", Executor.CONSOLE),
|
||||
isCommand("cmd2 %p", Executor.CONSOLE),
|
||||
|
||||
@@ -21,6 +21,10 @@ onLogin:
|
||||
display_list:
|
||||
command: 'list'
|
||||
executor: PLAYER
|
||||
warn_for_alts:
|
||||
command: 'helpop Player %p has more than 1 account'
|
||||
exeuctor: CONSOLE
|
||||
numberOfOtherAccountsAtLeast: 2
|
||||
onSessionLogin:
|
||||
welcome:
|
||||
command: 'msg %p Session login!'
|
||||
|
||||
Reference in New Issue
Block a user