diff options
author | ahaha-vip <48004552+ahaha-vip@users.noreply.github.com> | 2021-03-24 16:46:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-24 10:46:39 +0200 |
commit | 4e3d2fa1422cbbaf212f01fb171130fb082b4d95 (patch) | |
tree | a0806828031827b12a43bc16942c82b16737b2d1 | |
parent | ff02462c9d8c208a8ddff13b3fb6e94e017a21da (diff) | |
download | pf4j-4e3d2fa1422cbbaf212f01fb171130fb082b4d95.tar.gz pf4j-4e3d2fa1422cbbaf212f01fb171130fb082b4d95.zip |
Add a unit test in AbstractExtensionFinderTest to reproduce #428 (#430)
-rw-r--r-- | pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java | 9 | ||||
-rw-r--r-- | pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java | 40 |
2 files changed, 47 insertions, 2 deletions
diff --git a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java index a156fab..42d59ae 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java @@ -83,7 +83,7 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin // classpath's extensions <=> pluginId = null Set<String> classNames = findClassNames(pluginId); - if (classNames == null || classNames.isEmpty()) { + if (classNames.isEmpty()) { return result; } @@ -218,7 +218,12 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin @Override public Set<String> findClassNames(String pluginId) { - return getEntries().get(pluginId); + Set<String> classNames = getEntries().get(pluginId); + if (classNames == null) { + return Collections.emptySet(); + } + + return classNames; } @Override diff --git a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java index 83796ab..eff6ebe 100644 --- a/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.io.ByteStreams; import com.google.testing.compile.Compilation; import java.util.Comparator; +import java.util.UUID; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -204,6 +205,45 @@ public class AbstractExtensionFinderTest { assertEquals(1, result.size()); } + /** + * Test of {@link org.pf4j.AbstractExtensionFinder#find(java.lang.String)}. + */ + @Test + public void testFindExtensionWrappersFromPluginId() { + ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) { + + @Override + public Map<String, Set<String>> readPluginsStorages() { + Map<String, Set<String>> entries = new LinkedHashMap<>(); + + Set<String> bucket = new HashSet<>(); + bucket.add("org.pf4j.test.TestExtension"); + bucket.add("org.pf4j.test.FailTestExtension"); + entries.put("plugin1", bucket); + bucket = new HashSet<>(); + bucket.add("org.pf4j.test.TestExtension"); + entries.put("plugin2", bucket); + + return entries; + } + + @Override + public Map<String, Set<String>> readClasspathStorages() { + return Collections.emptyMap(); + } + + }; + + List<ExtensionWrapper> plugin1Result = instance.find("plugin1"); + assertEquals(2, plugin1Result.size()); + + List<ExtensionWrapper> plugin2Result = instance.find("plugin2"); + assertEquals(0, plugin2Result.size()); + + List<ExtensionWrapper> plugin3Result = instance.find(UUID.randomUUID().toString()); + assertEquals(0, plugin3Result.size()); + } + @Test public void findExtensionAnnotation() throws Exception { Compilation compilation = javac().compile(ExtensionAnnotationProcessorTest.Greeting, |