#347 Create tests and add check for missing settings in NewSetting

This commit is contained in:
ljacqu
2016-01-08 21:22:26 +01:00
parent 30db03837a
commit 69c225c850
8 changed files with 309 additions and 59 deletions
@@ -74,6 +74,16 @@ public class Property<T> {
return type.asYaml(this, configuration);
}
/**
* Return whether or not the given configuration file contains the property.
*
* @param configuration The configuration file to verify
* @return True if the property is present, false otherwise
*/
public boolean isPresent(YamlConfiguration configuration) {
return type.contains(this, configuration);
}
// -----
// Trivial getters
// -----
@@ -41,6 +41,17 @@ public abstract class PropertyType<T> {
return asYaml(getFromFile(property, configuration));
}
/**
* Return whether the property is present in the given configuration.
*
* @param property The property to search for
* @param configuration The configuration to verify
* @return True if the property is present, false otherwise
*/
public boolean contains(Property<T> property, YamlConfiguration configuration) {
return configuration.contains(property.getPath());
}
/**
* Transform the given value to YAML.
*
@@ -49,10 +60,6 @@ public abstract class PropertyType<T> {
*/
protected abstract List<String> asYaml(T value);
protected boolean contains(Property<T> property, YamlConfiguration configuration) {
return configuration.contains(property.getPath());
}
/**
* Boolean property.
@@ -145,6 +152,11 @@ public abstract class PropertyType<T> {
}
return resultLines;
}
@Override
public boolean contains(Property<List<String>> property, YamlConfiguration configuration) {
return configuration.contains(property.getPath()) && configuration.isList(property.getPath());
}
}
}