#927 Integrate ConfigMe into AuthMe (work in progress)
- Replace own code with ConfigMe
This commit is contained in:
@@ -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<Class<? extends SettingsClass>> classes;
|
||||
private static List<Class<? extends SettingsHolder>> 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) {
|
||||
|
||||
@@ -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<Integer> 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<PropertyEntry> generatePropertyMap() {
|
||||
List<PropertyEntry> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user