From f6ed39b118f875715e549d1dc029aa7e1fcdd698 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Thu, 24 Nov 2016 17:39:57 +0100 Subject: [PATCH] #411 Improve command migration handling, write tests --- .../commandconfig/CommandManager.java | 24 +---- .../commandconfig/CommandSettingsHolder.java | 10 +- .../commandconfig/CommandsMigrater.java | 22 ++++- .../properties/AuthMeSettingsRetriever.java | 3 +- src/main/resources/commands.yml | 12 ++- .../authme/ForceLoginCommandTest.java | 5 +- .../message/MessagesIntegrationTest.java | 2 +- .../xephi/authme/settings/SettingsTest.java | 18 ++++ .../CommandConfigTestHelper.java | 2 +- .../commandconfig/CommandManagerTest.java | 95 +++++++++++++++---- .../CommandYmlConsistencyTest.java | 60 ++++++++++++ .../commandconfig/CommandsMigraterTest.java | 20 ++++ .../AuthMeSettingsRetrieverTest.java | 32 +++++++ .../settings/commandconfig/commands.empty.yml | 0 14 files changed, 248 insertions(+), 57 deletions(-) create mode 100644 src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java create mode 100644 src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java create mode 100644 src/test/resources/fr/xephi/authme/settings/commandconfig/commands.empty.yml diff --git a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java index 015df7f6..2b476c4a 100644 --- a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java +++ b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java @@ -2,11 +2,9 @@ package fr.xephi.authme.settings.commandconfig; import com.github.authme.configme.SettingsManager; import com.github.authme.configme.resource.YamlFileResource; -import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.DataFolder; import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.FileUtils; import org.bukkit.entity.Player; @@ -22,17 +20,14 @@ public class CommandManager implements Reloadable { private final File dataFolder; private final BukkitService bukkitService; private final CommandsMigrater commandsMigrater; - private final Settings settings; private CommandConfig commandConfig; @Inject - CommandManager(@DataFolder File dataFolder, BukkitService bukkitService, - CommandsMigrater commandsMigrater, Settings settings) { + CommandManager(@DataFolder File dataFolder, BukkitService bukkitService, CommandsMigrater commandsMigrater) { this.dataFolder = dataFolder; this.bukkitService = bukkitService; this.commandsMigrater = commandsMigrater; - this.settings = settings; reload(); } @@ -65,21 +60,8 @@ public class CommandManager implements Reloadable { FileUtils.copyFileFromResource(file, "commands.yml"); SettingsManager settingsManager = new SettingsManager( - new YamlFileResource(file), null, CommandSettingsHolder.class); - CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS); - - if (commandsMigrater.transformOldCommands(commandConfig)) { - ConsoleLogger.warning("Old setting properties (such as settings.forceCommands) were found. " - + "They have been moved to commands.yml"); - settingsManager.setProperty(CommandSettingsHolder.COMMANDS, commandConfig); - settingsManager.save(); - settingsManager.reload(); - settings.save(); - settings.reload(); - - commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS); - } - this.commandConfig = commandConfig; + new YamlFileResource(file), commandsMigrater, CommandSettingsHolder.class); + commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS); } diff --git a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java index 4de2de5e..75906a32 100644 --- a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java +++ b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java @@ -25,7 +25,7 @@ public final class CommandSettingsHolder implements SettingsHolder { String[] comments = { "This configuration file allows you to execute commands on various events.", "%p in commands will be replaced with the player name.", - "For example, if you want to message a welcome message to a player who just registered:", + "For example, if you want to send a welcome message to a player who just registered:", "onRegister:", " welcome:", " command: 'msg %p Welcome to the server!'", @@ -33,15 +33,17 @@ public final class CommandSettingsHolder implements SettingsHolder { "", "This will make the console execute the msg command to the player.", "Each command under an event has a name you can choose freely (e.g. 'welcome' as above),", - "after which a mandatory 'command' field defines the command to run, ", + "after which a mandatory 'command' field defines the command to run,", "and 'as' defines who will run the command (either PLAYER or CONSOLE). Longer example:", "onLogin:", " welcome:", " command: 'msg %p Welcome back!'", - " # as: PLAYER # player is the default, you can leave this out if you want", + " as: PLAYER", " broadcast:", " command: 'broadcast %p has joined, welcome back!'", - " as: CONSOLE" + " as: CONSOLE", + "", + "Supported command events: onLogin, onJoin, onRegister" }; Map commentMap = new HashMap<>(); commentMap.put("onLogin", comments); diff --git a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandsMigrater.java b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandsMigrater.java index 8a2df167..a64260e0 100644 --- a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandsMigrater.java +++ b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandsMigrater.java @@ -1,5 +1,9 @@ package fr.xephi.authme.settings.commandconfig; +import com.github.authme.configme.migration.MigrationService; +import com.github.authme.configme.properties.Property; +import com.github.authme.configme.resource.PropertyResource; +import com.google.common.annotations.VisibleForTesting; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.settings.SettingsMigrationService; import fr.xephi.authme.util.RandomStringUtils; @@ -13,7 +17,7 @@ import java.util.stream.Collectors; /** * Migrates the commands from their old location, in config.yml, to the dedicated commands configuration file. */ -class CommandsMigrater { +class CommandsMigrater implements MigrationService { @Inject private SettingsMigrationService settingsMigrationService; @@ -21,12 +25,25 @@ class CommandsMigrater { CommandsMigrater() { } + @Override + public boolean checkAndMigrate(PropertyResource resource, List> properties) { + final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.getValue(resource); + final boolean didMoveCommands = transformOldCommands(commandConfig); + + if (didMoveCommands) { // TODO ConfigMe/#29: Check that loaded file isn't completely empty + resource.setValue("", commandConfig); + return true; + } + return false; + } + /** * Adds command settings from their old location (in config.yml) to the given command configuration object. * * @param commandConfig the command config object to move old commands to * @return true if commands have been moved, false if no migration was necessary */ + @VisibleForTesting boolean transformOldCommands(CommandConfig commandConfig) { boolean didMoveCommands = false; for (MigratableCommandSection section : MigratableCommandSection.values()) { @@ -97,7 +114,8 @@ class CommandsMigrater { } Map commandMap = commandMapGetter.apply(commandConfig); commands.forEach(cmd -> commandMap.put(RandomStringUtils.generate(10), cmd)); - ConsoleLogger.info("Migrated " + commands.size() + " commands of type " + this); + ConsoleLogger.info("Moving " + commands.size() + " commands of type " + this + + " from config.yml to commands.yml"); return true; } } diff --git a/src/main/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetriever.java b/src/main/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetriever.java index 80bd02cf..88b896f6 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetriever.java +++ b/src/main/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetriever.java @@ -6,8 +6,7 @@ import com.github.authme.configme.knownproperties.ConfigurationDataBuilder; import com.github.authme.configme.properties.Property; /** - * Utility class responsible for retrieving all {@link Property} fields - * from {@link SettingsHolder} implementations via reflection. + * Utility class responsible for retrieving all {@link Property} fields from {@link SettingsHolder} classes. */ public final class AuthMeSettingsRetriever { diff --git a/src/main/resources/commands.yml b/src/main/resources/commands.yml index a7c70359..c3741a29 100644 --- a/src/main/resources/commands.yml +++ b/src/main/resources/commands.yml @@ -1,24 +1,26 @@ # This configuration file allows you to execute commands on various events. # %p in commands will be replaced with the player name. -# For example, if you want to message a welcome message to a player who just registered: +# For example, if you want to send a welcome message to a player who just registered: # onRegister: # welcome: # command: 'msg %p Welcome to the server!' # as: CONSOLE -# +# # This will make the console execute the msg command to the player. # Each command under an event has a name you can choose freely (e.g. 'welcome' as above), -# after which a mandatory 'command' field defines the command to run, +# after which a mandatory 'command' field defines the command to run, # and 'as' defines who will run the command (either PLAYER or CONSOLE). Longer example: # onLogin: # welcome: # command: 'msg %p Welcome back!' -# # as: PLAYER # player is the default, you can leave this out if you want +# as: PLAYER # broadcast: # command: 'broadcast %p has joined, welcome back!' # as: CONSOLE +# +# Supported command events: onLogin, onJoin, onRegister onLogin: welcome: command: 'msg %p Welcome back!' - executor: 'PLAYER' \ No newline at end of file + executor: 'PLAYER' diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java index 8746f01b..76a73033 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ForceLoginCommandTest.java @@ -15,7 +15,6 @@ import org.mockito.runners.MockitoJUnitRunner; import java.util.Collections; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -53,7 +52,7 @@ public class ForceLoginCommandTest { // then verify(bukkitService).getPlayerExact(playerName); - verify(sender).sendMessage(argThat(equalTo("Player needs to be online!"))); + verify(sender).sendMessage("Player needs to be online!"); verifyZeroInteractions(management); } @@ -69,7 +68,7 @@ public class ForceLoginCommandTest { // then verify(bukkitService).getPlayerExact(playerName); - verify(sender).sendMessage(argThat(equalTo("Player needs to be online!"))); + verify(sender).sendMessage("Player needs to be online!"); verifyZeroInteractions(management); } diff --git a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java index 04004634..12949c5a 100644 --- a/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesIntegrationTest.java @@ -160,7 +160,7 @@ public class MessagesIntegrationTest { messages.send(sender, key); // then - verify(sender).sendMessage(argThat(equalTo("Use /captcha THE_CAPTCHA to solve the captcha"))); + verify(sender).sendMessage("Use /captcha THE_CAPTCHA to solve the captcha"); } @Test diff --git a/src/test/java/fr/xephi/authme/settings/SettingsTest.java b/src/test/java/fr/xephi/authme/settings/SettingsTest.java index 137d5a56..3480bd0c 100644 --- a/src/test/java/fr/xephi/authme/settings/SettingsTest.java +++ b/src/test/java/fr/xephi/authme/settings/SettingsTest.java @@ -83,6 +83,24 @@ public class SettingsTest { assertThat(result, equalTo(emailMessage)); } + @Test + public void shouldLoadRecoveryCodeMessage() throws IOException { + // given + String emailMessage = "Your recovery code is %code."; + File emailFile = new File(testPluginFolder, "recovery_code_email.html"); + createFile(emailFile); + Files.write(emailFile.toPath(), emailMessage.getBytes()); + + PropertyResource resource = mock(PropertyResource.class); + Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA); + + // when + String result = settings.getRecoveryCodeEmailMessage(); + + // then + assertThat(result, equalTo(emailMessage)); + } + private static void createFile(File file) { try { file.getParentFile().mkdirs(); diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandConfigTestHelper.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandConfigTestHelper.java index f9fb4e5f..88ee90f3 100644 --- a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandConfigTestHelper.java +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandConfigTestHelper.java @@ -19,7 +19,7 @@ final class CommandConfigTestHelper { * @param executor the expected executor * @return the matcher */ - public static Matcher isCommand(String cmd, Executor executor) { + static Matcher isCommand(String cmd, Executor executor) { return new TypeSafeMatcher() { @Override protected boolean matchesSafely(Command item) { diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java index eea0f569..ec03cb19 100644 --- a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java @@ -4,26 +4,33 @@ import com.google.common.io.Files; import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.TestHelper; import fr.xephi.authme.service.BukkitService; -import fr.xephi.authme.settings.Settings; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; +import fr.xephi.authme.settings.SettingsMigrationService; +import org.bukkit.entity.Player; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import java.io.File; import java.io.IOException; +import java.util.function.BiConsumer; import static fr.xephi.authme.settings.commandconfig.CommandConfigTestHelper.isCommand; +import static java.lang.String.format; import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.only; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Test for {@link CommandManager}. @@ -33,16 +40,18 @@ public class CommandManagerTest { private static final String TEST_FILES_FOLDER = "/fr/xephi/authme/settings/commandconfig/"; + private CommandManager manager; + @InjectMocks + private CommandsMigrater commandsMigrater; + @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); - private CommandManager manager; @Mock private BukkitService bukkitService; @Mock - private Settings settings; - @Mock - private CommandsMigrater commandsMigrater; + private SettingsMigrationService settingsMigrationService; + private File testFolder; @Before @@ -75,10 +84,9 @@ public class CommandManagerTest { } @Test - @Ignore // TODO #411: Implement tested behavior public void shouldLoadIncompleteFile() { // given - File configFile = copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.incomplete.yml"); + copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.incomplete.yml"); // when initManager(); @@ -90,23 +98,74 @@ public class CommandManagerTest { isCommand("msg %p Welcome back", Executor.CONSOLE), isCommand("list", Executor.PLAYER))); assertThat(commandConfig.getOnRegister(), anEmptyMap()); + } - // verify that we have rewritten the file with the proper sections - FileConfiguration configuration = YamlConfiguration.loadConfiguration(configFile); - assertThat(configuration.contains("onRegister"), equalTo(true)); - assertThat(configuration.contains("doesNotExist"), equalTo(false)); + @Test + public void shouldExecuteCommandsOnJoin() { + // given + String name = "Bobby1"; + + // when + testCommandExecution(name, CommandManager::runCommandsOnJoin); + + // then + verify(bukkitService, only()).dispatchConsoleCommand(format("broadcast %s has joined", name)); + } + + @Test + public void shouldExecuteCommandsOnRegister() { + // given + String name = "luis"; + + // when + testCommandExecution(name, CommandManager::runCommandsOnRegister); + + // then + verify(bukkitService).dispatchCommand(any(Player.class), eq("me I just registered")); + verify(bukkitService).dispatchConsoleCommand(format("log %s registered", name)); + verifyNoMoreInteractions(bukkitService); + } + + @Test + public void shouldExecuteCommandsOnLogin() { + // given + String name = "plaYer01"; + + // when + testCommandExecution(name, CommandManager::runCommandsOnLogin); + + // then + verify(bukkitService).dispatchConsoleCommand(format("msg %s Welcome back", name)); + verify(bukkitService).dispatchCommand(any(Player.class), eq("motd")); + verify(bukkitService).dispatchCommand(any(Player.class), eq("list")); + verifyNoMoreInteractions(bukkitService); + } + + @Test + public void shouldHaveHiddenConstructorInSettingsHolderClass() { + // given / when / then + TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandSettingsHolder.class); + } + + + private void testCommandExecution(String playerName, BiConsumer testMethod) { + copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml"); + initManager(); + Player player = mock(Player.class); + given(player.getName()).willReturn(playerName); + + testMethod.accept(manager, player); } private void initManager() { - manager = new CommandManager(testFolder, bukkitService, commandsMigrater, settings); + manager = new CommandManager(testFolder, bukkitService, commandsMigrater); } - private File copyJarFileAsCommandsYml(String path) { + private void copyJarFileAsCommandsYml(String path) { File source = TestHelper.getJarFile(path); File destination = new File(testFolder, "commands.yml"); try { Files.copy(source, destination); - return destination; } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java new file mode 100644 index 00000000..ff9e51da --- /dev/null +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java @@ -0,0 +1,60 @@ +package fr.xephi.authme.settings.commandconfig; + +import com.github.authme.configme.knownproperties.ConfigurationDataBuilder; +import com.github.authme.configme.resource.PropertyResource; +import com.github.authme.configme.resource.YamlFileResource; +import fr.xephi.authme.TestHelper; +import fr.xephi.authme.settings.SettingsMigrationService; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.io.File; +import java.util.Collections; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; + +/** + * Tests that commands.yml is well-formed. + */ +@RunWith(MockitoJUnitRunner.class) +public class CommandYmlConsistencyTest { + + @InjectMocks + private CommandsMigrater commandsMigrater; + + @Mock + private SettingsMigrationService settingsMigrationService; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Before + public void setUpSettingsMigrationService() { + given(settingsMigrationService.getOnLoginCommands()).willReturn(Collections.emptyList()); + given(settingsMigrationService.getOnLoginConsoleCommands()).willReturn(Collections.emptyList()); + given(settingsMigrationService.getOnRegisterCommands()).willReturn(Collections.emptyList()); + given(settingsMigrationService.getOnRegisterConsoleCommands()).willReturn(Collections.emptyList()); + } + + @Test + public void shouldLoadWithNoMigrations() { + // given + File commandFile = TestHelper.getJarFile("/commands.yml"); + PropertyResource resource = new YamlFileResource(commandFile); + + // when + boolean result = commandsMigrater.checkAndMigrate( + resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); + + // then + assertThat(result, equalTo(false)); + } +} diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandsMigraterTest.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandsMigraterTest.java index ee146884..0dae65fe 100644 --- a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandsMigraterTest.java +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandsMigraterTest.java @@ -1,14 +1,19 @@ package fr.xephi.authme.settings.commandconfig; +import com.github.authme.configme.knownproperties.ConfigurationDataBuilder; +import com.github.authme.configme.resource.PropertyResource; +import com.github.authme.configme.resource.YamlFileResource; import fr.xephi.authme.TestHelper; import fr.xephi.authme.settings.SettingsMigrationService; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.io.File; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -108,4 +113,19 @@ public class CommandsMigraterTest { isCommand("log %p registered", Executor.CONSOLE), isCommand("whois %p", Executor.CONSOLE))); } + + @Test + @Ignore // TODO ConfigMe/#29: Create PropertyResource#getKeys + public void shouldRewriteForEmptyFile() { + // given + File commandFile = TestHelper.getJarFile("/fr/xephi/authme/settings/commandconfig/commands.empty.yml"); + PropertyResource resource = new YamlFileResource(commandFile); + + // when + boolean result = commandsMigrater.checkAndMigrate( + resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); + + // then + assertThat(result, equalTo(true)); + } } diff --git a/src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java b/src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java new file mode 100644 index 00000000..a5bd8c90 --- /dev/null +++ b/src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java @@ -0,0 +1,32 @@ +package fr.xephi.authme.settings.properties; + +import com.github.authme.configme.knownproperties.ConfigurationData; +import fr.xephi.authme.TestHelper; +import org.junit.Test; + +import static org.hamcrest.Matchers.closeTo; +import static org.junit.Assert.assertThat; + +/** + * Test for {@link AuthMeSettingsRetriever}. + */ +public class AuthMeSettingsRetrieverTest { + + @Test + public void shouldReturnAllProperties() { + // given / when + ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData(); + + // then + // Note ljacqu 20161123: Check that the number of properties returned corresponds to what we expect with + // an error margin of 10: this prevents us from having to adjust the test every time the config is changed. + // If this test fails, replace the first argument in closeTo() with the new number of properties + assertThat((double) configurationData.getProperties().size(), + closeTo(150, 10)); + } + + @Test + public void shouldHaveHiddenConstructor() { + TestHelper.validateHasOnlyPrivateEmptyConstructor(AuthMeSettingsRetriever.class); + } +} diff --git a/src/test/resources/fr/xephi/authme/settings/commandconfig/commands.empty.yml b/src/test/resources/fr/xephi/authme/settings/commandconfig/commands.empty.yml new file mode 100644 index 00000000..e69de29b