#1035 Forced commands: add more tests, rename account constraints, update commands.yml comments

This commit is contained in:
ljacqu
2018-01-16 20:32:17 +01:00
parent 3c0236e15e
commit f19f8502d8
7 changed files with 118 additions and 26 deletions
@@ -17,6 +17,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import static org.mockito.ArgumentMatchers.any;
@@ -77,6 +78,61 @@ public class CommandManagerTest {
verifyZeroInteractions(geoIpService);
}
@Test
public void shouldExecuteCommandsOnLoginWithTwoAlts() {
// given
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml");
initManager();
// when
manager.runCommandsOnLogin(player, Arrays.asList("willy", "nilly", "billy", "silly"));
// then
verify(bukkitService).dispatchConsoleCommand("msg Bobby Welcome back");
verify(bukkitService).dispatchCommand(player, "motd");
verify(bukkitService).dispatchCommand(player, "list");
verify(bukkitService).dispatchConsoleCommand("helpop Player Bobby has more than 1 account");
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@Test
public void shouldExecuteCommandsOnLoginWithFifteenAlts() {
// given
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml");
initManager();
// when
manager.runCommandsOnLogin(player, Collections.nCopies(15, "swag"));
// then
verify(bukkitService).dispatchConsoleCommand("msg Bobby Welcome back");
verify(bukkitService).dispatchCommand(player, "motd");
verify(bukkitService).dispatchCommand(player, "list");
verify(bukkitService).dispatchConsoleCommand("helpop Player Bobby has more than 1 account");
verify(bukkitService).dispatchConsoleCommand("log Bobby 127.0.0.3 many accounts");
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@Test
public void shouldExecuteCommandsOnLoginWithTwentyFiveAlts() {
// given
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml");
initManager();
// when
manager.runCommandsOnLogin(player, Collections.nCopies(25, "yolo"));
// then
verify(bukkitService).dispatchConsoleCommand("msg Bobby Welcome back");
verify(bukkitService).dispatchCommand(player, "motd");
verify(bukkitService).dispatchCommand(player, "list");
verify(bukkitService).dispatchConsoleCommand("helpop Player Bobby has more than 1 account");
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@Test
public void shouldExecuteCommandsOnLoginWithIncompleteConfig() {
// given
@@ -123,6 +179,19 @@ public class CommandManagerTest {
verifyZeroInteractions(geoIpService);
}
@Test
public void shouldNotExecuteFirstLoginCommandWhoseThresholdIsNotMet() {
// given
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml");
initManager();
// when
manager.runCommandsOnFirstLogin(player, Arrays.asList("u", "wot", "m8"));
// then
verifyZeroInteractions(bukkitService, geoIpService);
}
@Test
public void shouldExecuteCommandsOnJoin() {
// given
@@ -88,7 +88,7 @@ public class CommandMigrationServiceTest {
Map<String, OnLoginCommand> onLoginCommands = new LinkedHashMap<>();
OnLoginCommand existingCommand = new OnLoginCommand("helpop %p has many alts", Executor.CONSOLE);
existingCommand.setNumberOfOtherAccountsAtLeast(Optional.of(2));
existingCommand.setIfNumberOfAccountsAtLeast(Optional.of(2));
onLoginCommands.put("alert_on_alts", existingCommand);
commandConfig.setOnLogin(onLoginCommands);
Map<String, Command> onRegisterCommands = new LinkedHashMap<>();
@@ -23,8 +23,13 @@ onLogin:
executor: PLAYER
warn_for_alts:
command: 'helpop Player %p has more than 1 account'
exeuctor: CONSOLE
numberOfOtherAccountsAtLeast: 2
executor: CONSOLE
ifNumberOfAccountsAtLeast: 2
log_suspicious_user:
command: 'log %p %ip many accounts'
executor: CONSOLE
ifNumberOfAccountsAtLeast: 5
ifNumberOfAccountsLessThan: 20
onSessionLogin:
welcome:
command: 'msg %p Session login!'
@@ -33,6 +38,7 @@ onFirstLogin:
give_money:
command: 'pay %p 30'
executor: CONSOLE
ifNumberOfAccountsLessThan: 3
onUnregister: {}
onLogout:
announce: