Fix some unit testing

This commit is contained in:
Gabriele C 2020-01-21 11:27:28 +01:00
parent a2fe62e3ff
commit e1f893afe3
3 changed files with 15 additions and 12 deletions

View File

@ -10,7 +10,7 @@ import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.ProtectionSettings; 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 org.bukkit.scheduler.BukkitTask;
import javax.inject.Inject; import javax.inject.Inject;
@ -35,7 +35,7 @@ public class AntiBotService implements SettingsDependent {
private AntiBotStatus antiBotStatus; private AntiBotStatus antiBotStatus;
private boolean startup; private boolean startup;
private BukkitTask disableTask; private BukkitTask disableTask;
private AtomicCounter flaggedCounter; private AtomicIntervalCounter flaggedCounter;
@Inject @Inject
AntiBotService(Settings settings, Messages messages, PermissionsManager permissionsManager, AntiBotService(Settings settings, Messages messages, PermissionsManager permissionsManager,
@ -58,7 +58,7 @@ public class AntiBotService implements SettingsDependent {
duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION);
int sensibility = settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY); int sensibility = settings.getProperty(ProtectionSettings.ANTIBOT_SENSIBILITY);
int interval = settings.getProperty(ProtectionSettings.ANTIBOT_INTERVAL) * 1000; int interval = settings.getProperty(ProtectionSettings.ANTIBOT_INTERVAL) * 1000;
flaggedCounter = new AtomicCounter(sensibility, interval); flaggedCounter = new AtomicIntervalCounter(sensibility, interval);
// Stop existing protection // Stop existing protection
stopProtection(); stopProtection();

View File

@ -1,12 +1,12 @@
package fr.xephi.authme.util; package fr.xephi.authme.util;
public class AtomicCounter { public class AtomicIntervalCounter {
private final int threshold; private final int threshold;
private final int interval; private final int interval;
private int count; private int count;
private long lastInsert; private long lastInsert;
public AtomicCounter(int threshold, int interval) { public AtomicIntervalCounter(int threshold, int interval) {
this.threshold = threshold; this.threshold = threshold;
this.interval = interval; this.interval = interval;
reset(); reset();

View File

@ -646,7 +646,7 @@ public class PlayerListenerTest {
} }
@Test @Test
public void shouldNotInterfereWithUnrestrictedUser() { public void shouldNotInterfereWithUnrestrictedUser() throws FailedVerificationException {
// given // given
String name = "Player01"; String name = "Player01";
Player player = mockPlayerWithName(name); Player player = mockPlayerWithName(name);
@ -658,12 +658,13 @@ public class PlayerListenerTest {
// then // then
verify(validationService).isUnrestricted(name); verify(validationService).isUnrestricted(name);
verify(onJoinVerifier).checkSingleSession(name);
verifyNoModifyingCalls(event); verifyNoModifyingCalls(event);
verifyNoInteractions(onJoinVerifier); verifyNoMoreInteractions(onJoinVerifier);
} }
@Test @Test
public void shouldStopHandlingForFullServer() { public void shouldStopHandlingForFullServer() throws FailedVerificationException {
// given // given
String name = "someone"; String name = "someone";
Player player = mockPlayerWithName(name); Player player = mockPlayerWithName(name);
@ -676,12 +677,14 @@ public class PlayerListenerTest {
// then // then
verify(validationService).isUnrestricted(name); verify(validationService).isUnrestricted(name);
verify(onJoinVerifier, only()).refusePlayerForFullServer(event); verify(onJoinVerifier).checkSingleSession(name);
verify(onJoinVerifier).refusePlayerForFullServer(event);
verifyNoMoreInteractions(onJoinVerifier);
verifyNoModifyingCalls(event); verifyNoModifyingCalls(event);
} }
@Test @Test
public void shouldStopHandlingEventForBadResult() { public void shouldStopHandlingEventForBadResult() throws FailedVerificationException {
// given // given
String name = "someone"; String name = "someone";
Player player = mockPlayerWithName(name); Player player = mockPlayerWithName(name);
@ -696,7 +699,8 @@ public class PlayerListenerTest {
// then // then
verify(validationService).isUnrestricted(name); verify(validationService).isUnrestricted(name);
verify(onJoinVerifier, only()).refusePlayerForFullServer(event); verify(onJoinVerifier).checkSingleSession(name);
verify(onJoinVerifier).refusePlayerForFullServer(event);
verifyNoModifyingCalls(event); verifyNoModifyingCalls(event);
} }
@ -715,7 +719,6 @@ public class PlayerListenerTest {
// then // then
verify(validationService).isUnrestricted(name); verify(validationService).isUnrestricted(name);
verify(onJoinVerifier).checkSingleSession(name);
verify(onJoinVerifier).checkIsValidName(name); verify(onJoinVerifier).checkIsValidName(name);
verifyNoInteractions(dataSource); verifyNoInteractions(dataSource);
verifyNoModifyingCalls(preLoginEvent); verifyNoModifyingCalls(preLoginEvent);