diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2020-04-21 15:30:35 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2020-04-21 15:30:35 +0300 |
commit | ec03fd022f032abc1669d0ff485c60db5ad1b5c3 (patch) | |
tree | c93c22ed5a7d06f173dc8be79c666f608a70433a /pf4j/src/test | |
parent | 42bb7976de80ac8711f62d2278c234c240987b85 (diff) | |
download | pf4j-ec03fd022f032abc1669d0ff485c60db5ad1b5c3.tar.gz pf4j-ec03fd022f032abc1669d0ff485c60db5ad1b5c3.zip |
Fix #363
Diffstat (limited to 'pf4j/src/test')
-rw-r--r-- | pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java | 17 | ||||
-rw-r--r-- | pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java | 21 |
2 files changed, 38 insertions, 0 deletions
diff --git a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java index 74ccadb..bcf1535 100644 --- a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java @@ -37,6 +37,7 @@ import java.util.Set; import static com.google.testing.compile.CompilationSubject.assertThat; import static com.google.testing.compile.Compiler.javac; +import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.eq; @@ -217,6 +218,22 @@ public class AbstractExtensionFinderTest { assertNotNull(extension); } + @Test + public void findExtensionAnnotationThatMissing() throws Exception { + Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting, + ExtensionAnnotationProcessorTest.SpinnakerExtension_NoExtension, + ExtensionAnnotationProcessorTest.WhazzupGreeting_SpinnakerExtension); + assertThat(compilation).succeededWithoutWarnings(); + ImmutableList<JavaFileObject> generatedFiles = compilation.generatedFiles(); + assertEquals(3, generatedFiles.size()); + + JavaFileObjectClassLoader classLoader = new JavaFileObjectClassLoader(); + Map<String, Class<?>> loadedClasses = classLoader.loadClasses(new ArrayList<>(generatedFiles)); + Class<?> clazz = loadedClasses.get("test.WhazzupGreeting"); + Extension extension = AbstractExtensionFinder.findExtensionAnnotation(clazz); + assertNull(extension); + } + static class JavaFileObjectClassLoader extends ClassLoader { public Map<String, Class<?>> loadClasses(List<JavaFileObject> classes) throws IOException { diff --git a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java index 652c754..f966523 100644 --- a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java +++ b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java @@ -103,6 +103,27 @@ public class ExtensionAnnotationProcessorTest { " }", "}"); + /** + * The same like {@link #SpinnakerExtension} but without {@code Extension} annotation. + */ + public static final JavaFileObject SpinnakerExtension_NoExtension = 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 {", + "}"); + @Test public void getSupportedAnnotationTypes() { ExtensionAnnotationProcessor instance = new ExtensionAnnotationProcessor(); |