aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j/src/test/java/org
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2024-06-23 13:17:41 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2024-06-23 13:17:41 +0300
commitf1620f7f8aac25eda45d4a4084cefb015bd8c47a (patch)
treecdc3dff881b5edf947dc315deeacfe5258bd6972 /pf4j/src/test/java/org
parent1a16be8ad024d3c5fac380ec819bf6e17644c375 (diff)
downloadpf4j-#576.tar.gz
pf4j-#576.zip
Don't force resolve dependencies when unload a transitive plugin#576
Diffstat (limited to 'pf4j/src/test/java/org')
-rw-r--r--pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java47
1 files changed, 42 insertions, 5 deletions
diff --git a/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java b/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java
index 07a083b..88be865 100644
--- a/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java
+++ b/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java
@@ -36,6 +36,8 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
@@ -49,7 +51,7 @@ public class AbstractPluginManagerTest {
@BeforeEach
void setUp() {
- pluginManager = mock(AbstractPluginManager.class, withSettings()
+ pluginManager = mock(AbstractPluginManagerWithDefaultVersionManager.class, withSettings()
.useConstructor()
.defaultAnswer(CALLS_REAL_METHODS));
}
@@ -119,11 +121,33 @@ public class AbstractPluginManagerTest {
assertThrows(PluginNotFoundException.class, () -> pluginManager.checkPluginId("plugin1"));
}
- private PluginWrapper createPluginWrapper(String pluginId) {
- DefaultPluginDescriptor pluginDescriptor = new DefaultPluginDescriptor();
- pluginDescriptor.setPluginId(pluginId);
- pluginDescriptor.setPluginVersion("1.2.3");
+ @Test
+ void unloadPluginCallsResolveDependenciesOnce() {
+ PluginWrapper pluginWrapper1 = createPluginWrapper("plugin1", "plugin2");
+ PluginWrapper pluginWrapper2 = createPluginWrapper("plugin2");
+
+ pluginManager.addPlugin(pluginWrapper1);
+ pluginManager.addPlugin(pluginWrapper2);
+ pluginManager.resolveDependencies();
+
+ // reset the mock to not count the explicit call of resolveDependencies
+ reset(pluginManager);
+
+ pluginManager.unloadPlugin("plugin2", true);
+
+ verify(pluginManager, times(1)).resolveDependencies();
+ }
+
+ private PluginWrapper createPluginWrapper(String pluginId, String... dependencies) {
+ PluginDescriptor pluginDescriptor = new DefaultPluginDescriptor()
+ .setPluginId(pluginId)
+ .setPluginVersion("1.2.3")
+ .setDependencies(String.join(", ", dependencies));
+ return createPluginWrapper(pluginDescriptor);
+ }
+
+ private PluginWrapper createPluginWrapper(PluginDescriptor pluginDescriptor) {
PluginWrapper pluginWrapper = new PluginWrapper(pluginManager, pluginDescriptor, Paths.get("plugin1"), getClass().getClassLoader());
Plugin plugin = mock(Plugin.class);
pluginWrapper.setPluginFactory(wrapper -> plugin);
@@ -131,4 +155,17 @@ public class AbstractPluginManagerTest {
return pluginWrapper;
}
+ static abstract class AbstractPluginManagerWithDefaultVersionManager extends AbstractPluginManager {
+
+ public AbstractPluginManagerWithDefaultVersionManager() {
+ super();
+ }
+
+ @Override
+ protected VersionManager createVersionManager() {
+ return new DefaultVersionManager();
+ }
+
+ }
+
}