Create test that AntiBot is not enabled if Settings disable it
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user