#1449 Fix copying of Commands, add tests with command delay

This commit is contained in:
ljacqu
2018-09-11 22:03:46 +02:00
parent 035c2f352a
commit 22c08c9fc3
7 changed files with 53 additions and 44 deletions
@@ -3,6 +3,7 @@ package fr.xephi.authme.settings.commandconfig;
import com.google.common.io.Files;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.BukkitServiceTestHelper;
import fr.xephi.authme.service.GeoIpService;
import fr.xephi.authme.settings.SettingsMigrationService;
import org.bukkit.entity.Player;
@@ -25,6 +26,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
@@ -59,6 +61,7 @@ public class CommandManagerTest {
public void setup() throws IOException {
testFolder = temporaryFolder.newFolder();
player = mockPlayer();
BukkitServiceTestHelper.setBukkitServiceToScheduleSyncDelayedTaskWithDelay(bukkitService);
}
@Test
@@ -74,6 +77,8 @@ public class CommandManagerTest {
verify(bukkitService).dispatchConsoleCommand("msg Bobby Welcome back");
verify(bukkitService).dispatchCommand(any(Player.class), eq("motd"));
verify(bukkitService).dispatchCommand(any(Player.class), eq("list"));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(60L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(120L));
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@@ -92,6 +97,9 @@ public class CommandManagerTest {
verify(bukkitService).dispatchCommand(player, "motd");
verify(bukkitService).dispatchCommand(player, "list");
verify(bukkitService).dispatchConsoleCommand("helpop Player Bobby has more than 1 account");
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(60L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(120L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(180L));
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@@ -111,6 +119,10 @@ public class CommandManagerTest {
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");
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(60L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(120L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(180L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(240L));
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@@ -129,6 +141,9 @@ public class CommandManagerTest {
verify(bukkitService).dispatchCommand(player, "motd");
verify(bukkitService).dispatchCommand(player, "list");
verify(bukkitService).dispatchConsoleCommand("helpop Player Bobby has more than 1 account");
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(60L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(120L));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(180L));
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@@ -138,6 +153,7 @@ public class CommandManagerTest {
// given
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.incomplete.yml");
initManager();
BukkitServiceTestHelper.setBukkitServiceToScheduleSyncDelayedTaskWithDelay(bukkitService);
// when
manager.runCommandsOnLogin(player, Collections.emptyList());
@@ -145,6 +161,7 @@ public class CommandManagerTest {
// then
verify(bukkitService).dispatchConsoleCommand("msg Bobby Welcome back, bob");
verify(bukkitService).dispatchCommand(any(Player.class), eq("list"));
verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(100L));
verifyNoMoreInteractions(bukkitService);
verifyZeroInteractions(geoIpService);
}
@@ -232,6 +249,7 @@ public class CommandManagerTest {
// then
verify(bukkitService).dispatchCommand(any(Player.class), eq("me I just registered"));
verify(bukkitService).dispatchConsoleCommand("log Bobby (127.0.0.3, Syldavia) registered");
verify(bukkitService, times(2)).scheduleSyncDelayedTask(any(Runnable.class), eq(100L));
verifyNoMoreInteractions(bukkitService);
}