From 34a2b4676881e2a6703cb231e19f3cab50dc095e Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 3 Sep 2016 11:30:03 +0200 Subject: [PATCH] #927 Fix Settings initialization and failing tests --- .../java/fr/xephi/authme/settings/Settings.java | 16 ++++++++-------- .../authme/settings/SettingsIntegrationTest.java | 12 +++++++----- .../fr/xephi/authme/settings/SettingsTest.java | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 46f47052b..a3b4cf579 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -41,6 +41,7 @@ public class Settings extends SettingsManager { List knownProperties) { super(resource, migrationService, knownProperties); this.pluginFolder = pluginFolder; + loadSettingsFromFiles(); } /** @@ -79,19 +80,18 @@ public class Settings extends SettingsManager { return welcomeMessage; } - @Override - protected void validateAndLoadOptions() { - if (migrationService.checkAndMigrate(resource, knownProperties)) { - ConsoleLogger.info("Merged new config options"); - ConsoleLogger.info("Please check your config.yml file for new settings!"); - save(); - } - + private void loadSettingsFromFiles() { messagesFile = buildMessagesFile(); welcomeMessage = readWelcomeMessage(); emailMessage = readEmailMessage(); } + @Override + public void reload() { + super.reload(); + loadSettingsFromFiles(); + } + private File buildMessagesFile() { String languageCode = getProperty(PluginSettings.MESSAGES_LANGUAGE); diff --git a/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java b/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java index 4e95b37ef..05ac665ab 100644 --- a/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java @@ -24,11 +24,12 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import static fr.xephi.authme.TestHelper.getJarFile; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; /** - * Integration test for {@link Settings}. + * Integration test for {@link Settings} (ConfigMe integration). */ public class SettingsIntegrationTest { @@ -118,13 +119,14 @@ public class SettingsIntegrationTest { @Test public void shouldReloadSettings() throws IOException { // given - PropertyResource resource = new YamlFileResource(temporaryFolder.newFile()); + File configFile = temporaryFolder.newFile(); + PropertyResource resource = new YamlFileResource(configFile); Settings settings = new Settings(testPluginFolder, resource, TestSettingsMigrationServices.alwaysFulfilled(), knownProperties); // when - assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), - equalTo(TestConfiguration.RATIO_ORDER.getDefaultValue())); + assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), equalTo(TestEnum.SECOND)); // default value + Files.copy(getJarFile(COMPLETE_FILE), configFile); settings.reload(); // then @@ -133,7 +135,7 @@ public class SettingsIntegrationTest { private File copyFileFromResources(String path) { try { - File source = TestHelper.getJarFile(path); + File source = getJarFile(path); File destination = temporaryFolder.newFile(); Files.copy(source, destination); return destination; diff --git a/src/test/java/fr/xephi/authme/settings/SettingsTest.java b/src/test/java/fr/xephi/authme/settings/SettingsTest.java index 7c9acf70e..963395faa 100644 --- a/src/test/java/fr/xephi/authme/settings/SettingsTest.java +++ b/src/test/java/fr/xephi/authme/settings/SettingsTest.java @@ -40,7 +40,7 @@ import static org.mockito.Mockito.when; */ public class SettingsTest { - private final List knownProperties = + private static final List knownProperties = SettingsFieldRetriever.getAllProperties(TestConfiguration.class); @Rule