From: Decebal Suiu Date: Tue, 21 Apr 2020 11:16:14 +0000 (+0300) Subject: Revert "Add test for findExtensionAnnotation (preparation for #363)" X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2d48162fbefe18ab048e3c85e9753fa4b0171164;p=pf4j.git Revert "Add test for findExtensionAnnotation (preparation for #363)" This reverts commit 1715cb3d --- diff --git a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java index 903e2cb..3cfbc7e 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java @@ -348,7 +348,7 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin return new ExtensionWrapper<>(descriptor, pluginManager.getExtensionFactory()); } - public static Extension findExtensionAnnotation(Class clazz) { + private Extension findExtensionAnnotation(Class clazz) { if (clazz.isAnnotationPresent(Extension.class)) { return clazz.getAnnotation(Extension.class); } diff --git a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java index 74ccadb..6383756 100644 --- a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java @@ -15,30 +15,20 @@ */ package org.pf4j; -import com.google.common.collect.ImmutableList; -import com.google.common.io.ByteStreams; -import com.google.testing.compile.Compilation; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.pf4j.plugin.FailTestPlugin; import org.pf4j.plugin.TestExtensionPoint; -import javax.tools.JavaFileObject; -import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; -import static com.google.testing.compile.CompilationSubject.assertThat; -import static com.google.testing.compile.Compiler.javac; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -202,48 +192,4 @@ public class AbstractExtensionFinderTest { assertEquals(1, result.size()); } - @Test - public void findExtensionAnnotation() throws Exception { - Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting, - ExtensionAnnotationProcessorTest.WhazzupGreeting); - assertThat(compilation).succeededWithoutWarnings(); - ImmutableList generatedFiles = compilation.generatedFiles(); - assertEquals(2, generatedFiles.size()); - - JavaFileObjectClassLoader classLoader = new JavaFileObjectClassLoader(); - Map> loadedClasses = classLoader.loadClasses(new ArrayList<>(generatedFiles)); - Class clazz = loadedClasses.get("test.WhazzupGreeting"); - Extension extension = AbstractExtensionFinder.findExtensionAnnotation(clazz); - assertNotNull(extension); - } - - static class JavaFileObjectClassLoader extends ClassLoader { - - public Map> loadClasses(List classes) throws IOException { - // Sort generated ".class" by lastModified field - classes.sort((c1, c2) -> (int) (c1.getLastModified() - c2.getLastModified())); - - // Load classes - Map> loadedClasses = new HashMap<>(classes.size()); - for (JavaFileObject clazz : classes) { - String className = getClassName(clazz); - byte[] data = ByteStreams.toByteArray(clazz.openInputStream()); - Class loadedClass = defineClass(className, data,0, data.length); - loadedClasses.put(className, loadedClass); - } - - return loadedClasses; - } - - private static String getClassName(JavaFileObject object) { - String name = object.getName(); - // Remove "/CLASS_OUT/" from head and ".class" from tail - name = name.substring(14, name.length() - 6); - name = name.replace('/', '.'); - - return name; - } - - } - } diff --git a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java index 1dc8f60..11467c8 100644 --- a/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java +++ b/pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java @@ -38,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ public class ExtensionAnnotationProcessorTest { - public static final JavaFileObject Greeting = JavaFileObjects.forSourceLines( + private static final JavaFileObject Greeting = JavaFileObjects.forSourceLines( "Greeting", "package test;", "import org.pf4j.ExtensionPoint;", @@ -47,7 +47,7 @@ public class ExtensionAnnotationProcessorTest { " String getGreeting();", "}"); - public static final JavaFileObject WhazzupGreeting = JavaFileObjects.forSourceLines( + private static final JavaFileObject WhazzupGreeting = JavaFileObjects.forSourceLines( "WhazzupGreeting", "package test;", "import org.pf4j.Extension;", @@ -60,7 +60,7 @@ public class ExtensionAnnotationProcessorTest { " }", "}"); - public static final JavaFileObject WhazzupGreeting_NoExtensionPoint = JavaFileObjects.forSourceLines( + private static final JavaFileObject WhazzupGreeting_NoExtensionPoint = JavaFileObjects.forSourceLines( "WhazzupGreeting", "package test;", "import org.pf4j.Extension;", @@ -73,7 +73,7 @@ public class ExtensionAnnotationProcessorTest { " }", "}"); - public static final JavaFileObject SpinnakerExtension = JavaFileObjects.forSourceLines( + private static final JavaFileObject SpinnakerExtension = JavaFileObjects.forSourceLines( "SpinnakerExtension", "package test;", "", @@ -91,7 +91,7 @@ public class ExtensionAnnotationProcessorTest { "public @interface SpinnakerExtension {", "}"); - public static final JavaFileObject WhazzupGreeting_SpinnakerExtension = JavaFileObjects.forSourceLines( + private static final JavaFileObject WhazzupGreeting_SpinnakerExtension = JavaFileObjects.forSourceLines( "WhazzupGreeting", "package test;", "",