Search in sources :

Example 31 with DataExtension

use of com.djrapitops.plan.extension.DataExtension in project Plan by plan-player-analytics.

the class ExtensionExtractorTest method descriptionOver50CharsIsWarnedAbout.

@Test
void descriptionOver50CharsIsWarnedAbout() {
    @PluginInfo(name = "Extension")
    class Extension implements DataExtension {

        @StringProvider(text = "a", description = "aaaaaAAAAAbbbbbBBBBBcccccCCCCCdddddDDDDDeeeeeEEEEEaaaaaAAAAAbbbbbBBBBBcccccCCCCCdddddDDDDDeeeeeEEEEEaaaaaAAAAAbbbbbBBBBBcccccCCCCCdddddDDDDDeeeeeEEEEEfffffFFFFF")
        public String method() {
            return "example";
        }
    }
    Extension extension = new Extension();
    ExtensionExtractor underTest = new ExtensionExtractor(extension);
    assertEquals("Warnings: [Extension.method 'description' was over 150 characters.]", assertThrows(IllegalArgumentException.class, underTest::validateAnnotations).getMessage());
}
Also used : DataExtension(com.djrapitops.plan.extension.DataExtension) DataExtension(com.djrapitops.plan.extension.DataExtension) Test(org.junit.jupiter.api.Test)

Example 32 with DataExtension

use of com.djrapitops.plan.extension.DataExtension in project Plan by plan-player-analytics.

the class ExtensionExtractorTest method stringProviderMustReturnString.

@Test
void stringProviderMustReturnString() {
    @PluginInfo(name = "Extension")
    class Extension implements DataExtension {

        @StringProvider(text = "Town")
        public Double method(UUID playerUUID) {
            return null;
        }
    }
    ExtensionExtractor underTest = new ExtensionExtractor(new Extension());
    assertEquals("Extension.method has invalid return type. was: java.lang.Double, expected: java.lang.String", assertThrows(IllegalArgumentException.class, underTest::validateAnnotations).getMessage());
}
Also used : DataExtension(com.djrapitops.plan.extension.DataExtension) DataExtension(com.djrapitops.plan.extension.DataExtension) Test(org.junit.jupiter.api.Test)

Example 33 with DataExtension

use of com.djrapitops.plan.extension.DataExtension in project Plan by plan-player-analytics.

the class ExtensionExtractorTest method methodNeedsValidParameters.

@Test
void methodNeedsValidParameters() {
    @PluginInfo(name = "Extension")
    class Extension implements DataExtension {

        @Conditional("hasJoined")
        @BooleanProvider(text = "Banned", conditionName = "isBanned")
        public boolean method(Integer invalid) {
            return false;
        }
    }
    ExtensionExtractor underTest = new ExtensionExtractor(new Extension());
    assertEquals("Extension.method has invalid parameter: 'java.lang.Integer' one of [class java.util.UUID, class java.lang.String, interface com.djrapitops.plan.extension.Group] is required as a parameter.", assertThrows(IllegalArgumentException.class, underTest::validateAnnotations).getMessage());
}
Also used : DataExtension(com.djrapitops.plan.extension.DataExtension) DataExtension(com.djrapitops.plan.extension.DataExtension) Test(org.junit.jupiter.api.Test)

Example 34 with DataExtension

use of com.djrapitops.plan.extension.DataExtension in project Plan by plan-player-analytics.

the class ExtensionExtractorTest method methodsAreExtracted6.

@Test
void methodsAreExtracted6() throws NoSuchMethodException {
    @PluginInfo(name = "Extension")
    class Extension implements DataExtension {

        @TableProvider
        public Table method() {
            return Table.builder().build();
        }
    }
    Extension extension = new Extension();
    ExtensionExtractor underTest = new ExtensionExtractor(extension);
    Map<ExtensionMethod.ParameterType, ExtensionMethods> result = underTest.getMethods();
    Map<ExtensionMethod.ParameterType, ExtensionMethods> expected = buildExpectedExtensionMethodMap(extension, ExtensionMethods::addTableMethod);
    assertEquals(expected, result);
}
Also used : DataExtension(com.djrapitops.plan.extension.DataExtension) DataExtension(com.djrapitops.plan.extension.DataExtension) Test(org.junit.jupiter.api.Test)

Example 35 with DataExtension

use of com.djrapitops.plan.extension.DataExtension in project Plan by plan-player-analytics.

the class ClassValuePairOrderTest method providedConditionsComeBeforeConditions.

@Test
void providedConditionsComeBeforeConditions() throws NoSuchMethodException {
    @PluginInfo(name = "Extension")
    class Extension implements DataExtension {

        @Conditional("condition")
        @StringProvider(text = "a")
        public String value() {
            return "";
        }
    }
    ExtDataBuilder builder = new ExtDataBuilder(new Extension());
    DataValue<Boolean> first = builder.valueBuilder("test").buildBooleanProvidingCondition(false, "condition");
    DataValue<Boolean> second = builder.valueBuilder("test").conditional(Extension.class.getMethod("value").getAnnotation(Conditional.class)).buildBoolean(false);
    builder.addValue(Boolean.class, second);
    builder.addValue(Boolean.class, first);
    List<ExtDataBuilder.ClassValuePair> expected = Arrays.asList(new ExtDataBuilder.ClassValuePair(Boolean.class, first), new ExtDataBuilder.ClassValuePair(Boolean.class, second));
    List<ExtDataBuilder.ClassValuePair> result = builder.getValues();
    assertEquals(expected, result);
}
Also used : DataExtension(com.djrapitops.plan.extension.DataExtension) DataExtension(com.djrapitops.plan.extension.DataExtension) PluginInfo(com.djrapitops.plan.extension.annotation.PluginInfo) Test(org.junit.jupiter.api.Test)

Aggregations

DataExtension (com.djrapitops.plan.extension.DataExtension)35 Test (org.junit.jupiter.api.Test)35 PluginInfo (com.djrapitops.plan.extension.annotation.PluginInfo)4