> CONFIGURATION_CLASSES = Arrays.asList(
- DatabaseSettings.class, ConverterSettings.class, PluginSettings.class,
- RestrictionSettings.class, EmailSettings.class, HooksSettings.class,
- ProtectionSettings.class, PurgeSettings.class, SecuritySettings.class,
- RegistrationSettings.class, BackupSettings.class);
-
- private SettingsFieldRetriever() {
- }
-
- /**
- * Scan all given classes for their properties and return the generated {@link PropertyMap}.
- *
- * @return PropertyMap containing all found properties and their associated comments
- * @see #CONFIGURATION_CLASSES
- */
- public static PropertyMap getAllPropertyFields() {
- PropertyMap properties = new PropertyMap();
- for (Class> clazz : CONFIGURATION_CLASSES) {
- Field[] declaredFields = clazz.getDeclaredFields();
- for (Field field : declaredFields) {
- Property> property = getPropertyField(field);
- if (property != null) {
- properties.put(property, getCommentsForField(field));
- }
- }
- }
- return properties;
- }
-
- private static String[] getCommentsForField(Field field) {
- if (field.isAnnotationPresent(Comment.class)) {
- return field.getAnnotation(Comment.class).value();
- }
- return new String[0];
- }
-
- /**
- * Return the given field's value if it is a static {@link Property}.
- *
- * @param field The field's value to return
- * @return The property the field defines, or null if not applicable
- */
- private static Property> getPropertyField(Field field) {
- field.setAccessible(true);
- if (field.isAccessible() && Property.class.equals(field.getType()) && Modifier.isStatic(field.getModifiers())) {
- try {
- return (Property>) field.get(null);
- } catch (IllegalAccessException e) {
- throw new IllegalStateException("Could not fetch field '" + field.getName() + "' from class '"
- + field.getDeclaringClass().getSimpleName() + "'", e);
- }
- }
- return null;
- }
-
-}
diff --git a/src/main/java/fr/xephi/authme/settings/propertymap/Node.java b/src/main/java/fr/xephi/authme/settings/propertymap/Node.java
deleted file mode 100644
index 7d281989..00000000
--- a/src/main/java/fr/xephi/authme/settings/propertymap/Node.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package fr.xephi.authme.settings.propertymap;
-
-import fr.xephi.authme.ConsoleLogger;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Node class for building a tree from supplied String paths, ordered by insertion.
- *
- * For instance, consider a tree to which the following paths are inserted (in the given order):
- * "animal.bird.duck", "color.yellow", "animal.rodent.rat", "animal.rodent.rabbit", "color.red".
- * For such a tree:
- * - "animal" (or any of its children) is sorted before "color" (or any of its children)
- * - "animal.bird" or any child thereof is sorted before "animal.rodent"
- * - "animal.rodent.rat" comes before "animal.rodent.rabbit"
- *
- *
- * @see PropertyMapComparator
- */
-final class Node {
-
- private final String name;
- private final List children;
-
- private Node(String name) {
- this.name = name;
- this.children = new ArrayList<>();
- }
-
- /**
- * Create a root node, i.e. the starting node for a new tree. Call this method to create
- * a new tree and always pass this root to other methods.
- *
- * @return The generated root node.
- */
- public static Node createRoot() {
- return new Node(null);
- }
-
- /**
- * Add a child node, creating any intermediary children that don't exist.
- *
- * @param fullPath The entire path of the node to add, separate by periods
- */
- public void addNode(String fullPath) {
- String[] pathParts = fullPath.split("\\.");
- Node parent = this;
- for (String part : pathParts) {
- Node child = parent.getChild(part);
- if (child == null) {
- child = new Node(part);
- parent.children.add(child);
- }
- parent = child;
- }
- }
-
- /**
- * Compare two nodes by this class' sorting behavior (insertion order).
- * Note that this method assumes that both supplied paths exist in the tree.
- *
- * @param fullPath1 The full path to the first node
- * @param fullPath2 The full path to the second node
- * @return The comparison result, in the same format as {@link Comparable#compareTo}
- */
- public int compare(String fullPath1, String fullPath2) {
- String[] path1 = fullPath1.split("\\.");
- String[] path2 = fullPath2.split("\\.");
-
- int commonCount = 0;
- Node commonNode = this;
- while (commonCount < path1.length && commonCount < path2.length
- && path1[commonCount].equals(path2[commonCount]) && commonNode != null) {
- commonNode = commonNode.getChild(path1[commonCount]);
- ++commonCount;
- }
-
- if (commonNode == null) {
- ConsoleLogger.warning("Could not find common node for '" + fullPath1 + "' at index " + commonCount);
- return fullPath1.compareTo(fullPath2); // fallback
- } else if (commonCount >= path1.length || commonCount >= path2.length) {
- return Integer.compare(path1.length, path2.length);
- }
- int child1Index = commonNode.getChildIndex(path1[commonCount]);
- int child2Index = commonNode.getChildIndex(path2[commonCount]);
- return Integer.compare(child1Index, child2Index);
- }
-
- private Node getChild(String name) {
- for (Node child : children) {
- if (child.name.equals(name)) {
- return child;
- }
- }
- return null;
- }
-
- /**
- * Return the child's index, i.e. the position at which it was inserted to its parent.
- *
- * @param name The name of the node
- * @return The insertion index
- */
- private int getChildIndex(String name) {
- int i = 0;
- for (Node child : children) {
- if (child.name.equals(name)) {
- return i;
- }
- ++i;
- }
- return -1;
- }
-
- @Override
- public String toString() {
- return "Node '" + name + "'";
- }
-
-}
diff --git a/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMap.java b/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMap.java
deleted file mode 100644
index aed4ac0e..00000000
--- a/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMap.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package fr.xephi.authme.settings.propertymap;
-
-import fr.xephi.authme.settings.domain.Property;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * Class wrapping a {@code Map} for storing properties and their associated
- * comments with custom ordering.
- *
- * @see PropertyMapComparator for details about the map's order
- */
-public class PropertyMap {
-
- private Map, String[]> map;
- private PropertyMapComparator comparator;
-
- /**
- * Create a new property map.
- */
- public PropertyMap() {
- comparator = new PropertyMapComparator();
- map = new TreeMap<>(comparator);
- }
-
- /**
- * Add a new property to the map.
- *
- * @param property The property to add
- * @param comments The comments associated to the property
- */
- public void put(Property> property, String[] comments) {
- comparator.add(property);
- map.put(property, comments);
- }
-
- /**
- * Return the entry set of the map.
- *
- * @return The entry set
- */
- public Set, String[]>> entrySet() {
- return map.entrySet();
- }
-
- /**
- * Return the key set of the map, i.e. all property objects it holds.
- *
- * @return The key set
- */
- public Set> keySet() {
- return map.keySet();
- }
-
- /**
- * Return the size of the map.
- *
- * @return The size
- */
- public int size() {
- return map.size();
- }
-
-}
diff --git a/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMapComparator.java b/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMapComparator.java
deleted file mode 100644
index e6bd9fb4..00000000
--- a/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMapComparator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package fr.xephi.authme.settings.propertymap;
-
-import fr.xephi.authme.settings.domain.Property;
-
-import java.util.Comparator;
-
-/**
- * Custom comparator for {@link PropertyMap}. It guarantees that the map's entries:
- *
- * - are grouped by path, e.g. all "DataSource.mysql" properties are together, and "DataSource.mysql" properties
- * are within the broader "DataSource" group.
- * - are ordered by insertion, e.g. if the first "DataSource" property is inserted before the first "security"
- * property, then "DataSource" properties will come before the "security" ones.
- *
- */
-final class PropertyMapComparator implements Comparator> {
-
- private Node parent = Node.createRoot();
-
- /**
- * Method to call when adding a new property to the map (as to retain its insertion time).
- *
- * @param property The property that is being added
- */
- public void add(Property> property) {
- parent.addNode(property.getPath());
- }
-
- @Override
- public int compare(Property> p1, Property> p2) {
- return parent.compare(p1.getPath(), p2.getPath());
- }
-
-}
diff --git a/src/main/java/fr/xephi/authme/util/ValidationService.java b/src/main/java/fr/xephi/authme/util/ValidationService.java
index aae881a0..7225c1e0 100644
--- a/src/main/java/fr/xephi/authme/util/ValidationService.java
+++ b/src/main/java/fr/xephi/authme/util/ValidationService.java
@@ -1,12 +1,12 @@
package fr.xephi.authme.util;
+import com.github.authme.configme.properties.Property;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.settings.Settings;
-import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
diff --git a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java
index 131ca9e7..f00f234a 100644
--- a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java
+++ b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java
@@ -2,6 +2,7 @@ package fr.xephi.authme;
import ch.jalu.injector.Injector;
import ch.jalu.injector.InjectorBuilder;
+import com.github.authme.configme.resource.PropertyResource;
import com.google.common.io.Files;
import fr.xephi.authme.api.NewAPI;
import fr.xephi.authme.command.CommandHandler;
@@ -35,7 +36,7 @@ import java.io.IOException;
import java.util.logging.Logger;
import static fr.xephi.authme.settings.TestSettingsMigrationServices.alwaysFulfilled;
-import static fr.xephi.authme.settings.properties.SettingsFieldRetriever.getAllPropertyFields;
+import static fr.xephi.authme.settings.properties.AuthMeSettingsRetriever.getAllPropertyFields;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
@@ -93,7 +94,7 @@ public class AuthMeInitializationTest {
@Test
public void shouldInitializeAllServices() {
// given
- Settings settings = new Settings(settingsFile, dataFolder, getAllPropertyFields(), alwaysFulfilled());
+ Settings settings = new Settings(dataFolder, getAllPropertyFields(), mock(PropertyResource.class), alwaysFulfilled());
Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme").create();
injector.provide(DataFolder.class, dataFolder);
diff --git a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java
index 76fed3a3..07c8a289 100644
--- a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java
+++ b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java
@@ -1,9 +1,9 @@
package fr.xephi.authme.command;
+import com.github.authme.configme.properties.Property;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
-import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.ValidationService;
import org.bukkit.command.CommandSender;
diff --git a/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java b/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java
index 62f48f13..a5ab1d50 100644
--- a/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java
+++ b/src/test/java/fr/xephi/authme/datasource/AbstractResourceClosingTest.java
@@ -1,5 +1,6 @@
package fr.xephi.authme.datasource;
+import com.github.authme.configme.properties.Property;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
@@ -9,7 +10,6 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.Settings;
-import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.junit.Before;
import org.junit.BeforeClass;
diff --git a/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java
index 232f7a63..ca808921 100644
--- a/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java
+++ b/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java
@@ -1,10 +1,10 @@
package fr.xephi.authme.datasource;
+import com.github.authme.configme.properties.Property;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.settings.Settings;
-import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import org.junit.After;
import org.junit.Before;
diff --git a/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java
index d87bcfa4..e0eb3eca 100644
--- a/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java
+++ b/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java
@@ -1,9 +1,9 @@
package fr.xephi.authme.datasource;
+import com.github.authme.configme.properties.Property;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.settings.Settings;
-import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import org.junit.After;
import org.junit.Before;
diff --git a/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java
index cd66a801..7770fbfb 100644
--- a/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java
+++ b/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java
@@ -1,9 +1,13 @@
package fr.xephi.authme.settings;
+import com.github.authme.configme.migration.MigrationService;
+import com.github.authme.configme.migration.PlainMigrationService;
+import com.github.authme.configme.properties.Property;
+import com.github.authme.configme.propertymap.PropertyEntry;
+import com.github.authme.configme.resource.PropertyResource;
+import com.github.authme.configme.resource.YamlFileResource;
import fr.xephi.authme.TestHelper;
-import fr.xephi.authme.settings.domain.Property;
-import fr.xephi.authme.settings.properties.SettingsFieldRetriever;
-import fr.xephi.authme.settings.propertymap.PropertyMap;
+import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.FileConfiguration;
@@ -35,18 +39,18 @@ public class ConfigFileConsistencyTest {
public void shouldHaveAllConfigs() throws IOException {
// given
File configFile = TestHelper.getJarFile(CONFIG_FILE);
- FileConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
- SettingsMigrationService migration = new SettingsMigrationService();
+ PropertyResource resource = new YamlFileResource(configFile);
+ MigrationService migration = new PlainMigrationService();
// when
- boolean result = migration.containsAllSettings(configuration, SettingsFieldRetriever.getAllPropertyFields());
+ boolean result = migration.checkAndMigrate(resource, AuthMeSettingsRetriever.getAllPropertyFields());
// then
- if (!result) {
+ if (result) {
Set knownProperties = getAllKnownPropertyPaths();
List missingProperties = new ArrayList<>();
for (String path : knownProperties) {
- if (!configuration.contains(path)) {
+ if (!resource.contains(path)) {
missingProperties.add(path);
}
}
@@ -82,21 +86,22 @@ public class ConfigFileConsistencyTest {
public void shouldHaveValueCorrespondingToPropertyDefault() {
// given
File configFile = TestHelper.getJarFile(CONFIG_FILE);
- FileConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
- PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
+ PropertyResource resource = new YamlFileResource(configFile);
+ List knownProperties = AuthMeSettingsRetriever.getAllPropertyFields();
// when / then
- for (Property> property : propertyMap.keySet()) {
+ for (PropertyEntry propertyEntry : knownProperties) {
+ Property> property = propertyEntry.getProperty();
assertThat("Default value of '" + property.getPath() + "' in config.yml should be the same as in Property",
- property.getFromFile(configuration).equals(property.getDefaultValue()), equalTo(true));
+ property.getValue(resource).equals(property.getDefaultValue()), equalTo(true));
}
}
private static Set getAllKnownPropertyPaths() {
- PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
- Set paths = new HashSet<>(propertyMap.size());
- for (Property> property : propertyMap.keySet()) {
- paths.add(property.getPath());
+ List knownProperties = AuthMeSettingsRetriever.getAllPropertyFields();
+ Set paths = new HashSet<>(knownProperties.size());
+ for (PropertyEntry propertyEntry : knownProperties) {
+ paths.add(propertyEntry.getProperty().getPath());
}
return paths;
}
diff --git a/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java b/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java
index fd1f7301..f8f87ac0 100644
--- a/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java
+++ b/src/test/java/fr/xephi/authme/settings/SettingsIntegrationTest.java
@@ -1,13 +1,15 @@
package fr.xephi.authme.settings;
+import com.github.authme.configme.migration.PlainMigrationService;
+import com.github.authme.configme.properties.Property;
+import com.github.authme.configme.propertymap.PropertyEntry;
+import com.github.authme.configme.resource.PropertyResource;
+import com.github.authme.configme.resource.YamlFileResource;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import fr.xephi.authme.TestHelper;
-import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.TestConfiguration;
import fr.xephi.authme.settings.properties.TestEnum;
-import fr.xephi.authme.settings.propertymap.PropertyMap;
-import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -21,8 +23,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-import static fr.xephi.authme.settings.TestSettingsMigrationServices.checkAllPropertiesPresent;
-import static fr.xephi.authme.settings.domain.Property.newProperty;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@@ -35,10 +35,8 @@ public class SettingsIntegrationTest {
private static final String COMPLETE_FILE = TestHelper.PROJECT_ROOT + "settings/config-sample-values.yml";
/** File name of the sample config missing certain {@link TestConfiguration} values. */
private static final String INCOMPLETE_FILE = TestHelper.PROJECT_ROOT + "settings/config-incomplete-sample.yml";
- /** File name for testing difficult values. */
- private static final String DIFFICULT_FILE = TestHelper.PROJECT_ROOT + "settings/config-difficult-values.yml";
- private static PropertyMap propertyMap = TestConfiguration.generatePropertyMap();
+ private static List propertyMap = TestConfiguration.generatePropertyMap();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -58,13 +56,13 @@ public class SettingsIntegrationTest {
@Test
public void shouldLoadAndReadAllProperties() throws IOException {
// given
- YamlConfiguration configuration = YamlConfiguration.loadConfiguration(copyFileFromResources(COMPLETE_FILE));
+ PropertyResource resource = new YamlFileResource(copyFileFromResources(COMPLETE_FILE));
// Pass another, non-existent file to check if the settings had to be rewritten
File newFile = temporaryFolder.newFile();
// when / then
- Settings settings = new Settings(configuration, newFile, testPluginFolder, propertyMap,
- checkAllPropertiesPresent());
+ Settings settings = new Settings(testPluginFolder, propertyMap, resource,
+ new PlainMigrationService());
Map, Object> expectedValues = ImmutableMap., Object>builder()
.put(TestConfiguration.DURATION_IN_SECONDS, 22)
.put(TestConfiguration.SYSTEM_NAME, "Custom sys name")
@@ -88,16 +86,16 @@ public class SettingsIntegrationTest {
public void shouldWriteMissingProperties() {
// given/when
File file = copyFileFromResources(INCOMPLETE_FILE);
- YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
+ PropertyResource resource = new YamlFileResource(file);
// Expectation: File is rewritten to since it does not have all configurations
- new Settings(configuration, file, testPluginFolder, propertyMap, checkAllPropertiesPresent());
+ new Settings(testPluginFolder, propertyMap, resource, new PlainMigrationService());
// Load the settings again -> checks that what we wrote can be loaded again
- configuration = YamlConfiguration.loadConfiguration(file);
+ resource = new YamlFileResource(file);
// then
- Settings settings = new Settings(configuration, file, testPluginFolder, propertyMap,
- checkAllPropertiesPresent());
+ Settings settings = new Settings(testPluginFolder, propertyMap, resource,
+ new PlainMigrationService());
Map, Object> expectedValues = ImmutableMap., Object>builder()
.put(TestConfiguration.DURATION_IN_SECONDS, 22)
.put(TestConfiguration.SYSTEM_NAME, "[TestDefaultValue]")
@@ -116,62 +114,11 @@ public class SettingsIntegrationTest {
}
}
- /** Verify that "difficult cases" such as apostrophes in strings etc. are handled properly. */
- @Test
- public void shouldProperlyExportAnyValues() {
- // given
- File file = copyFileFromResources(DIFFICULT_FILE);
- YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file);
-
- // Additional string properties
- List> additionalProperties = Arrays.asList(
- newProperty("more.string1", "it's a text with some \\'apostrophes'"),
- newProperty("more.string2", "\tthis one\nhas some\nnew '' lines-test")
- );
- for (Property> property : additionalProperties) {
- propertyMap.put(property, new String[0]);
- }
-
- // when
- new Settings(configuration, file, testPluginFolder, propertyMap, checkAllPropertiesPresent());
- // reload the file as settings should have been rewritten
- configuration = YamlConfiguration.loadConfiguration(file);
-
- // then
- // assert that we won't rewrite the settings again! One rewrite should produce a valid, complete configuration
- File unusedFile = new File("config-difficult-values.unused.yml");
- Settings settings = new Settings(configuration, unusedFile, testPluginFolder, propertyMap,
- checkAllPropertiesPresent());
- assertThat(unusedFile.exists(), equalTo(false));
- assertThat(configuration.contains(TestConfiguration.DUST_LEVEL.getPath()), equalTo(true));
-
- Map, Object> expectedValues = ImmutableMap., Object>builder()
- .put(TestConfiguration.DURATION_IN_SECONDS, 20)
- .put(TestConfiguration.SYSTEM_NAME, "A 'test' name")
- .put(TestConfiguration.RATIO_ORDER, TestEnum.FOURTH)
- .put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia\\", "\tBurundi'", "Colombia?\n''"))
- .put(TestConfiguration.VERSION_NUMBER, -1337)
- .put(TestConfiguration.SKIP_BORING_FEATURES, false)
- .put(TestConfiguration.BORING_COLORS, Arrays.asList("it's a difficult string!", "gray\nwith new lines\n"))
- .put(TestConfiguration.DUST_LEVEL, -1)
- .put(TestConfiguration.USE_COOL_FEATURES, true)
- .put(TestConfiguration.COOL_OPTIONS, Collections.EMPTY_LIST)
- .put(additionalProperties.get(0), additionalProperties.get(0).getDefaultValue())
- .put(additionalProperties.get(1), additionalProperties.get(1).getDefaultValue())
- .build();
- for (Map.Entry, Object> entry : expectedValues.entrySet()) {
- assertThat("Property '" + entry.getKey().getPath() + "' has expected value"
- + entry.getValue() + " but found " + settings.getProperty(entry.getKey()),
- settings.getProperty(entry.getKey()), equalTo(entry.getValue()));
- }
- }
-
@Test
public void shouldReloadSettings() throws IOException {
// given
- YamlConfiguration configuration = YamlConfiguration.loadConfiguration(temporaryFolder.newFile());
- File fullConfigFile = copyFileFromResources(COMPLETE_FILE);
- Settings settings = new Settings(configuration, fullConfigFile, testPluginFolder, propertyMap,
+ PropertyResource resource = new YamlFileResource(temporaryFolder.newFile());
+ Settings settings = new Settings(testPluginFolder, propertyMap, resource,
TestSettingsMigrationServices.alwaysFulfilled());
// when
diff --git a/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java b/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java
index a85f86e1..df290d13 100644
--- a/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java
+++ b/src/test/java/fr/xephi/authme/settings/SettingsMigrationServiceTest.java
@@ -1,17 +1,18 @@
package fr.xephi.authme.settings;
+import com.github.authme.configme.propertymap.PropertyEntry;
+import com.github.authme.configme.resource.PropertyResource;
+import com.github.authme.configme.resource.YamlFileResource;
import com.google.common.io.Files;
import fr.xephi.authme.TestHelper;
-import fr.xephi.authme.settings.properties.SettingsFieldRetriever;
-import fr.xephi.authme.settings.propertymap.PropertyMap;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
+import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
+import java.util.List;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
@@ -39,13 +40,13 @@ public class SettingsMigrationServiceTest {
public void shouldNotRewriteJarConfig() throws IOException {
// given
copyConfigToTestFolder();
- FileConfiguration configuration = YamlConfiguration.loadConfiguration(configTestFile);
- PropertyMap propertyMap = SettingsFieldRetriever.getAllPropertyFields();
+ PropertyResource resource = new YamlFileResource(configTestFile);
+ List propertyMap = AuthMeSettingsRetriever.getAllPropertyFields();
assumeThat(testFolder.listFiles(), arrayWithSize(1));
- SettingsMigrationService migrationService = new SettingsMigrationService();
+ SettingsMigrationService migrationService = new SettingsMigrationService(testFolder);
// when
- boolean result = migrationService.checkAndMigrate(configuration, propertyMap, testFolder);
+ boolean result = migrationService.checkAndMigrate(resource, propertyMap);
// then
assertThat(result, equalTo(false));
diff --git a/src/test/java/fr/xephi/authme/settings/SettingsTest.java b/src/test/java/fr/xephi/authme/settings/SettingsTest.java
index fffbf15e..ce17ebd5 100644
--- a/src/test/java/fr/xephi/authme/settings/SettingsTest.java
+++ b/src/test/java/fr/xephi/authme/settings/SettingsTest.java
@@ -1,22 +1,23 @@
package fr.xephi.authme.settings;
+import com.github.authme.configme.migration.PlainMigrationService;
+import com.github.authme.configme.properties.Property;
+import com.github.authme.configme.propertymap.PropertyEntry;
+import com.github.authme.configme.resource.PropertyResource;
import fr.xephi.authme.TestHelper;
-import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.TestConfiguration;
-import fr.xephi.authme.settings.properties.TestEnum;
-import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.util.Collections;
import java.util.List;
import static fr.xephi.authme.settings.properties.PluginSettings.MESSAGES_LANGUAGE;
@@ -28,13 +29,9 @@ import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyDouble;
-import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
@@ -56,38 +53,12 @@ public class SettingsTest {
testPluginFolder = temporaryFolder.newFolder();
}
- @Test
- public void shouldLoadAllConfigs() {
- // given
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.getString(anyString(), anyString())).willAnswer(new ReturnsArgumentAt(1));
- given(configuration.getBoolean(anyString(), anyBoolean())).willAnswer(new ReturnsArgumentAt(1));
- given(configuration.getDouble(anyString(), anyDouble())).willAnswer(new ReturnsArgumentAt(1));
- given(configuration.getInt(anyString(), anyInt())).willAnswer(new ReturnsArgumentAt(1));
-
- setReturnValue(configuration, TestConfiguration.VERSION_NUMBER, 20);
- setReturnValue(configuration, TestConfiguration.SKIP_BORING_FEATURES, true);
- setReturnValue(configuration, TestConfiguration.RATIO_ORDER, TestEnum.THIRD);
- setReturnValue(configuration, TestConfiguration.SYSTEM_NAME, "myTestSys");
-
- // when / then
- Settings settings = new Settings(configuration, null, null, null, null);
-
- assertThat(settings.getProperty(TestConfiguration.VERSION_NUMBER), equalTo(20));
- assertThat(settings.getProperty(TestConfiguration.SKIP_BORING_FEATURES), equalTo(true));
- assertThat(settings.getProperty(TestConfiguration.RATIO_ORDER), equalTo(TestEnum.THIRD));
- assertThat(settings.getProperty(TestConfiguration.SYSTEM_NAME), equalTo("myTestSys"));
-
- assertDefaultValue(TestConfiguration.DURATION_IN_SECONDS, settings);
- assertDefaultValue(TestConfiguration.DUST_LEVEL, settings);
- assertDefaultValue(TestConfiguration.COOL_OPTIONS, settings);
- }
-
@Test
public void shouldReturnDefaultFile() throws IOException {
// given
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- Settings settings = new Settings(configuration, null, null, null, null);
+ PropertyResource resource = mock(PropertyResource.class);
+ List knownProperties = Collections.emptyList();
+ Settings settings = new Settings(testPluginFolder, knownProperties, resource, new PlainMigrationService());
// when
String defaultFile = settings.getDefaultMessagesFile();
@@ -99,19 +70,6 @@ public class SettingsTest {
assertThat(stream.read(), not(equalTo(0)));
}
- @Test
- public void shouldSetProperty() {
- // given
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- Settings settings = new Settings(configuration, null, null, null, null);
-
- // when
- settings.setProperty(TestConfiguration.DUST_LEVEL, -4);
-
- // then
- verify(configuration).set(TestConfiguration.DUST_LEVEL.getPath(), -4);
- }
-
@Test
public void shouldReturnMessagesFile() {
// given
@@ -120,11 +78,11 @@ public class SettingsTest {
File file = new File(testPluginFolder, makePath("messages", "messages_" + languageCode + ".yml"));
createFile(file);
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.contains(anyString())).willReturn(true);
- setReturnValue(configuration, MESSAGES_LANGUAGE, languageCode);
- Settings settings = new Settings(configuration, null, testPluginFolder,
- TestConfiguration.generatePropertyMap(), TestSettingsMigrationServices.alwaysFulfilled());
+ PropertyResource resource = mock(PropertyResource.class);
+ given(resource.contains(anyString())).willReturn(true);
+ setReturnValue(resource, MESSAGES_LANGUAGE, languageCode);
+ Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
+ resource, TestSettingsMigrationServices.alwaysFulfilled());
// when
File messagesFile = settings.getMessagesFile();
@@ -137,11 +95,11 @@ public class SettingsTest {
@Test
public void shouldCopyDefaultForUnknownLanguageCode() {
// given
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.contains(anyString())).willReturn(true);
- setReturnValue(configuration, MESSAGES_LANGUAGE, "doesntexist");
- Settings settings = new Settings(configuration, null, testPluginFolder,
- TestConfiguration.generatePropertyMap(), TestSettingsMigrationServices.alwaysFulfilled());
+ PropertyResource resource = mock(PropertyResource.class);
+ given(resource.contains(anyString())).willReturn(true);
+ setReturnValue(resource, MESSAGES_LANGUAGE, "doesntexist");
+ Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
+ resource, TestSettingsMigrationServices.alwaysFulfilled());
// when
File messagesFile = settings.getMessagesFile();
@@ -159,10 +117,10 @@ public class SettingsTest {
createFile(welcomeFile);
Files.write(welcomeFile.toPath(), welcomeMessage.getBytes());
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- setReturnValue(configuration, RegistrationSettings.USE_WELCOME_MESSAGE, true);
- Settings settings = new Settings(configuration, null, testPluginFolder,
- TestConfiguration.generatePropertyMap(), TestSettingsMigrationServices.alwaysFulfilled());
+ PropertyResource resource = mock(PropertyResource.class);
+ setReturnValue(resource, RegistrationSettings.USE_WELCOME_MESSAGE, true);
+ Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
+ resource, TestSettingsMigrationServices.alwaysFulfilled());
// when
List result = settings.getWelcomeMessage();
@@ -181,9 +139,9 @@ public class SettingsTest {
createFile(emailFile);
Files.write(emailFile.toPath(), emailMessage.getBytes());
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- Settings settings = new Settings(configuration, null, testPluginFolder,
- TestConfiguration.generatePropertyMap(), TestSettingsMigrationServices.alwaysFulfilled());
+ PropertyResource resource = mock(PropertyResource.class);
+ Settings settings = new Settings(testPluginFolder, TestConfiguration.generatePropertyMap(),
+ resource, TestSettingsMigrationServices.alwaysFulfilled());
// when
String result = settings.getEmailMessage();
@@ -192,26 +150,21 @@ public class SettingsTest {
assertThat(result, equalTo(emailMessage));
}
- private static void setReturnValue(YamlConfiguration config, Property property, T value) {
+ private static void setReturnValue(PropertyResource resource, Property property, T value) {
if (value instanceof String) {
- when(config.getString(eq(property.getPath()), anyString())).thenReturn((String) value);
+ when(resource.getString(eq(property.getPath()))).thenReturn((String) value);
} else if (value instanceof Integer) {
- when(config.getInt(eq(property.getPath()), anyInt())).thenReturn((Integer) value);
+ when(resource.getInt(eq(property.getPath()))).thenReturn((Integer) value);
} else if (value instanceof Boolean) {
- when(config.getBoolean(eq(property.getPath()), anyBoolean())).thenReturn((Boolean) value);
+ when(resource.getBoolean(eq(property.getPath()))).thenReturn((Boolean) value);
} else if (value instanceof Enum>) {
- when(config.getString(property.getPath())).thenReturn(((Enum>) value).name());
+ when(resource.getString(property.getPath())).thenReturn(((Enum>) value).name());
} else {
throw new UnsupportedOperationException("Value has unsupported type '"
+ (value == null ? "null" : value.getClass().getSimpleName()) + "'");
}
}
- private static void assertDefaultValue(Property> property, Settings setting) {
- assertThat(property.getPath() + " has default value",
- setting.getProperty(property).equals(property.getDefaultValue()), equalTo(true));
- }
-
private static void createFile(File file) {
try {
file.getParentFile().mkdirs();
diff --git a/src/test/java/fr/xephi/authme/settings/TestSettingsMigrationServices.java b/src/test/java/fr/xephi/authme/settings/TestSettingsMigrationServices.java
index b3c7dd08..c7b64fb4 100644
--- a/src/test/java/fr/xephi/authme/settings/TestSettingsMigrationServices.java
+++ b/src/test/java/fr/xephi/authme/settings/TestSettingsMigrationServices.java
@@ -1,12 +1,13 @@
package fr.xephi.authme.settings;
-import fr.xephi.authme.settings.propertymap.PropertyMap;
-import org.bukkit.configuration.file.FileConfiguration;
+import com.github.authme.configme.migration.MigrationService;
+import com.github.authme.configme.propertymap.PropertyEntry;
+import com.github.authme.configme.resource.PropertyResource;
-import java.io.File;
+import java.util.List;
/**
- * Provides {@link SettingsMigrationService} implementations for testing.
+ * Provides {@link MigrationService} implementations for testing.
*/
public final class TestSettingsMigrationServices {
@@ -18,32 +19,12 @@ public final class TestSettingsMigrationServices {
*
* @return test settings migration service
*/
- public static SettingsMigrationService alwaysFulfilled() {
- return new SettingsMigrationService() {
+ public static MigrationService alwaysFulfilled() {
+ return new MigrationService() {
@Override
- public boolean checkAndMigrate(FileConfiguration configuration, PropertyMap propertyMap, File pluginFolder) {
+ public boolean checkAndMigrate(PropertyResource propertyResource, List list) {
return false;
}
- @Override
- public boolean containsAllSettings(FileConfiguration configuration, PropertyMap propertyMap) {
- return true;
- }
};
}
-
- /**
- * Returns a simple settings migration service which is fulfilled if all properties are present.
- *
- * @return test settings migration service
- */
- public static SettingsMigrationService checkAllPropertiesPresent() {
- return new SettingsMigrationService() {
- // See parent javadoc: true = some migration had to be done, false = config file is up-to-date
- @Override
- public boolean checkAndMigrate(FileConfiguration configuration, PropertyMap propertyMap, File pluginFolder) {
- return !super.containsAllSettings(configuration, propertyMap);
- }
- };
- }
-
}
diff --git a/src/test/java/fr/xephi/authme/settings/domain/EnumPropertyTest.java b/src/test/java/fr/xephi/authme/settings/domain/EnumPropertyTest.java
deleted file mode 100644
index 5fe55362..00000000
--- a/src/test/java/fr/xephi/authme/settings/domain/EnumPropertyTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package fr.xephi.authme.settings.domain;
-
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
-/**
- * Test for {@link EnumProperty}.
- */
-public class EnumPropertyTest {
-
- @Test
- public void shouldReturnCorrectEnumValue() {
- // given
- Property property = Property.newProperty(TestEnum.class, "enum.path", TestEnum.ENTRY_C);
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.getString(property.getPath())).willReturn("Entry_B");
-
- // when
- TestEnum result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo(TestEnum.ENTRY_B));
- }
-
- @Test
- public void shouldFallBackToDefaultForInvalidValue() {
- // given
- Property property = Property.newProperty(TestEnum.class, "enum.path", TestEnum.ENTRY_C);
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.getString(property.getPath())).willReturn("Bogus");
-
- // when
- TestEnum result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo(TestEnum.ENTRY_C));
- }
-
- @Test
- public void shouldFallBackToDefaultForNonExistentValue() {
- // given
- Property property = Property.newProperty(TestEnum.class, "enum.path", TestEnum.ENTRY_C);
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.getString(property.getPath())).willReturn(null);
-
- // when
- TestEnum result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo(TestEnum.ENTRY_C));
- }
-
- @Test
- public void shouldReturnTrueForContainsCheck() {
- // given
- Property property = Property.newProperty(TestEnum.class, "my.test.path", TestEnum.ENTRY_C);
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.contains(property.getPath())).willReturn(true);
- given(configuration.getString(property.getPath())).willReturn("ENTRY_B");
-
- // when
- boolean result = property.isPresent(configuration);
-
- // then
- assertThat(result, equalTo(true));
- }
-
- @Test
- public void shouldReturnFalseForFileWithoutConfig() {
- // given
- Property property = Property.newProperty(TestEnum.class, "my.test.path", TestEnum.ENTRY_C);
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.contains(property.getPath())).willReturn(false);
-
- // when
- boolean result = property.isPresent(configuration);
-
- // then
- assertThat(result, equalTo(false));
- }
-
- @Test
- public void shouldReturnFalseForUnknownValue() {
- // given
- Property property = Property.newProperty(TestEnum.class, "my.test.path", TestEnum.ENTRY_C);
- YamlConfiguration configuration = mock(YamlConfiguration.class);
- given(configuration.contains(property.getPath())).willReturn(true);
- given(configuration.getString(property.getPath())).willReturn("wrong value");
-
- // when
- boolean result = property.isPresent(configuration);
-
- // then
- assertThat(result, equalTo(false));
- }
-
-
- private enum TestEnum {
-
- ENTRY_A,
-
- ENTRY_B,
-
- ENTRY_C
-
- }
-}
diff --git a/src/test/java/fr/xephi/authme/settings/domain/PropertyTest.java b/src/test/java/fr/xephi/authme/settings/domain/PropertyTest.java
deleted file mode 100644
index 3ea8ff0e..00000000
--- a/src/test/java/fr/xephi/authme/settings/domain/PropertyTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-package fr.xephi.authme.settings.domain;
-
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-/**
- * Test for {@link Property} and the contained subtypes.
- */
-public class PropertyTest {
-
- private static YamlConfiguration configuration;
-
- @BeforeClass
- public static void setUpYamlConfigurationMock() {
- configuration = mock(YamlConfiguration.class);
-
- when(configuration.getBoolean(eq("bool.path.test"), anyBoolean())).thenReturn(true);
- when(configuration.getBoolean(eq("bool.path.wrong"), anyBoolean())).thenAnswer(new ReturnsArgumentAt(1));
- when(configuration.getInt(eq("int.path.test"), anyInt())).thenReturn(27);
- when(configuration.getInt(eq("int.path.wrong"), anyInt())).thenAnswer(new ReturnsArgumentAt(1));
- when(configuration.getString(eq("str.path.test"), anyString())).thenReturn("Test value");
- when(configuration.getString(eq("str.path.wrong"), anyString())).thenAnswer(new ReturnsArgumentAt(1));
- when(configuration.isList("list.path.test")).thenReturn(true);
- when(configuration.getStringList("list.path.test")).thenReturn(Arrays.asList("test1", "Test2", "3rd test"));
- when(configuration.isList("list.path.wrong")).thenReturn(false);
- when(configuration.isList("lowercaselist.path.test")).thenReturn(true);
- when(configuration.getStringList("lowercaselist.path.test")).thenReturn(Arrays.asList("test1", "Test2", "3rd test"));
- when(configuration.isList("lowercaselist.path.wrong")).thenReturn(false);
- }
-
- /* Boolean */
- @Test
- public void shouldGetBoolValue() {
- // given
- Property property = Property.newProperty("bool.path.test", false);
-
- // when
- boolean result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo(true));
- }
-
- @Test
- public void shouldGetBoolDefault() {
- // given
- Property property = Property.newProperty("bool.path.wrong", true);
-
- // when
- boolean result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo(true));
- }
-
- /* Integer */
- @Test
- public void shouldGetIntValue() {
- // given
- Property property = Property.newProperty("int.path.test", 3);
-
- // when
- int result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo(27));
- }
-
- @Test
- public void shouldGetIntDefault() {
- // given
- Property property = Property.newProperty("int.path.wrong", -10);
-
- // when
- int result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo(-10));
- }
-
- /* String */
- @Test
- public void shouldGetStringValue() {
- // given
- Property property = Property.newProperty("str.path.test", "unused default");
-
- // when
- String result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo("Test value"));
- }
-
- @Test
- public void shouldGetStringDefault() {
- // given
- Property property = Property.newProperty("str.path.wrong", "given default value");
-
- // when
- String result = property.getFromFile(configuration);
-
- // then
- assertThat(result, equalTo("given default value"));
- }
-
- /* String list */
- @Test
- public void shouldGetStringListValue() {
- // given
- Property> property = Property.newListProperty("list.path.test", "1", "b");
-
- // when
- List result = property.getFromFile(configuration);
-
- // then
- assertThat(result, contains("test1", "Test2", "3rd test"));
- }
-
- @Test
- public void shouldGetStringListDefault() {
- // given
- Property> property =
- Property.newListProperty("list.path.wrong", "default", "list", "elements");
-
- // when
- List result = property.getFromFile(configuration);
-
- // then
- assertThat(result, contains("default", "list", "elements"));
- }
-
- /* Lowercase String list */
- @Test
- public void shouldGetLowercaseStringListValue() {
- // given
- Property> property = Property.newLowercaseListProperty("lowercaselist.path.test", "1", "b");
-
- // when
- List result = property.getFromFile(configuration);
-
- // then
- assertThat(result, contains("test1", "test2", "3rd test"));
- }
-
- @Test
- public void shouldGetLowercaseStringListDefault() {
- // given
- Property> property =
- Property.newLowercaseListProperty("lowercaselist.path.wrong", "default", "list", "elements");
-
- // when
- List result = property.getFromFile(configuration);
-
- // then
- assertThat(result, contains("default", "list", "elements"));
- }
-}
diff --git a/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java
index 2be46b72..0b99ac5c 100644
--- a/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java
+++ b/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java
@@ -1,9 +1,9 @@
package fr.xephi.authme.settings.properties;
+import com.github.authme.configme.SettingsHolder;
+import com.github.authme.configme.properties.Property;
import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.TestHelper;
-import fr.xephi.authme.settings.domain.Property;
-import fr.xephi.authme.settings.domain.SettingsClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -20,12 +20,12 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
- * Test for {@link SettingsClass} implementations.
+ * Test for {@link SettingsHolder} implementations.
*/
public class SettingsClassConsistencyTest {
private static final String SETTINGS_FOLDER = "src/main/java/fr/xephi/authme/settings/properties";
- private static List> classes;
+ private static List> classes;
@BeforeClass
public static void scanForSettingsClasses() {
@@ -37,7 +37,7 @@ public class SettingsClassConsistencyTest {
classes = new ArrayList<>();
for (File file : filesInFolder) {
- Class extends SettingsClass> clazz = getSettingsClassFromFile(file);
+ Class extends SettingsHolder> clazz = getSettingsClassFromFile(file);
if (clazz != null) {
classes.add(clazz);
}
@@ -95,15 +95,15 @@ public class SettingsClassConsistencyTest {
}
@SuppressWarnings("unchecked")
- private static Class extends SettingsClass> getSettingsClassFromFile(File file) {
+ private static Class extends SettingsHolder> getSettingsClassFromFile(File file) {
String fileName = file.getPath();
String className = fileName
.substring("src/main/java/".length(), fileName.length() - ".java".length())
.replace(File.separator, ".");
try {
Class> clazz = SettingsClassConsistencyTest.class.getClassLoader().loadClass(className);
- if (SettingsClass.class.isAssignableFrom(clazz)) {
- return (Class extends SettingsClass>) clazz;
+ if (SettingsHolder.class.isAssignableFrom(clazz)) {
+ return (Class extends SettingsHolder>) clazz;
}
return null;
} catch (ClassNotFoundException e) {
diff --git a/src/test/java/fr/xephi/authme/settings/properties/TestConfiguration.java b/src/test/java/fr/xephi/authme/settings/properties/TestConfiguration.java
index 0f16e1e8..7019dc2f 100644
--- a/src/test/java/fr/xephi/authme/settings/properties/TestConfiguration.java
+++ b/src/test/java/fr/xephi/authme/settings/properties/TestConfiguration.java
@@ -1,20 +1,21 @@
package fr.xephi.authme.settings.properties;
+import com.github.authme.configme.SettingsHolder;
+import com.github.authme.configme.properties.Property;
+import com.github.authme.configme.propertymap.PropertyEntry;
import fr.xephi.authme.ReflectionTestUtils;
-import fr.xephi.authme.settings.domain.Property;
-import fr.xephi.authme.settings.domain.SettingsClass;
-import fr.xephi.authme.settings.propertymap.PropertyMap;
import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.List;
-import static fr.xephi.authme.settings.domain.Property.newListProperty;
-import static fr.xephi.authme.settings.domain.Property.newProperty;
+import static com.github.authme.configme.properties.PropertyInitializer.newListProperty;
+import static com.github.authme.configme.properties.PropertyInitializer.newProperty;
/**
* Sample properties for testing purposes.
*/
-public final class TestConfiguration implements SettingsClass {
+public final class TestConfiguration implements SettingsHolder {
public static final Property DURATION_IN_SECONDS =
newProperty("test.duration", 4);
@@ -55,17 +56,17 @@ public final class TestConfiguration implements SettingsClass {
*
* @return The generated property map
*/
- public static PropertyMap generatePropertyMap() {
- PropertyMap propertyMap = new PropertyMap();
+ public static List generatePropertyMap() {
+ List properties = new ArrayList<>();
for (Field field : TestConfiguration.class.getDeclaredFields()) {
Object fieldValue = ReflectionTestUtils.getFieldValue(TestConfiguration.class, null, field.getName());
if (fieldValue instanceof Property>) {
Property> property = (Property>) fieldValue;
String[] comments = new String[]{"Comment for '" + property.getPath() + "'"};
- propertyMap.put(property, comments);
+ properties.add(new PropertyEntry(property, comments));
}
}
- return propertyMap;
+ return properties;
}
}
diff --git a/src/test/java/fr/xephi/authme/settings/propertymap/PropertyMapTest.java b/src/test/java/fr/xephi/authme/settings/propertymap/PropertyMapTest.java
deleted file mode 100644
index 40ea14b7..00000000
--- a/src/test/java/fr/xephi/authme/settings/propertymap/PropertyMapTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package fr.xephi.authme.settings.propertymap;
-
-import fr.xephi.authme.settings.domain.Property;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-
-import static org.hamcrest.Matchers.contains;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-/**
- * Test for {@link PropertyMap}.
- */
-public class PropertyMapTest {
-
- @Test
- public void shouldKeepEntriesByInsertionAndGroup() {
- // given
- List paths = Arrays.asList("japan", "indonesia.jakarta", "japan.tokyo", "china.shanghai", "egypt.cairo",
- "china.shenzhen", "china", "indonesia.jakarta.tugu", "egypt", "japan.nagoya", "japan.tokyo.taito");
- PropertyMap map = new PropertyMap();
-
- // when
- for (String path : paths) {
- Property> property = createPropertyWithPath(path);
- map.put(property, new String[0]);
- }
-
- // then
- Set, String[]>> entrySet = map.entrySet();
- List resultPaths = new ArrayList<>(entrySet.size());
- for (Map.Entry, String[]> entry : entrySet) {
- resultPaths.add(entry.getKey().getPath());
- }
-
- Assert.assertThat(resultPaths, contains("japan", "japan.tokyo", "japan.tokyo.taito", "japan.nagoya",
- "indonesia.jakarta", "indonesia.jakarta.tugu", "china", "china.shanghai", "china.shenzhen",
- "egypt", "egypt.cairo"));
- }
-
- private static Property> createPropertyWithPath(String path) {
- Property> property = mock(Property.class);
- when(property.getPath()).thenReturn(path);
- return property;
- }
-}
diff --git a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java b/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java
index 7e8c18f7..23fa6d6b 100644
--- a/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java
+++ b/src/test/java/tools/hashmethods/EncryptionMethodInfoGatherer.java
@@ -2,6 +2,7 @@ package tools.hashmethods;
import ch.jalu.injector.Injector;
import ch.jalu.injector.InjectorBuilder;
+import com.github.authme.configme.properties.Property;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.crypts.EncryptionMethod;
import fr.xephi.authme.security.crypts.HexSaltedMethod;
@@ -9,7 +10,6 @@ import fr.xephi.authme.security.crypts.description.AsciiRestricted;
import fr.xephi.authme.security.crypts.description.HasSalt;
import fr.xephi.authme.security.crypts.description.Recommendation;
import fr.xephi.authme.settings.Settings;
-import fr.xephi.authme.settings.domain.Property;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
diff --git a/src/test/resources/fr/xephi/authme/settings/config-difficult-values.yml b/src/test/resources/fr/xephi/authme/settings/config-difficult-values.yml
deleted file mode 100644
index 29bc0e37..00000000
--- a/src/test/resources/fr/xephi/authme/settings/config-difficult-values.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-# Test config file with some "difficult" values
-
-test:
- duration: 20.102
- systemName: 'A ''test'' name'
-sample:
- ratio:
- order: Fourth
- fields:
- - Australia\
- - ' Burundi'''
- - 'Colombia?
-
- '''''
- # The last element above represents "Colombia?\n''"
-version: -1337
-features:
- boring:
- # YAML allows both "yes"/"no" and "true"/"false" for expressing booleans
- skip: no
- colors:
- - 'it''s a difficult string!'
- - |
- gray
- with new lines
- # dustLevel: 8 <-- missing property triggering rewrite
- cool:
- enabled: yes
- options: []