#927 Fix Settings initialization and failing tests

This commit is contained in:
ljacqu 2016-09-03 11:30:03 +02:00
parent b8153c2578
commit 34a2b46768
3 changed files with 16 additions and 14 deletions

View File

@ -41,6 +41,7 @@ public class Settings extends SettingsManager {
List<PropertyEntry> 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);

View File

@ -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;

View File

@ -40,7 +40,7 @@ import static org.mockito.Mockito.when;
*/
public class SettingsTest {
private final List<PropertyEntry> knownProperties =
private static final List<PropertyEntry> knownProperties =
SettingsFieldRetriever.getAllProperties(TestConfiguration.class);
@Rule