Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into commands-refactor
Conflicts: src/main/java/fr/xephi/authme/command/CommandUtils.java src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java
This commit is contained in:
@@ -5,6 +5,7 @@ import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.WrapperMock;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -269,6 +270,42 @@ public class CommandInitializerTest {
|
||||
walkThroughCommands(commands, adminPermissionChecker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that multiple CommandDescription instances pointing to the same ExecutableCommand use the same
|
||||
* count of arguments.
|
||||
*/
|
||||
@Test
|
||||
@Ignore // TODO #306 ljacqu 20151214: Un-ignore this test and fix the offending command
|
||||
public void shouldPointToSameExecutableCommandWithConsistentArgumentCount() {
|
||||
// given
|
||||
final Map<Class<? extends ExecutableCommand>, Integer> mandatoryArguments = new HashMap<>();
|
||||
final Map<Class<? extends ExecutableCommand>, Integer> totalArguments = new HashMap<>();
|
||||
|
||||
BiConsumer argChecker = new BiConsumer() {
|
||||
@Override
|
||||
public void accept(CommandDescription command, int depth) {
|
||||
testCollectionForCommand(command, CommandUtils.getMinNumberOfArguments(command), mandatoryArguments);
|
||||
testCollectionForCommand(command, CommandUtils.getMaxNumberOfArguments(command), totalArguments);
|
||||
}
|
||||
private void testCollectionForCommand(CommandDescription command, int argCount,
|
||||
Map<Class<? extends ExecutableCommand>, Integer> collection) {
|
||||
final Class<? extends ExecutableCommand> clazz = command.getExecutableCommand().getClass();
|
||||
Integer existingCount = collection.get(clazz);
|
||||
if (existingCount != null) {
|
||||
String commandDescription = "Command with label '" + command.getLabels().get(0) + "' and parent '"
|
||||
+ (command.getParent() != null ? command.getLabels().get(0) : "null") + "' ";
|
||||
assertThat(commandDescription + "should point to " + clazz + " with arguments consistent to others",
|
||||
argCount, equalTo(existingCount));
|
||||
} else {
|
||||
collection.put(clazz, argCount);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// when / then
|
||||
walkThroughCommands(commands, argChecker);
|
||||
}
|
||||
|
||||
|
||||
// ------------
|
||||
// Helper methods
|
||||
|
||||
@@ -2,9 +2,11 @@ package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.WrapperMock;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.File;
|
||||
@@ -14,6 +16,8 @@ import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
@@ -137,4 +141,58 @@ public class MessagesIntegrationTest {
|
||||
verify(player).sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendMessageToPlayerWithTagReplacement() {
|
||||
// given
|
||||
MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
|
||||
CommandSender sender = Mockito.mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
messages.send(sender, key, "1234");
|
||||
|
||||
// then
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sender, times(1)).sendMessage(captor.capture());
|
||||
String message = captor.getValue();
|
||||
assertThat(message, equalTo("Use /captcha 1234 to solve the captcha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotThrowForKeyWithNoTagReplacements() {
|
||||
// given
|
||||
MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
// when
|
||||
messages.send(sender, key);
|
||||
|
||||
// then
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(sender, times(1)).sendMessage(captor.capture());
|
||||
String message = captor.getValue();
|
||||
assertThat(message, equalTo("Use /captcha THE_CAPTCHA to solve the captcha"));
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void shouldThrowForInvalidReplacementCount() {
|
||||
// given
|
||||
MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
|
||||
|
||||
// when
|
||||
messages.send(mock(CommandSender.class), key, "rep", "rep2");
|
||||
|
||||
// then - expect exception
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void shouldThrowForReplacementsOnKeyWithNoTags() {
|
||||
// given
|
||||
MessageKey key = MessageKey.UNKNOWN_USER;
|
||||
|
||||
// when
|
||||
messages.send(mock(CommandSender.class), key, "Replacement");
|
||||
|
||||
// then - expect exception
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ import static org.junit.Assert.fail;
|
||||
public class AdminPermissionTest {
|
||||
|
||||
@Test
|
||||
public void shouldStartWithAuthMePrefix() {
|
||||
public void shouldStartWithAuthMeAdminPrefix() {
|
||||
// given
|
||||
String requiredPrefix = "authme.";
|
||||
String requiredPrefix = "authme.admin.";
|
||||
|
||||
// when/then
|
||||
for (AdminPermission permission : AdminPermission.values()) {
|
||||
@@ -26,20 +26,6 @@ public class AdminPermissionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldContainAdminBranch() {
|
||||
// given
|
||||
String requiredBranch = ".admin.";
|
||||
|
||||
// when/then
|
||||
for (AdminPermission permission : AdminPermission.values()) {
|
||||
if (!permission.getNode().contains(requiredBranch)) {
|
||||
fail("The permission '" + permission + "' does not contain with the required branch '"
|
||||
+ requiredBranch + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveUniqueNodes() {
|
||||
// given
|
||||
|
||||
@@ -13,32 +13,13 @@ import static org.junit.Assert.fail;
|
||||
public class PlayerPermissionTest {
|
||||
|
||||
@Test
|
||||
public void shouldStartWithAuthMePrefix() {
|
||||
public void shouldStartWithPlayerPrefix() {
|
||||
// given
|
||||
String requiredPrefix = "authme.";
|
||||
String playerBranch = "authme.player.";
|
||||
|
||||
// when/then
|
||||
for (PlayerPermission permission : PlayerPermission.values()) {
|
||||
if (!permission.getNode().startsWith(requiredPrefix)) {
|
||||
fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldContainPlayerBranch() {
|
||||
// given
|
||||
String playerBranch = ".player.";
|
||||
String adminBranch = ".admin.";
|
||||
|
||||
// when/then
|
||||
for (PlayerPermission permission : PlayerPermission.values()) {
|
||||
if (permission.getNode().contains(adminBranch)) {
|
||||
fail("The permission '" + permission + "' should not use a node with the admin-specific branch '"
|
||||
+ adminBranch + "'");
|
||||
|
||||
} else if (!permission.getNode().contains(playerBranch)) {
|
||||
if (!permission.getNode().startsWith(playerBranch)) {
|
||||
fail("The permission '" + permission + "' should use a node with the player-specific branch '"
|
||||
+ playerBranch + "'");
|
||||
}
|
||||
|
||||
@@ -4,3 +4,4 @@ not_logged_in: 'Apostrophes '' should be loaded correctly, don''t you think?'
|
||||
reg_voluntarily: 'You can register yourself to the server with the command "/register <password> <ConfirmPassword>"'
|
||||
usage_log: '&cUsage: /login <password>'
|
||||
wrong_pwd: '&cWrong password!'
|
||||
wrong_captcha: 'Use /captcha THE_CAPTCHA to solve the captcha'
|
||||
|
||||
Reference in New Issue
Block a user