Search in sources :

Example 1 with SettingsHolder

use of ch.jalu.configme.SettingsHolder in project AuthMeReloaded by AuthMe.

the class SettingsClassConsistencyTest method shouldHaveAllClassesInConfigurationData.

/**
     * Checks that {@link AuthMeSettingsRetriever} returns a ConfigurationData with all
     * available SettingsHolder classes.
     */
@Test
public void shouldHaveAllClassesInConfigurationData() {
    // given
    long totalProperties = classes.stream().map(Class::getDeclaredFields).flatMap(Arrays::stream).filter(field -> Property.class.isAssignableFrom(field.getType())).count();
    // when
    ConfigurationData configData = AuthMeSettingsRetriever.buildConfigurationData();
    // then
    assertThat("ConfigurationData should have " + totalProperties + " properties (as found manually)", configData.getProperties(), hasSize((int) totalProperties));
}
Also used : Arrays(java.util.Arrays) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) Set(java.util.Set) Test(org.junit.Test) Field(java.lang.reflect.Field) ReflectionTestUtils(fr.xephi.authme.ReflectionTestUtils) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Property(ch.jalu.configme.properties.Property) Modifier(java.lang.reflect.Modifier) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SettingsHolder(ch.jalu.configme.SettingsHolder) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) TestHelper(fr.xephi.authme.TestHelper) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Arrays(java.util.Arrays) Test(org.junit.Test)

Example 2 with SettingsHolder

use of ch.jalu.configme.SettingsHolder in project AuthMeReloaded by AuthMe.

the class SettingsClassConsistencyTest method scanForSettingsClasses.

@BeforeClass
public static void scanForSettingsClasses() {
    ClassCollector collector = new ClassCollector(TestHelper.SOURCES_FOLDER, SETTINGS_FOLDER);
    classes = collector.collectClasses(SettingsHolder.class);
    if (classes.isEmpty()) {
        throw new IllegalStateException("Did not find any SettingsHolder classes. Is the folder correct?");
    }
    System.out.println("Found " + classes.size() + " SettingsHolder implementations");
}
Also used : ClassCollector(fr.xephi.authme.ClassCollector) SettingsHolder(ch.jalu.configme.SettingsHolder) BeforeClass(org.junit.BeforeClass)

Example 3 with SettingsHolder

use of ch.jalu.configme.SettingsHolder in project AuthMeReloaded by AuthMe.

the class SettingsConsistencyTest method getSectionCommentMethods.

/**
     * Gets all {@link SectionComments} methods from {@link SettingsHolder} implementations.
     */
@SuppressWarnings("unchecked")
private List<Method> getSectionCommentMethods() {
    // Find all SettingsHolder classes
    List<Class<? extends SettingsHolder>> settingsClasses = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "settings/properties/").collectClasses(SettingsHolder.class);
    checkArgument(!settingsClasses.isEmpty(), "Could not find any SettingsHolder classes");
    // Find all @SectionComments methods in these classes
    return settingsClasses.stream().map(Class::getDeclaredMethods).flatMap(Arrays::stream).filter(method -> method.isAnnotationPresent(SectionComments.class)).collect(Collectors.toList());
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Arrays(java.util.Arrays) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) SettingsHolder(ch.jalu.configme.SettingsHolder) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Assert.fail(org.junit.Assert.fail) TestHelper(fr.xephi.authme.TestHelper) Method(java.lang.reflect.Method) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Test(org.junit.Test) EnumProperty(ch.jalu.configme.properties.EnumProperty) Collectors(java.util.stream.Collectors) ReflectionTestUtils(fr.xephi.authme.ReflectionTestUtils) ReflectionTestUtils.getFieldValue(fr.xephi.authme.ReflectionTestUtils.getFieldValue) List(java.util.List) Property(ch.jalu.configme.properties.Property) AuthMeSettingsRetriever(fr.xephi.authme.settings.properties.AuthMeSettingsRetriever) SectionComments(ch.jalu.configme.SectionComments) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) Arrays(java.util.Arrays) SettingsHolder(ch.jalu.configme.SettingsHolder)

Aggregations

SettingsHolder (ch.jalu.configme.SettingsHolder)3 ClassCollector (fr.xephi.authme.ClassCollector)3 BeforeClass (org.junit.BeforeClass)3 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)2 Property (ch.jalu.configme.properties.Property)2 ReflectionTestUtils (fr.xephi.authme.ReflectionTestUtils)2 TestHelper (fr.xephi.authme.TestHelper)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Assert.fail (org.junit.Assert.fail)2 Test (org.junit.Test)2 SectionComments (ch.jalu.configme.SectionComments)1 EnumProperty (ch.jalu.configme.properties.EnumProperty)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ReflectionTestUtils.getFieldValue (fr.xephi.authme.ReflectionTestUtils.getFieldValue)1 AuthMeSettingsRetriever (fr.xephi.authme.settings.properties.AuthMeSettingsRetriever)1 SecuritySettings (fr.xephi.authme.settings.properties.SecuritySettings)1