Testing - start change to non-reflection WrapperMock test setup

This commit is contained in:
ljacqu
2015-11-26 22:25:02 +01:00
parent 38e3bda406
commit 77f2f80eaf
9 changed files with 93 additions and 50 deletions
+3 -3
View File
@@ -15,9 +15,9 @@ import java.util.List;
*/
public class AntiBot {
private static final AuthMe plugin = AuthMe.getInstance();
private static final Messages messages = plugin.getMessages();
private static Wrapper wrapper = Wrapper.getInstance();
private static final Wrapper wrapper = Wrapper.getInstance();
private static final AuthMe plugin = wrapper.getAuthMe();
private static final Messages messages = wrapper.getMessages();
private static final List<String> antibotPlayers = new ArrayList<>();
private static AntiBotStatus antiBotStatus = AntiBotStatus.DISABLED;
@@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.DataSource.DataSourceType;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.util.Wrapper;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
@@ -18,7 +19,7 @@ import java.util.regex.Pattern;
*/
public final class Settings extends YamlConfiguration {
public static final File PLUGIN_FOLDER = AuthMe.getInstance().getDataFolder();
public static final File PLUGIN_FOLDER = Wrapper.getInstance().getDataFolder();
public static final File MODULE_FOLDER = new File(PLUGIN_FOLDER, "modules");
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
@@ -33,8 +33,8 @@ public final class Utils {
private static Method getOnlinePlayers;
static {
plugin = AuthMe.getInstance();
wrapper = Wrapper.getInstance();
plugin = wrapper.getAuthMe();
initializeOnlinePlayersIsCollectionField();
}
@@ -111,8 +111,9 @@ public final class Utils {
* @return True on success, false on failure.
*/
public static boolean addNormal(Player player, String group) {
if (!Settings.isPermissionCheckEnabled)
if (!Settings.isPermissionCheckEnabled) {
return false;
}
// Get the permissions manager, and make sure it's valid
PermissionsManager permsMan = plugin.getPermissionsManager();
@@ -1,10 +1,12 @@
package fr.xephi.authme.util;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.settings.Messages;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.scheduler.BukkitScheduler;
import java.io.File;
import java.util.logging.Logger;
/**
@@ -21,6 +23,15 @@ public class Wrapper {
Wrapper() {
}
/**
* Package-private setter of the singleton field used for tests to inject a mock instance.
*
* @param wrapper The wrapper to use as singleton
*/
static void setSingleton(Wrapper wrapper) {
Wrapper.singleton = wrapper;
}
public static Wrapper getInstance() {
if (singleton == null) {
singleton = new Wrapper();
@@ -40,6 +51,20 @@ public class Wrapper {
return getAuthMe().getLogger();
}
public Messages getMessages() {
return getAuthMe().getMessages();
}
/**
* Return the folder containing plugin data via the AuthMe instance.
*
* @return The plugin data folder
* @see AuthMe#getDataFolder()
*/
public File getDataFolder() {
return getAuthMe().getDataFolder();
}
public BukkitScheduler getScheduler() {
return Bukkit.getScheduler();
}