mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-03-27 22:05:45 +01:00
#727 Remove CommandService from ExecutableCommand interface
(work in progress) - Inject CommandService like other classes instead of passing it as method parameter - Not solved: cyclic dependency CommandInitializer > ExecutableCommand > CommandService > CommandInitializer...
This commit is contained in:
parent
40ce01f65e
commit
c6778b566d
src
main/java/fr/xephi/authme/command
CommandHandler.javaExecutableCommand.javaPlayerCommand.java
executable
HelpCommand.java
authme
AccountsCommand.javaAuthMeCommand.javaChangePasswordAdminCommand.javaConverterCommand.javaFirstSpawnCommand.javaForceLoginCommand.javaGetEmailCommand.javaGetIpCommand.javaLastLoginCommand.javaPurgeBannedPlayersCommand.javaPurgeCommand.javaPurgeLastPositionCommand.javaRegisterAdminCommand.javaReloadCommand.javaSetEmailCommand.javaSetFirstSpawnCommand.javaSetSpawnCommand.javaSpawnCommand.javaSwitchAntiBotCommand.javaUnregisterAdminCommand.javaVersionCommand.java
captcha
changepassword
email
login
logout
register
unregister
test/java/fr/xephi/authme/command
CommandHandlerTest.javaCommandUtilsTest.javaPlayerCommandTest.java
executable
authme
AccountsCommandTest.javaAuthMeCommandTest.javaChangePasswordAdminCommandTest.javaFirstSpawnCommandTest.javaForceLoginCommandTest.javaGetEmailCommandTest.javaGetIpCommandTest.javaLastLoginCommandTest.javaPurgeLastPositionCommandTest.javaRegisterAdminCommandTest.javaReloadCommandTest.javaSetFirstSpawnCommandTest.javaSetSpawnCommandTest.javaSpawnCommandTest.javaSwitchAntiBotCommandTest.java
captcha
changepassword
email
login
logout
register
help
@ -23,17 +23,12 @@ public class CommandHandler {
|
||||
*/
|
||||
private static final double SUGGEST_COMMAND_THRESHOLD = 0.75;
|
||||
|
||||
private final CommandService commandService;
|
||||
private final PermissionsManager permissionsManager;
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
@Inject
|
||||
public CommandHandler(CommandService commandService, PermissionsManager permissionsManager) {
|
||||
this.commandService = commandService;
|
||||
this.permissionsManager = permissionsManager;
|
||||
}
|
||||
private CommandService commandService;
|
||||
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
|
||||
/**
|
||||
* Map a command that was invoked to the proper {@link CommandDescription} or return a useful error
|
||||
@ -86,7 +81,7 @@ public class CommandHandler {
|
||||
private void executeCommand(CommandSender sender, FoundCommandResult result) {
|
||||
ExecutableCommand executableCommand = result.getCommandDescription().getExecutableCommand();
|
||||
List<String> arguments = result.getArguments();
|
||||
executableCommand.executeCommand(sender, arguments, commandService);
|
||||
executableCommand.executeCommand(sender, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,12 +10,11 @@ import java.util.List;
|
||||
public interface ExecutableCommand {
|
||||
|
||||
/**
|
||||
* Execute the command with the given arguments.
|
||||
* Executes the command with the given arguments.
|
||||
*
|
||||
* @param sender The command sender.
|
||||
* @param arguments The arguments.
|
||||
* @param commandService The command service.
|
||||
* @param sender the command sender (initiator of the command)
|
||||
* @param arguments the arguments
|
||||
*/
|
||||
void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService);
|
||||
void executeCommand(CommandSender sender, List<String> arguments);
|
||||
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Common base type for player-only commands, handling the verification that the command sender is indeed a player.
|
||||
*/
|
||||
public abstract class PlayerCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
if (sender instanceof Player) {
|
||||
runCommand((Player) sender, arguments, commandService);
|
||||
runCommand((Player) sender, arguments);
|
||||
} else {
|
||||
String alternative = getAlternativeCommand();
|
||||
if (alternative != null) {
|
||||
@ -25,19 +25,18 @@ public abstract class PlayerCommand implements ExecutableCommand {
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command with the given player and arguments.
|
||||
* Runs the command with the given player and arguments.
|
||||
*
|
||||
* @param player The player who initiated the command
|
||||
* @param arguments The arguments supplied with the command
|
||||
* @param commandService The command service
|
||||
* @param player the player who initiated the command
|
||||
* @param arguments the arguments supplied with the command
|
||||
*/
|
||||
protected abstract void runCommand(Player player, List<String> arguments, CommandService commandService);
|
||||
protected abstract void runCommand(Player player, List<String> arguments);
|
||||
|
||||
/**
|
||||
* Return an alternative command (textual representation) that is not restricted to players only.
|
||||
* Example: {@code "authme register <playerName> <password>"}
|
||||
* Returns an alternative command (textual representation) that is not restricted to players only.
|
||||
* Example: {@code "/authme register <playerName> <password>"}
|
||||
*
|
||||
* @return Alternative command not only for players, or null if not applicable
|
||||
* @return Alternative command not restricted to players, or null if not applicable
|
||||
*/
|
||||
protected String getAlternativeCommand() {
|
||||
return null;
|
||||
|
@ -9,6 +9,7 @@ import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.command.FoundResultStatus.MISSING_BASE_COMMAND;
|
||||
@ -16,10 +17,14 @@ import static fr.xephi.authme.command.FoundResultStatus.UNKNOWN_LABEL;
|
||||
|
||||
public class HelpCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
|
||||
// Convention: arguments is not the actual invoked arguments but the command that was invoked,
|
||||
// e.g. "/authme help register" would typically be arguments = [register], but here we pass [authme, register]
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
FoundCommandResult result = commandService.mapPartsToCommand(sender, arguments);
|
||||
|
||||
FoundResultStatus resultStatus = result.getResultStatus();
|
||||
|
@ -23,9 +23,11 @@ public class AccountsCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
final String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
|
||||
// Assumption: a player name cannot contain '.'
|
||||
|
@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -14,7 +13,7 @@ import java.util.List;
|
||||
public class AuthMeCommand implements ExecutableCommand {
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
sender.sendMessage(ChatColor.GREEN + "This server is running " + AuthMe.getPluginName() + " v"
|
||||
+ AuthMe.getPluginVersion() + " b" + AuthMe.getPluginBuildNumber()+ "! " + ChatColor.RED + "<3");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Use the command " + ChatColor.GOLD + "/authme help" + ChatColor.YELLOW
|
||||
|
@ -37,9 +37,11 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
// Get the player and password
|
||||
final String playerName = arguments.get(0);
|
||||
final String playerPass = arguments.get(1);
|
||||
|
@ -22,6 +22,9 @@ import java.util.List;
|
||||
*/
|
||||
public class ConverterCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@ -29,7 +32,7 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
private AuthMeServiceInitializer initializer;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
// Get the conversion job
|
||||
String job = arguments.get(0);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,7 +16,7 @@ public class FirstSpawnCommand extends PlayerCommand {
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
if (spawnLoader.getFirstSpawn() == null) {
|
||||
player.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
|
||||
} else {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.process.Management;
|
||||
@ -28,7 +27,7 @@ public class ForceLoginCommand implements ExecutableCommand {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
// Get the player query
|
||||
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
|
||||
|
@ -18,8 +18,11 @@ public class GetEmailCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
|
||||
PlayerAuth auth = dataSource.getAuth(playerName);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -15,7 +14,7 @@ public class GetIpCommand implements ExecutableCommand {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
// Get the player query
|
||||
String playerName = arguments.get(0);
|
||||
|
||||
|
@ -19,8 +19,11 @@ public class LastLoginCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
// Get the player
|
||||
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
|
||||
|
||||
|
@ -1,22 +1,19 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.task.PurgeTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Command for purging data of banned players. Depending on the settings
|
||||
* it purges (deletes) data from third-party plugins as well.
|
||||
@ -33,7 +30,7 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
// Get the list of banned players
|
||||
Set<String> namedBanned = new HashSet<>();
|
||||
Set<OfflinePlayer> bannedPlayers = bukkitService.getBannedPlayers();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.task.PurgeTask;
|
||||
@ -28,7 +27,7 @@ public class PurgeCommand implements ExecutableCommand {
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
// Get the days parameter
|
||||
String daysStr = arguments.get(0);
|
||||
|
||||
|
@ -18,8 +18,11 @@ public class PurgeLastPositionCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
|
||||
|
||||
if ("*".equals(playerName)) {
|
||||
|
@ -25,6 +25,9 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@ -35,8 +38,7 @@ public class RegisterAdminCommand implements ExecutableCommand {
|
||||
private ValidationService validationService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
// Get the player name and password
|
||||
final String playerName = arguments.get(0);
|
||||
final String playerPass = arguments.get(1);
|
||||
|
@ -31,8 +31,11 @@ public class ReloadCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
try {
|
||||
settings.reload();
|
||||
ConsoleLogger.setLoggingOptions(settings);
|
||||
|
@ -20,6 +20,9 @@ public class SetEmailCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@ -27,8 +30,7 @@ public class SetEmailCommand implements ExecutableCommand {
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
// Get the player name and email address
|
||||
final String playerName = arguments.get(0);
|
||||
final String playerEmail = arguments.get(1);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,7 +13,7 @@ public class SetFirstSpawnCommand extends PlayerCommand {
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
if (spawnLoader.setFirstSpawn(player.getLocation())) {
|
||||
player.sendMessage("[AuthMe] Correctly defined new first spawn point");
|
||||
} else {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,7 +13,7 @@ public class SetSpawnCommand extends PlayerCommand {
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
if (spawnLoader.setSpawn(player.getLocation())) {
|
||||
player.sendMessage("[AuthMe] Correctly defined new spawn point");
|
||||
} else {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,7 +13,7 @@ public class SpawnCommand extends PlayerCommand {
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
if (spawnLoader.getSpawn() == null) {
|
||||
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
||||
} else {
|
||||
|
@ -20,8 +20,11 @@ public class SwitchAntiBotCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private AntiBot antiBot;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
if (arguments.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] AntiBot status: " + antiBot.getAntiBotStatus().name());
|
||||
return;
|
||||
|
@ -33,6 +33,9 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@ -42,8 +45,11 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private LimboCache limboCache;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments) {
|
||||
// Get the player name
|
||||
String playerName = arguments.get(0);
|
||||
String playerNameLowerCase = playerName.toLowerCase();
|
||||
@ -88,14 +94,14 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
final String playerNameLowerCase = target.getName().toLowerCase();
|
||||
|
||||
Utils.teleportToSpawn(target);
|
||||
LimboCache.getInstance().addLimboPlayer(target);
|
||||
limboCache.addLimboPlayer(target);
|
||||
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(authMe, playerNameLowerCase, target), timeOut);
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTask(id);
|
||||
limboCache.getLimboPlayer(playerNameLowerCase).setTimeoutTask(id);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTask(
|
||||
limboCache.getLimboPlayer(playerNameLowerCase).setMessageTask(
|
||||
bukkitService.runTask(new MessageTask(bukkitService, authMe.getMessages(),
|
||||
playerNameLowerCase, MessageKey.REGISTER_MESSAGE, interval)));
|
||||
|
||||
|
@ -19,8 +19,11 @@ public class VersionCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
// Show some version info
|
||||
sender.sendMessage(ChatColor.GOLD + "==========[ " + commandService.getProperty(HELP_HEADER)
|
||||
+ " ABOUT ]==========");
|
||||
|
@ -18,8 +18,11 @@ public class CaptchaCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private CaptchaManager captchaManager;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
final String playerName = player.getName().toLowerCase();
|
||||
|
||||
if (playerCache.isAuthenticated(playerName)) {
|
||||
|
@ -20,6 +20,9 @@ import java.util.List;
|
||||
*/
|
||||
public class ChangePasswordCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@ -34,7 +37,7 @@ public class ChangePasswordCommand extends PlayerCommand {
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
String oldPassword = arguments.get(0);
|
||||
String newPassword = arguments.get(1);
|
||||
|
||||
|
@ -17,8 +17,11 @@ public class AddEmailCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
String email = arguments.get(0);
|
||||
String emailConfirmation = arguments.get(1);
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,7 +16,7 @@ public class ChangeEmailCommand extends PlayerCommand {
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
String playerMailOld = arguments.get(0);
|
||||
String playerMailNew = arguments.get(1);
|
||||
|
||||
|
@ -6,6 +6,7 @@ import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -14,8 +15,11 @@ import java.util.List;
|
||||
*/
|
||||
public class EmailBaseCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
FoundCommandResult result = commandService.mapPartsToCommand(sender, Collections.singletonList("email"));
|
||||
commandService.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
|
||||
}
|
||||
|
@ -1,11 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@ -19,12 +13,19 @@ import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class RecoverEmailCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@ -32,10 +33,11 @@ public class RecoverEmailCommand extends PlayerCommand {
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
// TODO #655: Remove injected AuthMe instance once Authme#mail is encapsulated
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
final String playerMail = arguments.get(0);
|
||||
final String playerName = player.getName();
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.login;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,7 +16,7 @@ public class LoginCommand extends PlayerCommand {
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
final String password = arguments.get(0);
|
||||
management.performLogin(player, password, false);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.logout;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,7 +16,7 @@ public class LogoutCommand extends PlayerCommand {
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
management.performLogout(player);
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,11 @@ public class RegisterCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
if (commandService.getProperty(SecuritySettings.PASSWORD_HASH) == HashAlgorithm.TWO_FACTOR) {
|
||||
//for two factor auth we don't need to check the usage
|
||||
management.performRegister(player, "", "", true);
|
||||
|
@ -15,8 +15,11 @@ public class UnregisterCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Inject
|
||||
private CommandService commandService;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
String playerPass = arguments.get(0);
|
||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||
|
||||
|
@ -47,7 +47,10 @@ public class CommandHandlerTest {
|
||||
private CommandHandler handler;
|
||||
|
||||
@Mock
|
||||
private CommandService serviceMock;
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private CommandMapper commandMapper;
|
||||
|
||||
@Mock
|
||||
private PermissionsManager permissionsManager;
|
||||
@ -66,17 +69,17 @@ public class CommandHandlerTest {
|
||||
ExecutableCommand executableCommand = mock(ExecutableCommand.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getExecutableCommand()).willReturn(executableCommand);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
.willReturn(new FoundCommandResult(command, asList("Authme", "Login"), asList("myPass"), 0.0, SUCCESS));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("Authme", "Login", "myPass"));
|
||||
|
||||
verify(executableCommand).executeCommand(eq(sender), captor.capture(), any(CommandService.class));
|
||||
verify(executableCommand).executeCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("myPass"));
|
||||
|
||||
// Ensure that no error message was issued to the command sender
|
||||
@ -90,14 +93,14 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class)))
|
||||
.willReturn(new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, NO_PERMISSION));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
verify(command, never()).getExecutableCommand();
|
||||
verify(sender).sendMessage(argThat(containsString("don't have permission")));
|
||||
@ -110,7 +113,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
|
||||
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(true);
|
||||
|
||||
@ -118,7 +121,7 @@ public class CommandHandlerTest {
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@ -134,7 +137,7 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, INCORRECT_ARGUMENTS));
|
||||
given(permissionsManager.hasPermission(sender, command.getPermission())).willReturn(false);
|
||||
|
||||
@ -142,7 +145,7 @@ public class CommandHandlerTest {
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@ -158,14 +161,14 @@ public class CommandHandlerTest {
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.0, MISSING_BASE_COMMAND));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
verify(command, never()).getExecutableCommand();
|
||||
verify(sender).sendMessage(argThat(containsString("Failed to parse")));
|
||||
@ -179,14 +182,14 @@ public class CommandHandlerTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 0.01, UNKNOWN_LABEL));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@ -207,14 +210,14 @@ public class CommandHandlerTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getLabels()).willReturn(Collections.singletonList("test_cmd"));
|
||||
given(serviceMock.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
given(commandService.mapPartsToCommand(any(CommandSender.class), anyListOf(String.class))).willReturn(
|
||||
new FoundCommandResult(command, asList("unreg"), asList("testPlayer"), 1.0, UNKNOWN_LABEL));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("unreg", "testPlayer"));
|
||||
|
||||
verify(command, never()).getExecutableCommand();
|
||||
@ -235,17 +238,17 @@ public class CommandHandlerTest {
|
||||
ExecutableCommand executableCommand = mock(ExecutableCommand.class);
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getExecutableCommand()).willReturn(executableCommand);
|
||||
given(serviceMock.mapPartsToCommand(eq(sender), anyListOf(String.class)))
|
||||
given(commandService.mapPartsToCommand(eq(sender), anyListOf(String.class)))
|
||||
.willReturn(new FoundCommandResult(command, asList("AuthMe", "LOGIN"), asList("testArg"), 0.0, SUCCESS));
|
||||
|
||||
// when
|
||||
handler.processCommand(sender, bukkitLabel, bukkitArgs);
|
||||
|
||||
// then
|
||||
verify(serviceMock).mapPartsToCommand(eq(sender), captor.capture());
|
||||
verify(commandService).mapPartsToCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("AuthMe", "LOGIN", "testArg"));
|
||||
|
||||
verify(command.getExecutableCommand()).executeCommand(eq(sender), captor.capture(), eq(serviceMock));
|
||||
verify(command.getExecutableCommand()).executeCommand(eq(sender), captor.capture());
|
||||
assertThat(captor.getValue(), contains("testArg"));
|
||||
|
||||
verify(sender, never()).sendMessage(anyString());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -113,6 +114,12 @@ public class CommandUtilsTest {
|
||||
checkArgumentCount(command, 1, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructor() {
|
||||
// given / when / then
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandUtils.class);
|
||||
}
|
||||
|
||||
|
||||
private static void checkArgumentCount(CommandDescription command, int expectedMin, int expectedMax) {
|
||||
assertThat(CommandUtils.getMinNumberOfArguments(command), equalTo(expectedMin));
|
||||
|
@ -27,7 +27,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandImpl command = new PlayerCommandImpl();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), mock(CommandService.class));
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("only for players")));
|
||||
@ -42,7 +42,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandImpl command = new PlayerCommandImpl();
|
||||
|
||||
// when
|
||||
command.executeCommand(player, arguments, service);
|
||||
command.executeCommand(player, arguments);
|
||||
|
||||
// then
|
||||
verify(player, times(1)).sendMessage("testarg2");
|
||||
@ -55,7 +55,7 @@ public class PlayerCommandTest {
|
||||
PlayerCommandWithAlt command = new PlayerCommandWithAlt();
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), mock(CommandService.class));
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(sender, times(1)).sendMessage(argThat(containsString("use /authme test <command> instead")));
|
||||
@ -64,14 +64,14 @@ public class PlayerCommandTest {
|
||||
|
||||
private static class PlayerCommandImpl extends PlayerCommand {
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
player.sendMessage(arguments.get(1));
|
||||
}
|
||||
}
|
||||
|
||||
private static class PlayerCommandWithAlt extends PlayerCommand {
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
throw new IllegalStateException("Should not be called");
|
||||
}
|
||||
@Override
|
||||
|
@ -53,7 +53,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Arrays.asList("Toaster", "Pester"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -69,7 +69,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAuth("someuser")).willReturn(null);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -85,7 +85,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp(anyString())).willReturn(Collections.<String>emptyList());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -101,7 +101,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("56.78.90.123")).willReturn(Collections.singletonList("SomeUser"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -119,7 +119,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("123.45.67.89")).willReturn(Collections.<String>emptyList());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -134,7 +134,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("24.24.48.48")).willReturn(Collections.singletonList("SomeUser"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -149,7 +149,7 @@ public class AccountsCommandTest {
|
||||
given(dataSource.getAllAuthsByIp("98.76.41.122")).willReturn(Arrays.asList("Tester", "Lester", "Taster"));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, arguments, service);
|
||||
command.executeCommand(sender, arguments);
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
@ -24,10 +23,9 @@ public class AuthMeCommandTest {
|
||||
// given
|
||||
ExecutableCommand command = new AuthMeCommand();
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandService service = mock(CommandService.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String> emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
ArgumentCaptor<String> messagesCaptor = ArgumentCaptor.forClass(String.class);
|
||||
|
@ -69,7 +69,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
new ValidationResult(MessageKey.PASSWORD_IS_USERNAME_ERROR));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("bobby", "Bobby"), service);
|
||||
command.executeCommand(sender, Arrays.asList("bobby", "Bobby"));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword("Bobby", "bobby");
|
||||
@ -88,7 +88,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -113,7 +113,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -141,7 +141,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -168,7 +168,7 @@ public class ChangePasswordAdminCommandTest {
|
||||
given(dataSource.updatePassword(auth)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(player, password), service);
|
||||
command.executeCommand(sender, Arrays.asList(player, password));
|
||||
runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -33,9 +32,6 @@ public class FirstSpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldTeleportToFirstSpawn() {
|
||||
// given
|
||||
@ -44,7 +40,7 @@ public class FirstSpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).teleport(firstSpawn);
|
||||
@ -58,7 +54,7 @@ public class FirstSpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).sendMessage(argThat(containsString("spawn has failed")));
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.process.Management;
|
||||
@ -43,9 +42,6 @@ public class ForceLoginCommandTest {
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Test
|
||||
public void shouldRejectOfflinePlayer() {
|
||||
// given
|
||||
@ -55,7 +51,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@ -71,7 +67,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@ -89,7 +85,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@ -107,7 +103,7 @@ public class ForceLoginCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
@ -125,7 +121,7 @@ public class ForceLoginCommandTest {
|
||||
given(sender.getName()).willReturn(senderName);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), commandService);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(senderName);
|
||||
|
@ -31,9 +31,6 @@ public class GetEmailCommandTest {
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@ -42,9 +39,10 @@ public class GetEmailCommandTest {
|
||||
// given
|
||||
String user = "myTestUser";
|
||||
given(dataSource.getAuth(user)).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(user), service);
|
||||
command.executeCommand(sender, Collections.singletonList(user));
|
||||
|
||||
// then
|
||||
verify(service).send(sender, MessageKey.UNKNOWN_USER);
|
||||
@ -58,9 +56,10 @@ public class GetEmailCommandTest {
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(auth.getEmail()).willReturn(email);
|
||||
given(dataSource.getAuth(user)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(user), service);
|
||||
command.executeCommand(sender, Collections.singletonList(user));
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString(email)));
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -31,22 +30,18 @@ public class GetIpCommandTest {
|
||||
@InjectMocks
|
||||
private GetIpCommand command;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
@Test
|
||||
public void shouldGetIpOfPlayer() {
|
||||
// given
|
||||
given(bukkitService.getPlayerExact(anyString())).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("Testt"), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList("Testt"));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact("Testt");
|
||||
@ -60,9 +55,10 @@ public class GetIpCommandTest {
|
||||
String ip = "123.34.56.88";
|
||||
Player player = mockPlayer(playerName, ip);
|
||||
given(bukkitService.getPlayerExact(playerName)).willReturn(player);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(playerName), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList(playerName));
|
||||
|
||||
// then
|
||||
verify(bukkitService).getPlayerExact(playerName);
|
||||
|
@ -29,6 +29,9 @@ import static org.mockito.Mockito.verify;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LastLoginCommandTest {
|
||||
|
||||
private static final long HOUR_IN_MSEC = 3600 * 1000;
|
||||
private static final long DAY_IN_MSEC = 24 * HOUR_IN_MSEC;
|
||||
|
||||
@InjectMocks
|
||||
private LastLoginCommand command;
|
||||
|
||||
@ -38,20 +41,16 @@ public class LastLoginCommandTest {
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
private static final long HOUR_IN_MSEC = 3600 * 1000;
|
||||
private static final long DAY_IN_MSEC = 24 * HOUR_IN_MSEC;
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonExistentUser() {
|
||||
// given
|
||||
String player = "tester";
|
||||
given(dataSource.getAuth(player)).willReturn(null);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(player), service);
|
||||
command.executeCommand(sender, Collections.singletonList(player));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@ -68,9 +67,10 @@ public class LastLoginCommandTest {
|
||||
given(auth.getLastLogin()).willReturn(lastLogin);
|
||||
given(auth.getIp()).willReturn("123.45.66.77");
|
||||
given(dataSource.getAuth(player)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(player), service);
|
||||
command.executeCommand(sender, Collections.singletonList(player));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@ -87,6 +87,7 @@ public class LastLoginCommandTest {
|
||||
public void shouldDisplayLastLoginOfCommandSender() {
|
||||
// given
|
||||
String name = "CommandSender";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(sender.getName()).willReturn(name);
|
||||
|
||||
long lastLogin = System.currentTimeMillis() -
|
||||
@ -97,7 +98,7 @@ public class LastLoginCommandTest {
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(name);
|
||||
|
@ -35,8 +35,6 @@ public class PurgeLastPositionCommandTest {
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
@Test
|
||||
public void shouldPurgeLastPosOfUser() {
|
||||
@ -44,9 +42,10 @@ public class PurgeLastPositionCommandTest {
|
||||
String player = "_Bobby";
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
given(dataSource.getAuth(player)).willReturn(auth);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(player), service);
|
||||
command.executeCommand(sender, Collections.singletonList(player));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@ -64,7 +63,7 @@ public class PurgeLastPositionCommandTest {
|
||||
given(dataSource.getAuth(player)).willReturn(auth);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(player);
|
||||
@ -76,9 +75,10 @@ public class PurgeLastPositionCommandTest {
|
||||
public void shouldHandleNonExistentUser() {
|
||||
// given
|
||||
String name = "invalidPlayer";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(name), service);
|
||||
command.executeCommand(sender, Collections.singletonList(name));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAuth(name);
|
||||
@ -92,9 +92,10 @@ public class PurgeLastPositionCommandTest {
|
||||
PlayerAuth auth2 = mock(PlayerAuth.class);
|
||||
PlayerAuth auth3 = mock(PlayerAuth.class);
|
||||
given(dataSource.getAllAuths()).willReturn(Arrays.asList(auth1, auth2, auth3));
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("*"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("*"));
|
||||
|
||||
// then
|
||||
verify(dataSource).getAllAuths();
|
||||
|
@ -71,7 +71,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword(password, user);
|
||||
@ -89,7 +89,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -111,7 +111,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -136,7 +136,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
|
||||
// then
|
||||
@ -163,7 +163,7 @@ public class RegisterAdminCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(user, password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(user, password));
|
||||
TestHelper.runInnerRunnable(bukkitService);
|
||||
runSyncDelayedTask(bukkitService);
|
||||
|
||||
|
@ -50,6 +50,9 @@ public class ReloadCommandTest {
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
@ -66,17 +69,16 @@ public class ReloadCommandTest {
|
||||
public void shouldReload() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandService service = mock(CommandService.class);
|
||||
given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL);
|
||||
given(dataSource.getType()).willReturn(DataSourceType.MYSQL);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(settings).reload();
|
||||
verify(initializer).performReloadOnServices();
|
||||
verify(service).send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
verify(commandService).send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -89,7 +91,7 @@ public class ReloadCommandTest {
|
||||
given(dataSource.getType()).willReturn(DataSourceType.MYSQL);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(settings).reload();
|
||||
@ -107,7 +109,7 @@ public class ReloadCommandTest {
|
||||
given(dataSource.getType()).willReturn(DataSourceType.SQLITE);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(settings).reload();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -30,8 +29,6 @@ public class SetFirstSpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldSetFirstSpawn() {
|
||||
@ -42,7 +39,7 @@ public class SetFirstSpawnCommandTest {
|
||||
given(spawnLoader.setFirstSpawn(location)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setFirstSpawn(location);
|
||||
@ -58,7 +55,7 @@ public class SetFirstSpawnCommandTest {
|
||||
given(spawnLoader.setFirstSpawn(location)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setFirstSpawn(location);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -30,8 +29,6 @@ public class SetSpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldSetSpawn() {
|
||||
@ -42,7 +39,7 @@ public class SetSpawnCommandTest {
|
||||
given(spawnLoader.setSpawn(location)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setSpawn(location);
|
||||
@ -58,7 +55,7 @@ public class SetSpawnCommandTest {
|
||||
given(spawnLoader.setSpawn(location)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(spawnLoader).setSpawn(location);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -33,8 +32,6 @@ public class SpawnCommandTest {
|
||||
@Mock
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Mock
|
||||
private CommandService service;
|
||||
|
||||
@Test
|
||||
public void shouldTeleportToSpawn() {
|
||||
@ -44,7 +41,7 @@ public class SpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).teleport(spawn);
|
||||
@ -58,7 +55,7 @@ public class SpawnCommandTest {
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(player).sendMessage(argThat(containsString("Spawn has failed")));
|
||||
|
@ -44,7 +44,7 @@ public class SwitchAntiBotCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), service);
|
||||
command.executeCommand(sender, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("status: ACTIVE")));
|
||||
@ -56,7 +56,7 @@ public class SwitchAntiBotCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("on"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("on"));
|
||||
|
||||
// then
|
||||
verify(antiBot).overrideAntiBotStatus(true);
|
||||
@ -69,7 +69,7 @@ public class SwitchAntiBotCommandTest {
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("Off"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("Off"));
|
||||
|
||||
// then
|
||||
verify(antiBot).overrideAntiBotStatus(false);
|
||||
@ -84,7 +84,7 @@ public class SwitchAntiBotCommandTest {
|
||||
given(service.mapPartsToCommand(sender, asList("authme", "antibot"))).willReturn(foundCommandResult);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("wrong"), service);
|
||||
command.executeCommand(sender, Collections.singletonList("wrong"));
|
||||
|
||||
// then
|
||||
verify(antiBot, never()).overrideAntiBotStatus(anyBoolean());
|
||||
|
@ -44,7 +44,7 @@ public class CaptchaCommandTest {
|
||||
given(playerCache.isAuthenticated(name)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("123"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("123"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
@ -59,7 +59,7 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.isCaptchaRequired(name)).willReturn(false);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("1234"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("1234"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(player, MessageKey.USAGE_LOGIN);
|
||||
@ -78,7 +78,7 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.checkCode(name, captchaCode)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode), commandService);
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode));
|
||||
|
||||
// then
|
||||
verify(captchaManager).isCaptchaRequired(name);
|
||||
@ -102,7 +102,7 @@ public class CaptchaCommandTest {
|
||||
given(captchaManager.generateCode(name)).willReturn(newCode);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode), commandService);
|
||||
command.executeCommand(player, Collections.singletonList(captchaCode));
|
||||
|
||||
// then
|
||||
verify(captchaManager).isCaptchaRequired(name);
|
||||
|
@ -73,7 +73,7 @@ public class ChangePasswordCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("only for players")));
|
||||
@ -85,7 +85,7 @@ public class ChangePasswordCommandTest {
|
||||
CommandSender sender = initPlayerWithName("name", false);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("pass", "pass"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("pass", "pass"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.NOT_LOGGED_IN);
|
||||
@ -100,7 +100,7 @@ public class ChangePasswordCommandTest {
|
||||
.willReturn(new ValidationResult(MessageKey.INVALID_PASSWORD_LENGTH));
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("tester", password), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("tester", password));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword(password, "abc12");
|
||||
@ -114,7 +114,7 @@ public class ChangePasswordCommandTest {
|
||||
given(validationService.validatePassword("abc123", "parker")).willReturn(new ValidationResult());
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("abc123", "abc123"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("abc123", "abc123"));
|
||||
|
||||
// then
|
||||
verify(validationService).validatePassword("abc123", "parker");
|
||||
|
@ -41,7 +41,7 @@ public class AddEmailCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@ -55,7 +55,7 @@ public class AddEmailCommandTest {
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(email, email), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(email, email));
|
||||
|
||||
// then
|
||||
verify(management).performAddEmail(sender, email);
|
||||
@ -69,7 +69,7 @@ public class AddEmailCommandTest {
|
||||
given(commandService.validateEmail(email)).willReturn(true);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(email, "wrongConf"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList(email, "wrongConf"));
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -30,9 +29,6 @@ public class ChangeEmailCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerSender() {
|
||||
@ -40,7 +36,7 @@ public class ChangeEmailCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@ -52,7 +48,7 @@ public class ChangeEmailCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("new.mail@example.org", "old_mail@example.org"), commandService);
|
||||
command.executeCommand(sender, Arrays.asList("new.mail@example.org", "old_mail@example.org"));
|
||||
|
||||
// then
|
||||
verify(management).performChangeEmail(sender, "new.mail@example.org", "old_mail@example.org");
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.login;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -33,8 +32,6 @@ public class LoginCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Test
|
||||
public void shouldStopIfSenderIsNotAPlayer() {
|
||||
@ -42,7 +39,7 @@ public class LoginCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@ -55,7 +52,7 @@ public class LoginCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("password"), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList("password"));
|
||||
|
||||
// then
|
||||
verify(management).performLogin(eq(sender), eq("password"), eq(false));
|
||||
|
@ -1,11 +1,9 @@
|
||||
package fr.xephi.authme.command.executable.logout;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@ -33,13 +31,6 @@ public class LogoutCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private CommandService commandService;
|
||||
|
||||
@Before
|
||||
public void initializeAuthMeMock() {
|
||||
commandService = mock(CommandService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopIfSenderIsNotAPlayer() {
|
||||
@ -47,7 +38,7 @@ public class LogoutCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(management);
|
||||
@ -60,7 +51,7 @@ public class LogoutCommandTest {
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("password"), commandService);
|
||||
command.executeCommand(sender, Collections.singletonList("password"));
|
||||
|
||||
// then
|
||||
verify(management).performLogout(sender);
|
||||
|
@ -49,8 +49,6 @@ public class RegisterCommandTest {
|
||||
@Mock
|
||||
private Management management;
|
||||
|
||||
@Mock
|
||||
private Player sender;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
@ -70,7 +68,7 @@ public class RegisterCommandTest {
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, new ArrayList<String>(), commandService);
|
||||
command.executeCommand(sender, new ArrayList<String>());
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("Player only!")));
|
||||
@ -81,21 +79,25 @@ public class RegisterCommandTest {
|
||||
public void shouldForwardToManagementForTwoFactor() {
|
||||
// given
|
||||
given(commandService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.TWO_FACTOR);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), commandService);
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(management).performRegister(sender, "", "", true);
|
||||
verify(management).performRegister(player, "", "", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnErrorForEmptyArguments() {
|
||||
// given / when
|
||||
command.executeCommand(sender, Collections.<String>emptyList(), commandService);
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.<String>emptyList());
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@ -103,12 +105,13 @@ public class RegisterCommandTest {
|
||||
public void shouldReturnErrorForMissingConfirmation() {
|
||||
// given
|
||||
given(commandService.getProperty(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION)).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("arrrr"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("arrrr"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@ -117,12 +120,13 @@ public class RegisterCommandTest {
|
||||
// given
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("test@example.org"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("test@example.org"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@ -132,12 +136,13 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(false);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList("myMail@example.tld"), commandService);
|
||||
command.executeCommand(player, Collections.singletonList("myMail@example.tld"));
|
||||
|
||||
// then
|
||||
verify(sender).sendMessage(argThat(containsString("no email address")));
|
||||
verify(player).sendMessage(argThat(containsString("no email address")));
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@ -150,13 +155,14 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(playerMail, playerMail), commandService);
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(commandService).send(sender, MessageKey.INVALID_EMAIL);
|
||||
verify(commandService).send(player, MessageKey.INVALID_EMAIL);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@ -169,12 +175,13 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(playerMail, "invalid"), commandService);
|
||||
command.executeCommand(player, Arrays.asList(playerMail, "invalid"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.USAGE_REGISTER);
|
||||
verify(commandService).send(player, MessageKey.USAGE_REGISTER);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@ -189,35 +196,40 @@ public class RegisterCommandTest {
|
||||
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
|
||||
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
|
||||
given(commandService.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn("server@example.com");
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList(playerMail, playerMail), commandService);
|
||||
command.executeCommand(player, Arrays.asList(playerMail, playerMail));
|
||||
|
||||
// then
|
||||
verify(commandService).validateEmail(playerMail);
|
||||
verify(management).performRegister(eq(sender), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
||||
verify(management).performRegister(eq(player), argThat(stringWithLength(passLength)), eq(playerMail), eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidPasswordConfirmation() {
|
||||
// given
|
||||
given(commandService.getProperty(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION)).willReturn(true);
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Arrays.asList("myPass", "mypass"), commandService);
|
||||
command.executeCommand(player, Arrays.asList("myPass", "mypass"));
|
||||
|
||||
// then
|
||||
verify(commandService).send(sender, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
verify(commandService).send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
verifyZeroInteractions(management);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformPasswordValidation() {
|
||||
// given / when
|
||||
command.executeCommand(sender, Collections.singletonList("myPass"), commandService);
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("myPass"));
|
||||
|
||||
// then
|
||||
verify(management).performRegister(sender, "myPass", "", true);
|
||||
verify(management).performRegister(player, "myPass", "", true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.TestCommandsUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -66,4 +67,10 @@ public class CommandSyntaxHelperTest {
|
||||
assertThat(result, equalTo(ChatColor.WHITE + "/email" + ChatColor.YELLOW + " [player]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveHiddenConstructor() {
|
||||
// given / when / then
|
||||
TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandSyntaxHelper.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user