- Create Property class for defining config properties - Create logic for typed retrival of properties from YAML file - Add custom save method - Retain comments from Comment annotations in the classes - Write in a sorted order: first discovered properties are first written to config.yml - Adjust properties to reflect the current config.yml - Add sample tests for the retrieval and writing of properties with the new setup
43 lines
1.2 KiB
Java
43 lines
1.2 KiB
Java
package fr.xephi.authme.settings.custom;
|
|
|
|
import org.junit.Test;
|
|
|
|
import java.io.File;
|
|
import java.net.URL;
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
/**
|
|
* Test for the save() function of new settings
|
|
*/
|
|
public class NewSettingsWriteTest {
|
|
|
|
private static final String CONFIG_FILE = "437-write-test.yml";
|
|
|
|
@Test
|
|
public void shouldWriteProperties() {
|
|
File file = getConfigFile();
|
|
NewSetting setting = new NewSetting(file);
|
|
setting.save();
|
|
|
|
// assert that we can load the file again -- i.e. that it's valid YAML!
|
|
NewSetting newSetting = new NewSetting(file);
|
|
assertThat(newSetting.getOption(SecuritySettings.CAPTCHA_LENGTH),
|
|
equalTo(SecuritySettings.CAPTCHA_LENGTH.getDefaultValue()));
|
|
assertThat(newSetting.getOption(ProtectionSettings.COUNTRIES_BLACKLIST),
|
|
equalTo(ProtectionSettings.COUNTRIES_BLACKLIST.getDefaultValue()));
|
|
}
|
|
|
|
|
|
|
|
private File getConfigFile() {
|
|
URL url = getClass().getClassLoader().getResource(CONFIG_FILE);
|
|
if (url == null) {
|
|
throw new RuntimeException("File '" + CONFIG_FILE + "' could not be loaded");
|
|
}
|
|
return new File(url.getFile());
|
|
}
|
|
|
|
}
|