From 7b5a857f744159d0b0fbf0feb7a0d4fd9091c793 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 7 Oct 2016 19:19:12 +0200 Subject: [PATCH] Remove useless packages --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +-- src/main/java/fr/xephi/authme/api/API.java | 10 +-- src/main/java/fr/xephi/authme/api/NewAPI.java | 10 +-- .../initialization/OnShutdownPlayerSaver.java | 6 +- .../authme/listener/ListenerService.java | 10 +-- .../xephi/authme/listener/ServerListener.java | 16 ++--- .../authme/process/join/AsynchronousJoin.java | 8 +-- .../GeoIpService.java} | 8 +-- .../PluginHookService.java} | 6 +- .../authme/service/ValidationService.java | 5 +- .../fr/xephi/authme/settings/SpawnLoader.java | 14 ++-- .../authme/task/purge/PurgeExecutor.java | 6 +- .../java/fr/xephi/authme/api/NewAPITest.java | 6 +- .../authme/listener/ListenerServiceTest.java | 10 +-- .../authme/listener/ServerListenerTest.java | 20 +++--- .../GeoIpServiceTest.java} | 19 ++--- .../PluginHookServiceTest.java} | 69 ++++++++++--------- .../authme/service/ValidationServiceTest.java | 21 +++--- .../authme/settings/SpawnLoaderTest.java | 4 +- 19 files changed, 128 insertions(+), 128 deletions(-) rename src/main/java/fr/xephi/authme/{geoip/GeoIpManager.java => service/GeoIpService.java} (96%) rename src/main/java/fr/xephi/authme/{hooks/PluginHooks.java => service/PluginHookService.java} (97%) rename src/test/java/fr/xephi/authme/{geoip/GeoIpManagerTest.java => service/GeoIpServiceTest.java} (83%) rename src/test/java/fr/xephi/authme/{hooks/PluginHooksTest.java => service/PluginHookServiceTest.java} (73%) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index eaee0347d..04922d4a9 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -26,6 +26,7 @@ import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.security.crypts.SHA256; import fr.xephi.authme.service.BackupService; +import fr.xephi.authme.service.GeoIpService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -33,7 +34,6 @@ import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.task.CleanupTask; import fr.xephi.authme.task.purge.PurgeService; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.util.PlayerUtils; import org.bukkit.Server; @@ -74,7 +74,7 @@ public class AuthMe extends JavaPlugin { private DataSource database; private BukkitService bukkitService; private Injector injector; - private GeoIpManager geoIpManager; + private GeoIpService geoIpService; private PlayerCache playerCache; /** @@ -248,7 +248,7 @@ public class AuthMe extends JavaPlugin { permsMan = injector.getSingleton(PermissionsManager.class); bukkitService = injector.getSingleton(BukkitService.class); commandHandler = injector.getSingleton(CommandHandler.class); - geoIpManager = injector.getSingleton(GeoIpManager.class); + geoIpService = injector.getSingleton(GeoIpService.class); // Trigger construction of API classes; they will keep track of the singleton injector.getSingleton(NewAPI.class); @@ -374,7 +374,7 @@ public class AuthMe extends JavaPlugin { .replace("{SERVER}", server.getServerName()) .replace("{VERSION}", server.getBukkitVersion()) // TODO: We should cache info like this, maybe with a class that extends Player? - .replace("{COUNTRY}", geoIpManager.getCountryName(ipAddress)); + .replace("{COUNTRY}", geoIpService.getCountryName(ipAddress)); } diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 8073cf632..7fa027882 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; @@ -28,7 +28,7 @@ public class API { private static DataSource dataSource; private static PasswordSecurity passwordSecurity; private static Management management; - private static PluginHooks pluginHooks; + private static PluginHookService pluginHookService; private static ValidationService validationService; /* @@ -36,12 +36,12 @@ public class API { */ @Inject API(AuthMe instance, DataSource dataSource, PasswordSecurity passwordSecurity, Management management, - PluginHooks pluginHooks, ValidationService validationService) { + PluginHookService pluginHookService, ValidationService validationService) { API.instance = instance; API.dataSource = dataSource; API.passwordSecurity = passwordSecurity; API.management = management; - API.pluginHooks = pluginHooks; + API.pluginHookService = pluginHookService; API.validationService = validationService; } @@ -171,7 +171,7 @@ public class API { * @return true if player is an npc */ public boolean isNPC(Player player) { - return pluginHooks.isNpc(player); + return pluginHookService.isNpc(player); } } diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index d42d765d0..5805e4afd 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -4,7 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; @@ -27,7 +27,7 @@ public class NewAPI { public static NewAPI singleton; public final AuthMe plugin; - private final PluginHooks pluginHooks; + private final PluginHookService pluginHookService; private final DataSource dataSource; private final PasswordSecurity passwordSecurity; private final Management management; @@ -38,10 +38,10 @@ public class NewAPI { * Constructor for NewAPI. */ @Inject - NewAPI(AuthMe plugin, PluginHooks pluginHooks, DataSource dataSource, PasswordSecurity passwordSecurity, + NewAPI(AuthMe plugin, PluginHookService pluginHookService, DataSource dataSource, PasswordSecurity passwordSecurity, Management management, ValidationService validationService, PlayerCache playerCache) { this.plugin = plugin; - this.pluginHooks = pluginHooks; + this.pluginHookService = pluginHookService; this.dataSource = dataSource; this.passwordSecurity = passwordSecurity; this.management = management; @@ -100,7 +100,7 @@ public class NewAPI { * @return true if the player is an npc */ public boolean isNPC(Player player) { - return pluginHooks.isNpc(player); + return pluginHookService.isNpc(player); } /** diff --git a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java index 079fc76a2..6141e47ef 100644 --- a/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java +++ b/src/main/java/fr/xephi/authme/initialization/OnShutdownPlayerSaver.java @@ -5,7 +5,7 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.backup.LimboPlayerStorage; import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -36,7 +36,7 @@ public class OnShutdownPlayerSaver { @Inject private SpawnLoader spawnLoader; @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private PlayerCache playerCache; @@ -54,7 +54,7 @@ public class OnShutdownPlayerSaver { private void savePlayer(Player player) { final String name = player.getName().toLowerCase(); - if (pluginHooks.isNpc(player) || validationService.isUnrestricted(name)) { + if (pluginHookService.isNpc(player) || validationService.isUnrestricted(name)) { return; } if (limboCache.hasPlayerData(name)) { diff --git a/src/main/java/fr/xephi/authme/listener/ListenerService.java b/src/main/java/fr/xephi/authme/listener/ListenerService.java index 279bfd6c2..03928bf5d 100644 --- a/src/main/java/fr/xephi/authme/listener/ListenerService.java +++ b/src/main/java/fr/xephi/authme/listener/ListenerService.java @@ -2,7 +2,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; @@ -20,17 +20,17 @@ import javax.inject.Inject; class ListenerService implements SettingsDependent { private final DataSource dataSource; - private final PluginHooks pluginHooks; + private final PluginHookService pluginHookService; private final PlayerCache playerCache; private final ValidationService validationService; private boolean isRegistrationForced; @Inject - ListenerService(Settings settings, DataSource dataSource, PluginHooks pluginHooks, + ListenerService(Settings settings, DataSource dataSource, PluginHookService pluginHookService, PlayerCache playerCache, ValidationService validationService) { this.dataSource = dataSource; - this.pluginHooks = pluginHooks; + this.pluginHookService = pluginHookService; this.playerCache = playerCache; this.validationService = validationService; reload(settings); @@ -79,7 +79,7 @@ class ListenerService implements SettingsDependent { * @return true if the associated event should be canceled, false otherwise */ public boolean shouldCancelEvent(Player player) { - return player != null && !checkAuth(player.getName()) && !pluginHooks.isNpc(player); + return player != null && !checkAuth(player.getName()) && !pluginHookService.isNpc(player); } @Override diff --git a/src/main/java/fr/xephi/authme/listener/ServerListener.java b/src/main/java/fr/xephi/authme/listener/ServerListener.java index e3cbb813a..909ab4f26 100644 --- a/src/main/java/fr/xephi/authme/listener/ServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/ServerListener.java @@ -1,7 +1,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.listener.protocollib.ProtocolLibService; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; @@ -17,7 +17,7 @@ import javax.inject.Inject; public class ServerListener implements Listener { @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private SpawnLoader spawnLoader; @Inject @@ -38,13 +38,13 @@ public class ServerListener implements Listener { permissionsManager.onPluginDisable(pluginName); if ("Essentials".equalsIgnoreCase(pluginName)) { - pluginHooks.unhookEssentials(); + pluginHookService.unhookEssentials(); ConsoleLogger.info("Essentials has been disabled: unhooking"); } else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) { - pluginHooks.unhookMultiverse(); + pluginHookService.unhookMultiverse(); ConsoleLogger.info("Multiverse-Core has been disabled: unhooking"); } else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) { - pluginHooks.unhookCombatPlus(); + pluginHookService.unhookCombatPlus(); ConsoleLogger.info("CombatTagPlus has been disabled: unhooking"); } else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) { spawnLoader.unloadEssentialsSpawn(); @@ -68,11 +68,11 @@ public class ServerListener implements Listener { permissionsManager.onPluginEnable(pluginName); if ("Essentials".equalsIgnoreCase(pluginName)) { - pluginHooks.tryHookToEssentials(); + pluginHookService.tryHookToEssentials(); } else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) { - pluginHooks.tryHookToMultiverse(); + pluginHookService.tryHookToMultiverse(); } else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) { - pluginHooks.tryHookToCombatPlus(); + pluginHookService.tryHookToCombatPlus(); } else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) { spawnLoader.loadEssentialsSpawn(); } else if ("ProtocolLib".equalsIgnoreCase(pluginName)) { diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index 5ea7ebcba..89e7a671e 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -8,7 +8,7 @@ import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.ProtectInventoryEvent; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.AuthGroupType; import fr.xephi.authme.permission.PlayerStatePermission; @@ -61,7 +61,7 @@ public class AsynchronousJoin implements AsynchronousProcess { private SessionManager sessionManager; @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private BukkitService bukkitService; @@ -95,7 +95,7 @@ public class AsynchronousJoin implements AsynchronousProcess { } if (service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) { - pluginHooks.setEssentialsSocialSpyStatus(player, false); + pluginHookService.setEssentialsSocialSpyStatus(player, false); } if (isNameRestricted(name, ip, player.getAddress().getHostName())) { @@ -172,7 +172,7 @@ public class AsynchronousJoin implements AsynchronousProcess { player.setWalkSpeed(0.0f); } player.setNoDamageTicks(registrationTimeout); - if (pluginHooks.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) { + if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) { player.performCommand("motd"); } if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { diff --git a/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java similarity index 96% rename from src/main/java/fr/xephi/authme/geoip/GeoIpManager.java rename to src/main/java/fr/xephi/authme/service/GeoIpService.java index bd397a97c..f1335c7df 100644 --- a/src/main/java/fr/xephi/authme/geoip/GeoIpManager.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.geoip; +package fr.xephi.authme.service; import com.google.common.annotations.VisibleForTesting; import com.maxmind.geoip.LookupService; @@ -17,7 +17,7 @@ import java.net.URLConnection; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; -public class GeoIpManager { +public class GeoIpService { private static final String LICENSE = "[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com"; private static final String GEOIP_URL = @@ -28,14 +28,14 @@ public class GeoIpManager { private final File dataFile; @Inject - GeoIpManager(@DataFolder File dataFolder) { + GeoIpService(@DataFolder File dataFolder) { this.dataFile = new File(dataFolder, "GeoIP.dat"); // Fires download of recent data or the initialization of the look up service isDataAvailable(); } @VisibleForTesting - GeoIpManager(@DataFolder File dataFolder, LookupService lookupService) { + GeoIpService(@DataFolder File dataFolder, LookupService lookupService) { this.dataFile = dataFolder; this.lookupService = lookupService; } diff --git a/src/main/java/fr/xephi/authme/hooks/PluginHooks.java b/src/main/java/fr/xephi/authme/service/PluginHookService.java similarity index 97% rename from src/main/java/fr/xephi/authme/hooks/PluginHooks.java rename to src/main/java/fr/xephi/authme/service/PluginHookService.java index f3a066e19..9ebcd712a 100644 --- a/src/main/java/fr/xephi/authme/hooks/PluginHooks.java +++ b/src/main/java/fr/xephi/authme/service/PluginHookService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.hooks; +package fr.xephi.authme.service; import ch.jalu.injector.annotations.NoFieldScan; import com.earth2me.essentials.Essentials; @@ -19,7 +19,7 @@ import java.io.File; * Hooks into third-party plugins and allows to perform actions on them. */ @NoFieldScan -public class PluginHooks { +public class PluginHookService { private final PluginManager pluginManager; private Essentials essentials; @@ -32,7 +32,7 @@ public class PluginHooks { * @param pluginManager The server's plugin manager */ @Inject - public PluginHooks(PluginManager pluginManager) { + public PluginHookService(PluginManager pluginManager) { this.pluginManager = pluginManager; tryHookToCombatPlus(); tryHookToEssentials(); diff --git a/src/main/java/fr/xephi/authme/service/ValidationService.java b/src/main/java/fr/xephi/authme/service/ValidationService.java index 030657ce5..e3a69fc94 100644 --- a/src/main/java/fr/xephi/authme/service/ValidationService.java +++ b/src/main/java/fr/xephi/authme/service/ValidationService.java @@ -2,7 +2,6 @@ package fr.xephi.authme.service; import com.github.authme.configme.properties.Property; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; @@ -36,7 +35,7 @@ public class ValidationService implements Reloadable { @Inject private PermissionsManager permissionsManager; @Inject - private GeoIpManager geoIpManager; + private GeoIpService geoIpService; private Pattern passwordRegex; private Set unrestrictedNames; @@ -115,7 +114,7 @@ public class ValidationService implements Reloadable { return true; } - String countryCode = geoIpManager.getCountryCode(hostAddress); + String countryCode = geoIpService.getCountryCode(hostAddress); return validateWhitelistAndBlacklist(countryCode, ProtectionSettings.COUNTRIES_WHITELIST, ProtectionSettings.COUNTRIES_BLACKLIST); diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java index 3345ef8df..b3a06f5eb 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -2,7 +2,7 @@ package fr.xephi.authme.settings; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.settings.properties.HooksSettings; @@ -32,7 +32,7 @@ public class SpawnLoader implements Reloadable { private final File authMeConfigurationFile; private final Settings settings; - private final PluginHooks pluginHooks; + private final PluginHookService pluginHookService; private FileConfiguration authMeConfiguration; private String[] spawnPriority; private Location essentialsSpawn; @@ -42,18 +42,18 @@ public class SpawnLoader implements Reloadable { * * @param pluginFolder The AuthMe data folder * @param settings The setting instance - * @param pluginHooks The plugin hooks instance + * @param pluginHookService The plugin hooks instance * @param dataSource The plugin auth database instance */ @Inject - SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHooks pluginHooks, + SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHookService pluginHookService, DataSource dataSource) { File spawnFile = new File(pluginFolder, "spawn.yml"); // TODO ljacqu 20160312: Check if resource could be copied and handle the case if not FileUtils.copyFileFromResource(spawnFile, "spawn.yml"); this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml"); this.settings = settings; - this.pluginHooks = pluginHooks; + this.pluginHookService = pluginHookService; reload(); } @@ -112,7 +112,7 @@ public class SpawnLoader implements Reloadable { */ public void loadEssentialsSpawn() { // EssentialsSpawn cannot run without Essentials, so it's fine to get the Essentials data folder - File essentialsFolder = pluginHooks.getEssentialsDataFolder(); + File essentialsFolder = pluginHookService.getEssentialsDataFolder(); if (essentialsFolder == null) { return; } @@ -160,7 +160,7 @@ public class SpawnLoader implements Reloadable { break; case "multiverse": if (settings.getProperty(HooksSettings.MULTIVERSE)) { - spawnLoc = pluginHooks.getMultiverseSpawn(world); + spawnLoc = pluginHookService.getMultiverseSpawn(world); } break; case "essentials": diff --git a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java index 43476e750..985630cfa 100644 --- a/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java +++ b/src/main/java/fr/xephi/authme/task/purge/PurgeExecutor.java @@ -2,7 +2,7 @@ package fr.xephi.authme.task.purge; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PurgeSettings; @@ -33,7 +33,7 @@ class PurgeExecutor { private PermissionsManager permissionsManager; @Inject - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Inject private BukkitService bukkitService; @@ -172,7 +172,7 @@ class PurgeExecutor { } int i = 0; - File essentialsDataFolder = pluginHooks.getEssentialsDataFolder(); + File essentialsDataFolder = pluginHookService.getEssentialsDataFolder(); if (essentialsDataFolder == null) { ConsoleLogger.info("Cannot purge Essentials: plugin is not loaded"); return; diff --git a/src/test/java/fr/xephi/authme/api/NewAPITest.java b/src/test/java/fr/xephi/authme/api/NewAPITest.java index 64e4c7c85..02dfbec26 100644 --- a/src/test/java/fr/xephi/authme/api/NewAPITest.java +++ b/src/test/java/fr/xephi/authme/api/NewAPITest.java @@ -5,7 +5,7 @@ import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.service.ValidationService; @@ -46,7 +46,7 @@ public class NewAPITest { @Mock private AuthMe authMe; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Mock private ValidationService validationService; @Mock @@ -86,7 +86,7 @@ public class NewAPITest { public void shouldReturnIfPlayerIsNpc() { // given Player player = mock(Player.class); - given(pluginHooks.isNpc(player)).willReturn(true); + given(pluginHookService.isNpc(player)).willReturn(true); // when boolean result = api.isNPC(player); diff --git a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java index bc999c533..15f9e7973 100644 --- a/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java +++ b/src/test/java/fr/xephi/authme/listener/ListenerServiceTest.java @@ -5,7 +5,7 @@ import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.service.ValidationService; @@ -41,7 +41,7 @@ public class ListenerServiceTest { private DataSource dataSource; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Mock private PlayerCache playerCache; @@ -161,14 +161,14 @@ public class ListenerServiceTest { Player player = mockPlayerWithName(playerName); EntityEvent event = mock(EntityEvent.class); given(event.getEntity()).willReturn(player); - given(pluginHooks.isNpc(player)).willReturn(true); + given(pluginHookService.isNpc(player)).willReturn(true); // when boolean result = listenerService.shouldCancelEvent(event); // then assertThat(result, equalTo(false)); - verify(pluginHooks).isNpc(player); + verify(pluginHookService).isNpc(player); } @Test @@ -215,7 +215,7 @@ public class ListenerServiceTest { assertThat(result, equalTo(true)); verify(playerCache).isAuthenticated(playerName); verifyZeroInteractions(dataSource); - verify(pluginHooks).isNpc(player); + verify(pluginHookService).isNpc(player); } private static Player mockPlayerWithName(String name) { diff --git a/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java b/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java index 0c1686a11..266a437ff 100644 --- a/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java @@ -1,7 +1,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.listener.protocollib.ProtocolLibService; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.settings.SpawnLoader; @@ -41,7 +41,7 @@ public class ServerListenerTest { private PermissionsManager permissionsManager; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Mock private ProtocolLibService protocolLibService; @@ -59,7 +59,7 @@ public class ServerListenerTest { checkEnableHandling(ESSENTIALS, new Runnable() { @Override public void run() { - verify(pluginHooks).tryHookToEssentials(); + verify(pluginHookService).tryHookToEssentials(); } }); checkEnableHandling(ESSENTIALS_SPAWN, new Runnable() { @@ -71,13 +71,13 @@ public class ServerListenerTest { checkEnableHandling(MULTIVERSE, new Runnable() { @Override public void run() { - verify(pluginHooks).tryHookToMultiverse(); + verify(pluginHookService).tryHookToMultiverse(); } }); checkEnableHandling(COMBAT_TAG, new Runnable() { @Override public void run() { - verify(pluginHooks).tryHookToCombatPlus(); + verify(pluginHookService).tryHookToCombatPlus(); } }); checkEnableHandling(PROTOCOL_LIB, new Runnable() { @@ -99,7 +99,7 @@ public class ServerListenerTest { checkDisableHandling(ESSENTIALS, new Runnable() { @Override public void run() { - verify(pluginHooks).unhookEssentials(); + verify(pluginHookService).unhookEssentials(); } }); checkDisableHandling(ESSENTIALS_SPAWN, new Runnable() { @@ -111,13 +111,13 @@ public class ServerListenerTest { checkDisableHandling(MULTIVERSE, new Runnable() { @Override public void run() { - verify(pluginHooks).unhookMultiverse(); + verify(pluginHookService).unhookMultiverse(); } }); checkDisableHandling(COMBAT_TAG, new Runnable() { @Override public void run() { - verify(pluginHooks).unhookCombatPlus(); + verify(pluginHookService).unhookCombatPlus(); } }); checkDisableHandling(PROTOCOL_LIB, new Runnable() { @@ -164,8 +164,8 @@ public class ServerListenerTest { } private void verifyNoMoreInteractionsAndReset() { - verifyNoMoreInteractions(permissionsManager, pluginHooks, protocolLibService, spawnLoader); - reset(permissionsManager, pluginHooks, protocolLibService, spawnLoader); + verifyNoMoreInteractions(permissionsManager, pluginHookService, protocolLibService, spawnLoader); + reset(permissionsManager, pluginHookService, protocolLibService, spawnLoader); } private static T mockEventWithPluginName(Class eventClass, String name) { diff --git a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java b/src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java similarity index 83% rename from src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java rename to src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java index a4d459ca5..5d1d9681f 100644 --- a/src/test/java/fr/xephi/authme/geoip/GeoIpManagerTest.java +++ b/src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java @@ -1,7 +1,8 @@ -package fr.xephi.authme.geoip; +package fr.xephi.authme.service; import com.maxmind.geoip.Country; import com.maxmind.geoip.LookupService; +import fr.xephi.authme.service.GeoIpService; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -22,12 +23,12 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** - * Test for {@link GeoIpManager}. + * Test for {@link GeoIpService}. */ @RunWith(MockitoJUnitRunner.class) -public class GeoIpManagerTest { +public class GeoIpServiceTest { - private GeoIpManager geoIpManager; + private GeoIpService geoIpService; private File dataFolder; @Mock private LookupService lookupService; @@ -38,7 +39,7 @@ public class GeoIpManagerTest { @Before public void initializeGeoLiteApi() throws IOException { dataFolder = temporaryFolder.newFolder(); - geoIpManager = new GeoIpManager(dataFolder, lookupService); + geoIpService = new GeoIpService(dataFolder, lookupService); } @Test @@ -51,7 +52,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoIpManager.getCountryCode(ip); + String result = geoIpService.getCountryCode(ip); // then assertThat(result, equalTo(countryCode)); @@ -64,7 +65,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoIpManager.getCountryCode(ip); + String result = geoIpService.getCountryCode(ip); // then assertThat(result, equalTo("--")); @@ -81,7 +82,7 @@ public class GeoIpManagerTest { given(lookupService.getCountry(ip)).willReturn(country); // when - String result = geoIpManager.getCountryName(ip); + String result = geoIpService.getCountryName(ip); // then assertThat(result, equalTo(countryName)); @@ -94,7 +95,7 @@ public class GeoIpManagerTest { String ip = "127.0.0.1"; // when - String result = geoIpManager.getCountryName(ip); + String result = geoIpService.getCountryName(ip); // then assertThat(result, equalTo("N/A")); diff --git a/src/test/java/fr/xephi/authme/hooks/PluginHooksTest.java b/src/test/java/fr/xephi/authme/service/PluginHookServiceTest.java similarity index 73% rename from src/test/java/fr/xephi/authme/hooks/PluginHooksTest.java rename to src/test/java/fr/xephi/authme/service/PluginHookServiceTest.java index eef561443..970bcef45 100644 --- a/src/test/java/fr/xephi/authme/hooks/PluginHooksTest.java +++ b/src/test/java/fr/xephi/authme/service/PluginHookServiceTest.java @@ -1,10 +1,11 @@ -package fr.xephi.authme.hooks; +package fr.xephi.authme.service; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.TestHelper; import org.bukkit.Location; @@ -29,9 +30,9 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** - * Test for {@link PluginHooks}. + * Test for {@link PluginHookService}. */ -public class PluginHooksTest { +public class PluginHookServiceTest { /** The plugin name of Essentials. */ private static final String ESSENTIALS = "Essentials"; @@ -47,15 +48,15 @@ public class PluginHooksTest { public void shouldHookIntoEssentials() { // given PluginManager pluginManager = mock(PluginManager.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class); - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false)); // when - pluginHooks.tryHookToEssentials(); + pluginHookService.tryHookToEssentials(); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true)); } // Note ljacqu 20160312: Cannot test with Multiverse or CombatTagPlus because their classes are declared final @@ -67,10 +68,10 @@ public class PluginHooksTest { setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class); // when - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(true)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true)); } @Test @@ -80,10 +81,10 @@ public class PluginHooksTest { setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class); // when - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // then - assertThat(pluginHooks.isMultiverseAvailable(), equalTo(true)); + assertThat(pluginHookService.isMultiverseAvailable(), equalTo(true)); } @Test @@ -96,10 +97,10 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, ESSENTIALS, ess); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - File dataFolder = pluginHooks.getEssentialsDataFolder(); + File dataFolder = pluginHookService.getEssentialsDataFolder(); // then assertThat(dataFolder, equalTo(essDataFolder)); @@ -109,10 +110,10 @@ public class PluginHooksTest { public void shouldReturnNullForUnhookedEssentials() { // given PluginManager pluginManager = mock(PluginManager.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - File result = pluginHooks.getEssentialsDataFolder(); + File result = pluginHookService.getEssentialsDataFolder(); // then assertThat(result, nullValue()); @@ -129,10 +130,10 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, ESSENTIALS, ess); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - pluginHooks.setEssentialsSocialSpyStatus(player, true); + pluginHookService.setEssentialsSocialSpyStatus(player, true); // then verify(ess).getUser(player); @@ -142,10 +143,10 @@ public class PluginHooksTest { @Test public void shouldNotDoAnythingForUnhookedEssentials() { // given - PluginHooks pluginHooks = new PluginHooks(mock(PluginManager.class)); + PluginHookService pluginHookService = new PluginHookService(mock(PluginManager.class)); // when/then - pluginHooks.setEssentialsSocialSpyStatus(mock(Player.class), false); + pluginHookService.setEssentialsSocialSpyStatus(mock(Player.class), false); } @Test @@ -154,15 +155,15 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class); setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - pluginHooks.unhookEssentials(); - pluginHooks.unhookMultiverse(); + pluginHookService.unhookEssentials(); + pluginHookService.unhookMultiverse(); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false)); - assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false)); + assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false)); } @Test @@ -173,23 +174,23 @@ public class PluginHooksTest { doThrow(IllegalStateException.class).when(pluginManager).getPlugin(anyString()); // when - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // then - assertThat(pluginHooks.isEssentialsAvailable(), equalTo(false)); - assertThat(pluginHooks.isMultiverseAvailable(), equalTo(false)); - assertThat(pluginHooks.isCombatTagPlusAvailable(), equalTo(false)); + assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false)); + assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false)); + assertThat(pluginHookService.isCombatTagPlusAvailable(), equalTo(false)); } @Test public void shouldReturnNullForUnavailableMultiverse() { // given PluginManager pluginManager = mock(PluginManager.class); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); World world = mock(World.class); // when - Location result = pluginHooks.getMultiverseSpawn(world); + Location result = pluginHookService.getMultiverseSpawn(world); // then assertThat(result, nullValue()); @@ -211,10 +212,10 @@ public class PluginHooksTest { PluginManager pluginManager = mock(PluginManager.class); setPluginAvailable(pluginManager, MULTIVERSE, multiverse); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - Location spawn = pluginHooks.getMultiverseSpawn(world); + Location spawn = pluginHookService.getMultiverseSpawn(world); // then assertThat(spawn, equalTo(location)); @@ -234,10 +235,10 @@ public class PluginHooksTest { MultiverseCore multiverse = mock(MultiverseCore.class); setPluginAvailable(pluginManager, MULTIVERSE, multiverse); given(multiverse.getMVWorldManager()).willReturn(mvWorldManager); - PluginHooks pluginHooks = new PluginHooks(pluginManager); + PluginHookService pluginHookService = new PluginHookService(pluginManager); // when - Location spawn = pluginHooks.getMultiverseSpawn(world); + Location spawn = pluginHookService.getMultiverseSpawn(world); // then assertThat(spawn, nullValue()); diff --git a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java index 1a1cbbe45..a011d212e 100644 --- a/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/ValidationServiceTest.java @@ -5,7 +5,6 @@ import ch.jalu.injector.testing.DelayedInjectionRunner; import ch.jalu.injector.testing.InjectDelayed; import com.google.common.base.Strings; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.message.MessageKey; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; @@ -45,7 +44,7 @@ public class ValidationServiceTest { @Mock private PermissionsManager permissionsManager; @Mock - private GeoIpManager geoIpManager; + private GeoIpService geoIpService; @BeforeInjecting public void createService() { @@ -266,7 +265,7 @@ public class ValidationServiceTest { // then assertThat(result, equalTo(true)); - verifyZeroInteractions(geoIpManager); + verifyZeroInteractions(geoIpService); } @Test @@ -275,14 +274,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "127.0.0.1"; - given(geoIpManager.getCountryCode(ip)).willReturn("CH"); + given(geoIpService.getCountryCode(ip)).willReturn("CH"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } @Test @@ -291,14 +290,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it")); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.emptyList()); String ip = "123.45.67.89"; - given(geoIpManager.getCountryCode(ip)).willReturn("BR"); + given(geoIpService.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } @Test @@ -307,14 +306,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "127.0.0.1"; - given(geoIpManager.getCountryCode(ip)).willReturn("BR"); + given(geoIpService.getCountryCode(ip)).willReturn("BR"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(true)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } @Test @@ -323,14 +322,14 @@ public class ValidationServiceTest { given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.emptyList()); given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it")); String ip = "123.45.67.89"; - given(geoIpManager.getCountryCode(ip)).willReturn("IT"); + given(geoIpService.getCountryCode(ip)).willReturn("IT"); // when boolean result = validationService.isCountryAdmitted(ip); // then assertThat(result, equalTo(false)); - verify(geoIpManager).getCountryCode(ip); + verify(geoIpService).getCountryCode(ip); } private static void assertErrorEquals(ValidationResult validationResult, MessageKey messageKey, String... args) { diff --git a/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java b/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java index 8449b121f..1ca06911a 100644 --- a/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java +++ b/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java @@ -6,7 +6,7 @@ import ch.jalu.injector.testing.InjectDelayed; import com.google.common.io.Files; import fr.xephi.authme.TestHelper; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.hooks.PluginHooks; +import fr.xephi.authme.service.PluginHookService; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.settings.properties.RestrictionSettings; import org.bukkit.Location; @@ -42,7 +42,7 @@ public class SpawnLoaderTest { private DataSource dataSource; @Mock - private PluginHooks pluginHooks; + private PluginHookService pluginHookService; @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();