#347 Create consistency and integration tests for NewSetting
- Ensure that the project's config.yml contains all settings that NewSetting is aware of - Add extensive, more generic integration tests
This commit is contained in:
@@ -19,7 +19,7 @@ public class HooksSettings implements SettingsClass {
|
||||
|
||||
@Comment("Send player to this BungeeCord server after register/login")
|
||||
public static final Property<String> BUNGEECORD_SERVER =
|
||||
newProperty(PropertyType.STRING, "bungeecord.server", "");
|
||||
newProperty(PropertyType.STRING, "Hooks.sendPlayerTo", "");
|
||||
|
||||
@Comment("Do we need to disable Essentials SocialSpy on join?")
|
||||
public static final Property<Boolean> DISABLE_SOCIAL_SPY =
|
||||
|
||||
@@ -24,6 +24,12 @@ public class NewSetting {
|
||||
private File file;
|
||||
private YamlConfiguration configuration;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Loads the file as YAML and checks its integrity.
|
||||
*
|
||||
* @param file The configuration file
|
||||
*/
|
||||
public NewSetting(File file) {
|
||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.file = file;
|
||||
@@ -34,12 +40,33 @@ public class NewSetting {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple constructor for testing purposes. Does not check for all properties and
|
||||
* never saves to the file.
|
||||
*
|
||||
* @param yamlConfiguration The YamlConfiguration object to use
|
||||
* @param file The file to write to
|
||||
* @param propertyMap The property map whose properties should be verified for presence, or null to skip this
|
||||
*/
|
||||
@VisibleForTesting
|
||||
NewSetting(YamlConfiguration yamlConfiguration, String file) {
|
||||
NewSetting(YamlConfiguration yamlConfiguration, File file, PropertyMap propertyMap) {
|
||||
this.configuration = yamlConfiguration;
|
||||
this.file = new File(file);
|
||||
this.file = file;
|
||||
|
||||
if (propertyMap != null) {
|
||||
if (!containsAllSettings(propertyMap)) {
|
||||
save(propertyMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given property from the configuration.
|
||||
*
|
||||
* @param property The property to retrieve
|
||||
* @param <T> The property's type
|
||||
* @return The property's value
|
||||
*/
|
||||
public <T> T getOption(Property<T> property) {
|
||||
return property.getFromFile(configuration);
|
||||
}
|
||||
@@ -105,7 +132,8 @@ public class NewSetting {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean containsAllSettings(PropertyMap propertyMap) {
|
||||
@VisibleForTesting
|
||||
boolean containsAllSettings(PropertyMap propertyMap) {
|
||||
for (Property<?> property : propertyMap.keySet()) {
|
||||
if (!property.isPresent(configuration)) {
|
||||
return false;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class PurgeSettings implements SettingsClass {
|
||||
|
||||
@Comment("Do we need to remove the Essentials/users/player.yml file during purge process?")
|
||||
public static final Property<Boolean> REMOVE_ESSENTIALS_FILES =
|
||||
newProperty(BOOLEAN, "Purge.removeEssentialsFiles", false);
|
||||
newProperty(BOOLEAN, "Purge.removeEssentialsFile", false);
|
||||
|
||||
@Comment("World where are players.dat stores")
|
||||
public static final Property<String> DEFAULT_WORLD =
|
||||
|
||||
@@ -355,6 +355,8 @@ Email:
|
||||
emailWhitelisted: []
|
||||
# Do we need to send new password draw in an image?
|
||||
generateImage: false
|
||||
# The email OAuth 2 token (leave empty if not used)
|
||||
emailOauth2Token: ''
|
||||
Hooks:
|
||||
# Do we need to hook with multiverse for spawn checking?
|
||||
multiverse: true
|
||||
|
||||
Reference in New Issue
Block a user