#293 Fix tests and create consistency test for English help file
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.CommandInitializer;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests that /messages/help_en.yml contains texts that correspond
|
||||
* to the texts provided in the CommandDescription.
|
||||
*/
|
||||
public class HelpMessagesConsistencyTest {
|
||||
|
||||
private static final File DEFAULT_MESSAGES_FILE = TestHelper.getJarFile("/messages/help_en.yml");
|
||||
|
||||
@Test
|
||||
public void shouldHaveIdenticalTexts() {
|
||||
// given
|
||||
CommandDescription description = getAuthMeRegisterDescription();
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(DEFAULT_MESSAGES_FILE);
|
||||
final String path = "commands.authme.register.";
|
||||
|
||||
// when / then
|
||||
assertThat(configuration.get(path + "description"), equalTo(description.getDescription()));
|
||||
assertThat(configuration.get(path + "detailedDescription"), equalTo(description.getDetailedDescription()));
|
||||
assertThat(configuration.get(path + "arg1.label"), equalTo(description.getArguments().get(0).getName()));
|
||||
assertThat(configuration.get(path + "arg1.description"), equalTo(description.getArguments().get(0).getDescription()));
|
||||
assertThat(configuration.get(path + "arg2.label"), equalTo(description.getArguments().get(1).getName()));
|
||||
assertThat(configuration.get(path + "arg2.description"), equalTo(description.getArguments().get(1).getDescription()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Since CommandInitializer contains all descriptions for commands in English, the help_en.yml file
|
||||
* only contains an entry for one command as to provide an example.
|
||||
*/
|
||||
@Test
|
||||
public void shouldOnlyHaveDescriptionForOneCommand() {
|
||||
// given
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(DEFAULT_MESSAGES_FILE);
|
||||
|
||||
// when
|
||||
Object commands = configuration.get("commands");
|
||||
|
||||
// then
|
||||
assertThat(commands, instanceOf(MemorySection.class));
|
||||
assertThat(((MemorySection) commands).getKeys(false), contains("authme"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveEntryForEachHelpMessageKey() {
|
||||
// given
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(DEFAULT_MESSAGES_FILE);
|
||||
|
||||
// when / then
|
||||
for (HelpMessageKey key : HelpMessageKey.values()) {
|
||||
assertThat("Default configuration has entry for key '" + key + "'",
|
||||
configuration.contains(key.getKey()), equalTo(true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the CommandDescription object for the {@code /authme register} command.
|
||||
*/
|
||||
private static CommandDescription getAuthMeRegisterDescription() {
|
||||
Set<CommandDescription> commands = new CommandInitializer().getCommands();
|
||||
|
||||
List<CommandDescription> children = commands.stream()
|
||||
.filter(command -> command.getLabels().contains("authme"))
|
||||
.map(CommandDescription::getChildren)
|
||||
.findFirst().get();
|
||||
|
||||
return children
|
||||
.stream()
|
||||
.filter(child -> child.getLabels().contains("register"))
|
||||
.findFirst().get();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.FoundResultStatus;
|
||||
import fr.xephi.authme.command.TestCommandsUtil;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
@@ -72,8 +73,7 @@ public class HelpProviderTest {
|
||||
@BeforeInjecting
|
||||
public void setInitialSettings() {
|
||||
given(settings.getProperty(PluginSettings.HELP_HEADER)).willReturn(HELP_HEADER);
|
||||
given(helpMessagesService.buildLocalizedDescription(any(CommandDescription.class)))
|
||||
.willAnswer(new ReturnsArgumentAt(0));
|
||||
setDefaultHelpMessages(helpMessagesService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,9 +160,9 @@ public class HelpProviderTest {
|
||||
assertThat(lines, hasSize(5));
|
||||
assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
|
||||
assertThat(removeColors(lines.get(2)),
|
||||
containsString(AdminPermission.UNREGISTER.getNode() + " (You have permission)"));
|
||||
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (You have permission)"));
|
||||
assertThat(removeColors(lines.get(4)), containsString("Result: You have permission"));
|
||||
containsString(AdminPermission.UNREGISTER.getNode() + " (Has permission)"));
|
||||
assertThat(removeColors(lines.get(3)), containsString("Default: Op only (Has permission)"));
|
||||
assertThat(removeColors(lines.get(4)), containsString("Result: Has permission"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,7 +183,7 @@ public class HelpProviderTest {
|
||||
assertThat(removeColors(lines.get(1)), containsString("Permissions:"));
|
||||
assertThat(removeColors(lines.get(2)),
|
||||
containsString(AdminPermission.UNREGISTER.getNode() + " (No permission)"));
|
||||
assertThat(removeColors(lines.get(3)), containsString("Default: OP's only (No permission)"));
|
||||
assertThat(removeColors(lines.get(3)), containsString("Default: Op only (No permission)"));
|
||||
assertThat(removeColors(lines.get(4)), containsString("Result: No permission"));
|
||||
}
|
||||
|
||||
@@ -365,4 +365,19 @@ public class HelpProviderTest {
|
||||
return captor.getAllValues();
|
||||
}
|
||||
|
||||
private static void setDefaultHelpMessages(HelpMessagesService helpMessagesService) {
|
||||
given(helpMessagesService.buildLocalizedDescription(any(CommandDescription.class)))
|
||||
.willAnswer(new ReturnsArgumentAt(0));
|
||||
for (HelpMessageKey key : HelpMessageKey.values()) {
|
||||
String text = key.name().replace("_", " ").toLowerCase();
|
||||
given(helpMessagesService.getMessage(key))
|
||||
.willReturn(text.substring(0, 1).toUpperCase() + text.substring(1));
|
||||
}
|
||||
for (DefaultPermission permission : DefaultPermission.values()) {
|
||||
String text = permission.name().replace("_", " ").toLowerCase();
|
||||
given(helpMessagesService.getMessage(permission))
|
||||
.willReturn(text.substring(0, 1).toUpperCase() + text.substring(1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user