#1113 Create LimboService (work in progress)
- Introduce new LimboService with a higher level abstraction for outside classes to trigger LimboPlayer actions - Add methods to LimboPlayerTaskManager for muting the MessagesTask safely
This commit is contained in:
+2
-2
@@ -2,7 +2,7 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
@@ -57,7 +57,7 @@ public class RegisterAdminCommandTest {
|
||||
private ValidationService validationService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
|
||||
@@ -2,11 +2,9 @@ package fr.xephi.authme.command.executable.captcha;
|
||||
|
||||
import fr.xephi.authme.data.CaptchaManager;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.task.MessageTask;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.task.LimboPlayerTaskManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -40,7 +38,7 @@ public class CaptchaCommandTest {
|
||||
private CommonService commandService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
|
||||
@Test
|
||||
public void shouldDetectIfPlayerIsLoggedIn() {
|
||||
@@ -82,10 +80,6 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.isCaptchaRequired(name)).willReturn(true);
|
||||
String captchaCode = "3991";
|
||||
given(captchaManager.checkCode(name, captchaCode)).willReturn(true);
|
||||
MessageTask messageTask = mock(MessageTask.class);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboPlayer.getMessageTask()).willReturn(messageTask);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode));
|
||||
@@ -96,7 +90,7 @@ public class CaptchaCommandTest {
|
||||
verifyNoMoreInteractions(captchaManager);
|
||||
verify(commandService).send(player, MessageKey.CAPTCHA_SUCCESS);
|
||||
verify(commandService).send(player, MessageKey.LOGIN_MESSAGE);
|
||||
verify(messageTask).setMuted(false);
|
||||
verify(limboPlayerTaskManager).unmuteMessageTask(player);
|
||||
verifyNoMoreInteractions(commandService);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@ package fr.xephi.authme.process.unregister;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.TeleportationService;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -53,7 +53,7 @@ public class AsynchronousUnregisterTest {
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
@Mock
|
||||
private LimboPlayerTaskManager limboPlayerTaskManager;
|
||||
@Mock
|
||||
@@ -85,7 +85,7 @@ public class AsynchronousUnregisterTest {
|
||||
// then
|
||||
verify(service).send(player, MessageKey.WRONG_PASSWORD);
|
||||
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
||||
verifyZeroInteractions(dataSource, limboPlayerTaskManager, limboCache, authGroupHandler, teleportationService);
|
||||
verifyZeroInteractions(dataSource, limboPlayerTaskManager, limboService, authGroupHandler, teleportationService);
|
||||
verify(player, only()).getName();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.data.limbo.LimboCache;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
@@ -47,7 +47,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private LimboCache limboCache;
|
||||
private LimboService limboService;
|
||||
|
||||
@Mock
|
||||
private PlayerCache playerCache;
|
||||
@@ -62,7 +62,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
// given
|
||||
String name = "bobby";
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
MessageKey key = MessageKey.REGISTER_MESSAGE;
|
||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||
int interval = 12;
|
||||
@@ -82,14 +82,14 @@ public class LimboPlayerTaskManagerTest {
|
||||
public void shouldNotScheduleTaskForMissingLimboPlayer() {
|
||||
// given
|
||||
String name = "ghost";
|
||||
given(limboCache.getPlayerData(name)).willReturn(null);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(null);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(5);
|
||||
|
||||
// when
|
||||
limboPlayerTaskManager.registerMessageTask(name, true);
|
||||
|
||||
// then
|
||||
verify(limboCache).getPlayerData(name);
|
||||
verify(limboService).getLimboPlayer(name);
|
||||
verifyZeroInteractions(bukkitService);
|
||||
verifyZeroInteractions(messages);
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
given(limboPlayer.getMessageTask()).willReturn(existingMessageTask);
|
||||
|
||||
String name = "bobby";
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||
|
||||
// when
|
||||
@@ -136,7 +136,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30);
|
||||
BukkitTask bukkitTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
||||
@@ -156,7 +156,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
String name = "Phantom_";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
given(limboCache.getPlayerData(name)).willReturn(null);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(null);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(27);
|
||||
|
||||
// when
|
||||
@@ -189,7 +189,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
BukkitTask existingTask = mock(BukkitTask.class);
|
||||
given(limboPlayer.getTimeoutTask()).willReturn(existingTask);
|
||||
given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
|
||||
given(limboService.getLimboPlayer(name)).willReturn(limboPlayer);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
|
||||
BukkitTask bukkitTask = mock(BukkitTask.class);
|
||||
given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
|
||||
|
||||
Reference in New Issue
Block a user