#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<>();