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