mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 12:45:57 +01:00
Create test that AntiBot is not enabled if Settings disable it
This commit is contained in:
parent
0065a6a827
commit
37a615fa03
@ -3,6 +3,7 @@ package fr.xephi.authme;
|
||||
import fr.xephi.authme.settings.MessageKey;
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -16,6 +17,7 @@ public class AntiBot {
|
||||
|
||||
private static final AuthMe plugin = AuthMe.getInstance();
|
||||
private static final Messages messages = plugin.getMessages();
|
||||
private static Wrapper wrapper = new Wrapper(plugin);
|
||||
private static final List<String> antibotPlayers = new ArrayList<>();
|
||||
private static AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
|
||||
|
||||
@ -52,7 +54,7 @@ public class AntiBot {
|
||||
Bukkit.broadcastMessage(s);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
wrapper.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (antiBotStatus == AntiBotStatus.ACTIVE) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -29,6 +31,10 @@ public class Wrapper {
|
||||
return authMe.getLogger();
|
||||
}
|
||||
|
||||
public BukkitScheduler getScheduler() {
|
||||
return Bukkit.getScheduler();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
36
src/test/java/fr/xephi/authme/AntiBotTest.java
Normal file
36
src/test/java/fr/xephi/authme/AntiBotTest.java
Normal file
@ -0,0 +1,36 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test for {@link AntiBot}.
|
||||
*/
|
||||
public class AntiBotTest {
|
||||
|
||||
private Wrapper wrapper;
|
||||
|
||||
@Before
|
||||
public void setUpMocks() {
|
||||
AuthMeMockUtil.mockAuthMeInstance();
|
||||
wrapper = AuthMeMockUtil.insertMockWrapperInstance(AntiBot.class, "wrapper");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotEnableAntiBot() {
|
||||
// given
|
||||
Settings.enableAntiBot = false;
|
||||
|
||||
// when
|
||||
AntiBot.setupAntiBotService();
|
||||
|
||||
// then
|
||||
verify(wrapper.getScheduler(), never()).scheduleSyncDelayedTask(any(AuthMe.class), any(Runnable.class));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -40,6 +41,11 @@ public class WrapperMock extends Wrapper {
|
||||
return getMock(AuthMe.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitScheduler getScheduler() {
|
||||
return getMock(BukkitScheduler.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T getMock(Class<?> clazz) {
|
||||
Object o = mocks.get(clazz);
|
||||
|
Loading…
Reference in New Issue
Block a user