Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 761-permission-groups
This commit is contained in:
@@ -39,10 +39,10 @@ public class HelpMessagesServiceTest {
|
||||
@Mock
|
||||
private MessageFileHandlerProvider messageFileHandlerProvider;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeInjecting
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializeHandler() {
|
||||
MessageFileHandler handler = new MessageFileHandler(getJarFile(TEST_FILE), "messages/messages_en.yml");
|
||||
MessageFileHandler handler = new MessageFileHandler(getJarFile(TEST_FILE), "messages/messages_en.yml", null);
|
||||
given(messageFileHandlerProvider.initializeHandler(any(Function.class))).willReturn(handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.data.limbo;
|
||||
|
||||
import fr.xephi.authme.ReflectionTestUtils;
|
||||
import fr.xephi.authme.data.backup.LimboPlayerStorage;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
|
||||
+2
-3
@@ -1,14 +1,13 @@
|
||||
package fr.xephi.authme.data.backup;
|
||||
package fr.xephi.authme.data.limbo;
|
||||
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -0,0 +1,93 @@
|
||||
package fr.xephi.authme.message;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.help.HelpMessage;
|
||||
import fr.xephi.authme.command.help.HelpSection;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.Matchers.both;
|
||||
import static org.hamcrest.Matchers.emptyString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests that all help_xx.yml files contain all entries for
|
||||
* {@link HelpSection}, {@link HelpMessage} and {@link DefaultPermission}.
|
||||
*/
|
||||
public class HelpMessageConsistencyTest {
|
||||
|
||||
private static final String MESSAGES_FOLDER = "/messages";
|
||||
private static final Pattern HELP_MESSAGES_FILE = Pattern.compile("help_[a-z]+\\.yml");
|
||||
|
||||
private List<File> helpFiles;
|
||||
|
||||
@Before
|
||||
public void findHelpMessagesFiles() {
|
||||
File folder = TestHelper.getJarFile(MESSAGES_FOLDER);
|
||||
File[] files = folder.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
throw new IllegalStateException("Could not get files from '" + MESSAGES_FOLDER + "'");
|
||||
}
|
||||
helpFiles = Arrays.stream(files)
|
||||
.filter(file -> HELP_MESSAGES_FILE.matcher(file.getName()).matches())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveRequiredEntries() {
|
||||
for (File file : helpFiles) {
|
||||
// given
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// when / then
|
||||
assertHasAllHelpSectionEntries(file.getName(), configuration);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertHasAllHelpSectionEntries(String filename, FileConfiguration configuration) {
|
||||
for (HelpSection section : HelpSection.values()) {
|
||||
assertThat(filename + " should have entry for HelpSection '" + section + "'",
|
||||
configuration.getString(section.getKey()), notEmptyString());
|
||||
}
|
||||
|
||||
for (HelpMessage message : HelpMessage.values()) {
|
||||
assertThat(filename + " should have entry for HelpMessage '" + message + "'",
|
||||
configuration.getString(message.getKey()), notEmptyString());
|
||||
}
|
||||
|
||||
for (DefaultPermission defaultPermission : DefaultPermission.values()) {
|
||||
assertThat(filename + " should have entry for DefaultPermission '" + defaultPermission + "'",
|
||||
configuration.getString(getPathForDefaultPermission(defaultPermission)), notEmptyString());
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPathForDefaultPermission(DefaultPermission defaultPermission) {
|
||||
String path = "common.defaultPermissions.";
|
||||
switch (defaultPermission) {
|
||||
case ALLOWED:
|
||||
return path + "allowed";
|
||||
case NOT_ALLOWED:
|
||||
return path + "notAllowed";
|
||||
case OP_ONLY:
|
||||
return path + "opOnly";
|
||||
default:
|
||||
throw new IllegalStateException("Unknown default permission '" + defaultPermission + "'");
|
||||
}
|
||||
}
|
||||
|
||||
private static Matcher<String> notEmptyString() {
|
||||
return both(not(emptyString())).and(not(nullValue()));
|
||||
}
|
||||
}
|
||||
@@ -233,8 +233,8 @@ public class MessagesIntegrationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static MessageFileHandlerProvider providerReturning(File file, String defaultFile) {
|
||||
MessageFileHandlerProvider handler = mock(MessageFileHandlerProvider.class);
|
||||
given(handler.initializeHandler(any(Function.class)))
|
||||
.willReturn(new MessageFileHandler(file, defaultFile));
|
||||
given(handler.initializeHandler(any(Function.class), anyString()))
|
||||
.willReturn(new MessageFileHandler(file, defaultFile, "/authme messages"));
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@ import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.service.PluginHookService;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -38,9 +37,6 @@ public class SpawnLoaderTest {
|
||||
@Mock
|
||||
private Settings settings;
|
||||
|
||||
@Mock
|
||||
private DataSource dataSource;
|
||||
|
||||
@Mock
|
||||
private PluginHookService pluginHookService;
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ public class AddJavaDocToMessageEnumTask implements AutoToolTask {
|
||||
return configuration.getString(key.getKey())
|
||||
.replaceAll("&[0-9a-f]", "")
|
||||
.replace("&", "&")
|
||||
.replace("<", "<");
|
||||
.replace("<", "<")
|
||||
.replace(">", ">");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user