Search in sources :

Example 16 with DataExtension

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

the class ExtensionExtractorTest method methodsAreExtracted2.

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

        @Conditional("hasJoined")
        @NumberProvider(text = "Test")
        public long method() {
            return 0;
        }
    }
    Extension extension = new Extension();
    ExtensionExtractor underTest = new ExtensionExtractor(extension);
    Map<ExtensionMethod.ParameterType, ExtensionMethods> result = underTest.getMethods();
    Map<ExtensionMethod.ParameterType, ExtensionMethods> expected = buildExpectedExtensionMethodMap(extension, ExtensionMethods::addNumberMethod);
    assertEquals(expected, result);
}
Also used : DataExtension(com.djrapitops.plan.extension.DataExtension) DataExtension(com.djrapitops.plan.extension.DataExtension) Test(org.junit.jupiter.api.Test)

Example 17 with DataExtension

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

the class ExtensionExtractorTest method publicProviderMethodsAreRequired.

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

        @BooleanProvider(text = "Banned")
        private boolean method(UUID playerUUID) {
            return false;
        }
    }
    ExtensionExtractor underTest = new ExtensionExtractor(new Extension());
    assertEquals("Extension class had no methods annotated with a Provider annotation", 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 18 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 19 with DataExtension

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

the class ExtensionExtractorTest method textOver50CharsIsWarnedAbout.

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

        @StringProvider(text = "aaaaaAAAAAbbbbbBBBBBcccccCCCCCdddddDDDDDeeeeeEEEEEfffffFFFF")
        public String method() {
            return "example";
        }
    }
    Extension extension = new Extension();
    ExtensionExtractor underTest = new ExtensionExtractor(extension);
    assertEquals("Warnings: [Extension.method 'text' was over 50 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 20 with DataExtension

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

the class ExtensionExtractorTest method dataBuilderProviderMustProvideDataBuilder.

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

        @DataBuilderProvider
        public Group method(UUID playerUUID) {
            return null;
        }
    }
    ExtensionExtractor underTest = new ExtensionExtractor(new Extension());
    assertEquals("Extension.method has invalid return type. was: com.djrapitops.plan.extension.Group, expected: com.djrapitops.plan.extension.builder.ExtensionDataBuilder", 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)

Aggregations

DataExtension (com.djrapitops.plan.extension.DataExtension)35 Test (org.junit.jupiter.api.Test)35 PluginInfo (com.djrapitops.plan.extension.annotation.PluginInfo)4 Group (com.djrapitops.plan.extension.Group)1 com.djrapitops.plan.extension.annotation (com.djrapitops.plan.extension.annotation)1 ExtensionDataBuilder (com.djrapitops.plan.extension.builder.ExtensionDataBuilder)1 Table (com.djrapitops.plan.extension.table.Table)1 java.util (java.util)1 BiConsumer (java.util.function.BiConsumer)1 Stream (java.util.stream.Stream)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1