mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 09:10:01 +01:00
#927 Fix Settings initialization and failing tests
This commit is contained in:
parent
b8153c2578
commit
34a2b46768
@ -41,6 +41,7 @@ public class Settings extends SettingsManager {
|
|||||||
List<PropertyEntry> knownProperties) {
|
List<PropertyEntry> knownProperties) {
|
||||||
super(resource, migrationService, knownProperties);
|
super(resource, migrationService, knownProperties);
|
||||||
this.pluginFolder = pluginFolder;
|
this.pluginFolder = pluginFolder;
|
||||||
|
loadSettingsFromFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,19 +80,18 @@ public class Settings extends SettingsManager {
|
|||||||
return welcomeMessage;
|
return welcomeMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void loadSettingsFromFiles() {
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
messagesFile = buildMessagesFile();
|
messagesFile = buildMessagesFile();
|
||||||
welcomeMessage = readWelcomeMessage();
|
welcomeMessage = readWelcomeMessage();
|
||||||
emailMessage = readEmailMessage();
|
emailMessage = readEmailMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
super.reload();
|
||||||
|
loadSettingsFromFiles();
|
||||||
|
}
|
||||||
|
|
||||||
private File buildMessagesFile() {
|
private File buildMessagesFile() {
|
||||||
String languageCode = getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
String languageCode = getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||||
|
|
||||||
|
@ -24,11 +24,12 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static fr.xephi.authme.TestHelper.getJarFile;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test for {@link Settings}.
|
* Integration test for {@link Settings} (ConfigMe integration).
|
||||||
*/
|
*/
|
||||||
public class SettingsIntegrationTest {
|
public class SettingsIntegrationTest {
|
||||||
|
|
||||||
@ -118,13 +119,14 @@ public class SettingsIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReloadSettings() throws IOException {
|
public void shouldReloadSettings() throws IOException {
|
||||||
// given
|
// given
|
||||||
PropertyResource resource = new YamlFileResource(temporaryFolder.newFile());
|
File configFile = temporaryFolder.newFile();
|
||||||
|
PropertyResource resource = new YamlFileResource(configFile);
|
||||||
Settings settings = new Settings(testPluginFolder, resource,
|
Settings settings = new Settings(testPluginFolder, resource,
|
||||||
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
TestSettingsMigrationServices.alwaysFulfilled(), knownProperties);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER),
|
assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), equalTo(TestEnum.SECOND)); // default value
|
||||||
equalTo(TestConfiguration.RATIO_ORDER.getDefaultValue()));
|
Files.copy(getJarFile(COMPLETE_FILE), configFile);
|
||||||
settings.reload();
|
settings.reload();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -133,7 +135,7 @@ public class SettingsIntegrationTest {
|
|||||||
|
|
||||||
private File copyFileFromResources(String path) {
|
private File copyFileFromResources(String path) {
|
||||||
try {
|
try {
|
||||||
File source = TestHelper.getJarFile(path);
|
File source = getJarFile(path);
|
||||||
File destination = temporaryFolder.newFile();
|
File destination = temporaryFolder.newFile();
|
||||||
Files.copy(source, destination);
|
Files.copy(source, destination);
|
||||||
return destination;
|
return destination;
|
||||||
|
@ -40,7 +40,7 @@ import static org.mockito.Mockito.when;
|
|||||||
*/
|
*/
|
||||||
public class SettingsTest {
|
public class SettingsTest {
|
||||||
|
|
||||||
private final List<PropertyEntry> knownProperties =
|
private static final List<PropertyEntry> knownProperties =
|
||||||
SettingsFieldRetriever.getAllProperties(TestConfiguration.class);
|
SettingsFieldRetriever.getAllProperties(TestConfiguration.class);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
|
Loading…
Reference in New Issue
Block a user