aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j/src/test
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2023-01-30 20:36:47 +0200
committerGitHub <noreply@github.com>2023-01-30 20:36:47 +0200
commit1f04209be1769e40c730cf2701926611e2f85435 (patch)
treed824ef5c8dd93264a4b99ed9bf3704540d73ce76 /pf4j/src/test
parentde63736b13a71c227c1dec95e8e39c95a3962870 (diff)
downloadpf4j-1f04209be1769e40c730cf2701926611e2f85435.tar.gz
pf4j-1f04209be1769e40c730cf2701926611e2f85435.zip
Relax Plugin construction (remove dependency on PluginWrapper) (#512)
Diffstat (limited to 'pf4j/src/test')
-rw-r--r--pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java17
-rw-r--r--pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java2
-rw-r--r--pf4j/src/test/java/org/pf4j/test/AnotherTestPlugin.java34
3 files changed, 52 insertions, 1 deletions
diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
index 3107083..c453e38 100644
--- a/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
+++ b/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
@@ -17,6 +17,7 @@ package org.pf4j;
import org.junit.jupiter.api.Test;
import org.pf4j.test.AnotherFailTestPlugin;
+import org.pf4j.test.AnotherTestPlugin;
import org.pf4j.test.FailTestPlugin;
import org.pf4j.test.TestPlugin;
@@ -49,6 +50,22 @@ public class DefaultPluginFactoryTest {
}
@Test
+ public void pluginConstructorNoParameters() {
+ PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
+ when(pluginDescriptor.getPluginClass()).thenReturn(AnotherTestPlugin.class.getName());
+
+ PluginWrapper pluginWrapper = mock(PluginWrapper.class);
+ when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
+ when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
+
+ PluginFactory pluginFactory = new DefaultPluginFactory();
+
+ Plugin result = pluginFactory.create(pluginWrapper);
+ assertNotNull(result);
+ assertThat(result, instanceOf(AnotherTestPlugin.class));
+ }
+
+ @Test
public void testCreateFail() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
when(pluginDescriptor.getPluginClass()).thenReturn(FailTestPlugin.class.getName());
diff --git a/pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java b/pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java
index d97b32c..79aa41b 100644
--- a/pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java
+++ b/pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java
@@ -19,7 +19,7 @@ import org.pf4j.Plugin;
/**
* A wrong {@link org.pf4j.Plugin}.
- * It's wrong because it doesn't contain a constructor with one parameter ({@link org.pf4j.PluginWrapper} as parameter type).
+ * It's wrong because it calls super constructor with {@code null} for ({@link org.pf4j.PluginWrapper} parameter).
*
* @author Mario Franco
*/
diff --git a/pf4j/src/test/java/org/pf4j/test/AnotherTestPlugin.java b/pf4j/src/test/java/org/pf4j/test/AnotherTestPlugin.java
new file mode 100644
index 0000000..f2e10c1
--- /dev/null
+++ b/pf4j/src/test/java/org/pf4j/test/AnotherTestPlugin.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012-present the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.pf4j.test;
+
+import org.pf4j.Plugin;
+
+/**
+ * A simple {@link Plugin}.
+ *
+ * In real applications you don't need to create a plugin like this if you are not interested in lifecycle events.
+ * {@code PF4J} will automatically create a plugin similar to this (empty / dummy) if no class plugin is specified.
+ *
+ * @author Decebal Suiu
+ */
+public class AnotherTestPlugin extends Plugin {
+
+ public AnotherTestPlugin() {
+ super();
+ }
+
+}