mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-25 11:46:38 +01:00
Fix some unit testing
This commit is contained in:
parent
a2fe62e3ff
commit
e1f893afe3
@ -10,7 +10,7 @@ import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import fr.xephi.authme.util.AtomicCounter;
|
||||
import fr.xephi.authme.util.AtomicIntervalCounter;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -35,7 +35,7 @@ public class AntiBotService implements SettingsDependent {
|
||||
private AntiBotStatus antiBotStatus;
|
||||
private boolean startup;
|
||||
private BukkitTask disableTask;
|
||||
private AtomicCounter flaggedCounter;
|
||||
private AtomicIntervalCounter flaggedCounter;
|
||||
|
||||
@Inject
|
||||
AntiBotService(Settings settings, Messages messages, PermissionsManager permissionsManager,
|
||||
@ -58,7 +58,7 @@ public class AntiBotService implements SettingsDependent {
|
||||
duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION);
|
||||
int sensibility = settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY);
|
||||
int interval = settings.getProperty(ProtectionSettings.ANTIBOT_INTERVAL) * 1000;
|
||||
flaggedCounter = new AtomicCounter(sensibility, interval);
|
||||
flaggedCounter = new AtomicIntervalCounter(sensibility, interval);
|
||||
|
||||
// Stop existing protection
|
||||
stopProtection();
|
||||
|
@ -1,12 +1,12 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
public class AtomicCounter {
|
||||
public class AtomicIntervalCounter {
|
||||
private final int threshold;
|
||||
private final int interval;
|
||||
private int count;
|
||||
private long lastInsert;
|
||||
|
||||
public AtomicCounter(int threshold, int interval) {
|
||||
public AtomicIntervalCounter(int threshold, int interval) {
|
||||
this.threshold = threshold;
|
||||
this.interval = interval;
|
||||
reset();
|
@ -646,7 +646,7 @@ public class PlayerListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotInterfereWithUnrestrictedUser() {
|
||||
public void shouldNotInterfereWithUnrestrictedUser() throws FailedVerificationException {
|
||||
// given
|
||||
String name = "Player01";
|
||||
Player player = mockPlayerWithName(name);
|
||||
@ -658,12 +658,13 @@ public class PlayerListenerTest {
|
||||
|
||||
// then
|
||||
verify(validationService).isUnrestricted(name);
|
||||
verify(onJoinVerifier).checkSingleSession(name);
|
||||
verifyNoModifyingCalls(event);
|
||||
verifyNoInteractions(onJoinVerifier);
|
||||
verifyNoMoreInteractions(onJoinVerifier);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopHandlingForFullServer() {
|
||||
public void shouldStopHandlingForFullServer() throws FailedVerificationException {
|
||||
// given
|
||||
String name = "someone";
|
||||
Player player = mockPlayerWithName(name);
|
||||
@ -676,12 +677,14 @@ public class PlayerListenerTest {
|
||||
|
||||
// then
|
||||
verify(validationService).isUnrestricted(name);
|
||||
verify(onJoinVerifier, only()).refusePlayerForFullServer(event);
|
||||
verify(onJoinVerifier).checkSingleSession(name);
|
||||
verify(onJoinVerifier).refusePlayerForFullServer(event);
|
||||
verifyNoMoreInteractions(onJoinVerifier);
|
||||
verifyNoModifyingCalls(event);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopHandlingEventForBadResult() {
|
||||
public void shouldStopHandlingEventForBadResult() throws FailedVerificationException {
|
||||
// given
|
||||
String name = "someone";
|
||||
Player player = mockPlayerWithName(name);
|
||||
@ -696,7 +699,8 @@ public class PlayerListenerTest {
|
||||
|
||||
// then
|
||||
verify(validationService).isUnrestricted(name);
|
||||
verify(onJoinVerifier, only()).refusePlayerForFullServer(event);
|
||||
verify(onJoinVerifier).checkSingleSession(name);
|
||||
verify(onJoinVerifier).refusePlayerForFullServer(event);
|
||||
verifyNoModifyingCalls(event);
|
||||
}
|
||||
|
||||
@ -715,7 +719,6 @@ public class PlayerListenerTest {
|
||||
|
||||
// then
|
||||
verify(validationService).isUnrestricted(name);
|
||||
verify(onJoinVerifier).checkSingleSession(name);
|
||||
verify(onJoinVerifier).checkIsValidName(name);
|
||||
verifyNoInteractions(dataSource);
|
||||
verifyNoModifyingCalls(preLoginEvent);
|
||||
|
Loading…
Reference in New Issue
Block a user