diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2019-11-15 17:53:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-15 17:53:51 +0200 |
commit | 84461f0f6ec8471bb5d6c226e6e259815effe564 (patch) | |
tree | 10c6224a2f15ce6073b235aa2cbccec1d9f01b2d /pf4j/src/test | |
parent | a7bf2eb382c8a8be74f71bca1c44686929535114 (diff) | |
download | pf4j-84461f0f6ec8471bb5d6c226e6e259815effe564.tar.gz pf4j-84461f0f6ec8471bb5d6c226e6e259815effe564.zip |
Found extensions when using decorated annotations (#348)
Diffstat (limited to 'pf4j/src/test')
-rw-r--r-- | pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java index 1556472..4f8dd2e 100644 --- a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java +++ b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java @@ -60,7 +60,7 @@ public class ExtensionAnnotationProcessorTest { " }", "}"); - private static final JavaFileObject WhazzupGreeting_No_ExtensionPoint = JavaFileObjects.forSourceLines( + private static final JavaFileObject WhazzupGreeting_NoExtensionPoint = JavaFileObjects.forSourceLines( "WhazzupGreeting", "package test;", "import org.pf4j.Extension;", @@ -73,12 +73,42 @@ public class ExtensionAnnotationProcessorTest { " }", "}"); + private static final JavaFileObject SpinnakerExtension = JavaFileObjects.forSourceLines( + "SpinnakerExtension", + "package test;", + "", + "import org.pf4j.Extension;", + "import java.lang.annotation.Documented;", + "import java.lang.annotation.ElementType;", + "import java.lang.annotation.Retention;", + "import java.lang.annotation.RetentionPolicy;", + "import java.lang.annotation.Target;", + "", + "@Extension", + "@Retention(RetentionPolicy.RUNTIME)", + "@Target(ElementType.TYPE)", + "@Documented", + "public @interface SpinnakerExtension {", + "}"); + + private static final JavaFileObject WhazzupGreeting_SpinnakerExtension = JavaFileObjects.forSourceLines( + "WhazzupGreeting", + "package test;", + "", + "@SpinnakerExtension", + "public class WhazzupGreeting implements Greeting {", + " @Override", + " public String getGreeting() {", + " return \"Whazzup\";", + " }", + "}"); + @Test public void getSupportedAnnotationTypes() { ExtensionAnnotationProcessor instance = new ExtensionAnnotationProcessor(); Set<String> result = instance.getSupportedAnnotationTypes(); assertEquals(1, result.size()); - assertEquals(Extension.class.getName(), result.iterator().next()); + assertEquals("*", result.iterator().next()); } @Test @@ -118,10 +148,10 @@ public class ExtensionAnnotationProcessorTest { @Test public void compileWithError() { ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor(); - Compilation compilation = javac().withProcessors(processor).compile(Greeting, WhazzupGreeting_No_ExtensionPoint); + Compilation compilation = javac().withProcessors(processor).compile(Greeting, WhazzupGreeting_NoExtensionPoint); assertThat(compilation).failed(); assertThat(compilation).hadErrorContaining("it doesn't implement ExtensionPoint") - .inFile(WhazzupGreeting_No_ExtensionPoint) + .inFile(WhazzupGreeting_NoExtensionPoint) .onLine(5) .atColumn(8); } @@ -136,4 +166,14 @@ public class ExtensionAnnotationProcessorTest { assertEquals(extensions, processor.getExtensions()); } + @Test + public void compileNestedExtensionAnnotation() { + ExtensionAnnotationProcessor processor = new ExtensionAnnotationProcessor(); + Compilation compilation = javac().withProcessors(processor).compile(Greeting, SpinnakerExtension, WhazzupGreeting_SpinnakerExtension); + assertThat(compilation).succeededWithoutWarnings(); + Map<String, Set<String>> extensions = new HashMap<>(); + extensions.put("test.Greeting", new HashSet<>(Collections.singletonList("test.WhazzupGreeting"))); + assertEquals(extensions, processor.getExtensions()); + } + } |