Search in sources :

Example 1 with SectionComments

use of ch.jalu.configme.SectionComments 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)

Example 2 with SectionComments

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

the class SettingsConsistencyTest method shouldNotHaveVeryLongSectionCommentLines.

@Test
public void shouldNotHaveVeryLongSectionCommentLines() {
    // given
    List<Method> sectionCommentMethods = getSectionCommentMethods();
    Set<Method> badMethods = new HashSet<>();
    // when
    for (Method method : sectionCommentMethods) {
        boolean hasTooLongLine = getSectionComments(method).stream().anyMatch(line -> line.length() > MAX_COMMENT_LENGTH);
        if (hasTooLongLine) {
            badMethods.add(method);
        }
    }
    // then
    if (!badMethods.isEmpty()) {
        String methodList = badMethods.stream().map(m -> m.getName() + " in " + m.getDeclaringClass().getSimpleName()).collect(Collectors.joining("\n- "));
        fail("Found SectionComments methods with too long comments:\n- " + methodList);
    }
}
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) Method(java.lang.reflect.Method) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SectionComments (ch.jalu.configme.SectionComments)2 SettingsHolder (ch.jalu.configme.SettingsHolder)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)2 EnumProperty (ch.jalu.configme.properties.EnumProperty)2 Property (ch.jalu.configme.properties.Property)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ClassCollector (fr.xephi.authme.ClassCollector)2 ReflectionTestUtils (fr.xephi.authme.ReflectionTestUtils)2 ReflectionTestUtils.getFieldValue (fr.xephi.authme.ReflectionTestUtils.getFieldValue)2 TestHelper (fr.xephi.authme.TestHelper)2 AuthMeSettingsRetriever (fr.xephi.authme.settings.properties.AuthMeSettingsRetriever)2 SecuritySettings (fr.xephi.authme.settings.properties.SecuritySettings)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2