Browse Source

Migrate to JUnit 5

pull/305/head
Decebal Suiu 6 years ago
parent
commit
e1fb3f7bc4
  1. 5
      pf4j/pom.xml
  2. 12
      pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java
  3. 30
      pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
  4. 7
      pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java
  5. 8
      pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
  6. 42
      pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java
  7. 42
      pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
  8. 30
      pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
  9. 18
      pf4j/src/test/java/org/pf4j/DefaultVersionManagerTest.java
  10. 10
      pf4j/src/test/java/org/pf4j/DependencyResolverTest.java
  11. 6
      pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java
  12. 4
      pf4j/src/test/java/org/pf4j/LegacyExtensionStorageTest.java
  13. 79
      pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
  14. 39
      pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java
  15. 19
      pf4j/src/test/java/org/pf4j/PluginDependencyTest.java
  16. 42
      pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java
  17. 5
      pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java
  18. 19
      pf4j/src/test/java/org/pf4j/plugin/PluginZip.java
  19. 4
      pf4j/src/test/java/org/pf4j/processor/ServiceProviderExtensionStorageTest.java
  20. 18
      pf4j/src/test/java/org/pf4j/util/FileUtilsTest.java
  21. 2
      pom.xml

5
pf4j/pom.xml

@ -100,11 +100,12 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version> <version>${junit.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

12
pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java

@ -15,9 +15,9 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.pf4j.plugin.FailTestPlugin; import org.pf4j.plugin.FailTestPlugin;
import org.pf4j.plugin.TestExtensionPoint; import org.pf4j.plugin.TestExtensionPoint;
@ -28,7 +28,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -40,7 +40,7 @@ public class AbstractExtensionFinderTest {
private PluginManager pluginManager; private PluginManager pluginManager;
@Before @BeforeEach
public void setUp() { public void setUp() {
PluginWrapper pluginStarted = mock(PluginWrapper.class); PluginWrapper pluginStarted = mock(PluginWrapper.class);
when(pluginStarted.getPluginClassLoader()).thenReturn(getClass().getClassLoader()); when(pluginStarted.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
@ -57,7 +57,7 @@ public class AbstractExtensionFinderTest {
when(pluginManager.getExtensionFactory()).thenReturn(new DefaultExtensionFactory()); when(pluginManager.getExtensionFactory()).thenReturn(new DefaultExtensionFactory());
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
pluginManager = null; pluginManager = null;
} }

30
pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java

@ -15,28 +15,27 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import org.pf4j.plugin.PluginZip; import org.pf4j.plugin.PluginZip;
import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* @author Decebal Suiu * @author Decebal Suiu
*/ */
public class CompoundPluginDescriptorFinderTest { public class CompoundPluginDescriptorFinderTest {
@Rule @TempDir
public TemporaryFolder pluginsFolder = new TemporaryFolder(); Path pluginsPath;
@Test @Test
public void add() { public void add() {
@ -49,7 +48,8 @@ public class CompoundPluginDescriptorFinderTest {
@Test @Test
public void find() throws Exception { public void find() throws Exception {
Path pluginPath = pluginsFolder.newFolder("test-plugin-1").toPath(); Path pluginPath = pluginsPath.resolve("test-plugin-1");
Files.createDirectories(pluginPath);
Files.write(pluginPath.resolve("plugin.properties"), getPlugin1Properties(), StandardCharsets.UTF_8); Files.write(pluginPath.resolve("plugin.properties"), getPlugin1Properties(), StandardCharsets.UTF_8);
PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder() PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
@ -66,7 +66,7 @@ public class CompoundPluginDescriptorFinderTest {
PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder() PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
.add(new PropertiesPluginDescriptorFinder()); .add(new PropertiesPluginDescriptorFinder());
PluginZip pluginJar = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.jar"), "myPlugin") PluginZip pluginJar = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.jar"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();
@ -76,19 +76,17 @@ public class CompoundPluginDescriptorFinderTest {
assertEquals("1.2.3", pluginJar.pluginVersion()); assertEquals("1.2.3", pluginJar.pluginVersion());
} }
@Test(expected = PluginException.class) @Test
public void testNotFound() throws Exception { public void testNotFound() {
PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder(); PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder();
Path pluginsPath = pluginsFolder.getRoot().toPath(); assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
descriptorFinder.find(pluginsPath.resolve("test-plugin-3"));
} }
@Test @Test
public void testSpaceCharacterInFileName() throws Exception { public void testSpaceCharacterInFileName() throws Exception {
PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder(); PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
File jar = pluginsFolder.newFile("my plugin-1.2.3.jar");
PluginZip pluginJar = new PluginZip.Builder(jar, "myPlugin") PluginZip pluginJar = new PluginZip.Builder(pluginsPath.resolve("my plugin-1.2.3.jar"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();

7
pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java

@ -15,11 +15,12 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.pf4j.plugin.TestExtension;
import org.pf4j.plugin.FailTestExtension; import org.pf4j.plugin.FailTestExtension;
import org.pf4j.plugin.TestExtension;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/** /**
* *

8
pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java

@ -15,15 +15,15 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.pf4j.plugin.AnotherFailTestPlugin; import org.pf4j.plugin.AnotherFailTestPlugin;
import org.pf4j.plugin.FailTestPlugin; import org.pf4j.plugin.FailTestPlugin;
import org.pf4j.plugin.TestPlugin; import org.pf4j.plugin.TestPlugin;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertNotNull; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

42
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java

@ -15,21 +15,21 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import org.pf4j.plugin.PluginZip; import org.pf4j.plugin.PluginZip;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -38,14 +38,12 @@ public class DefaultPluginManagerTest {
private DefaultPluginManager pluginManager; private DefaultPluginManager pluginManager;
private DefaultPluginDescriptor pluginDescriptor; private DefaultPluginDescriptor pluginDescriptor;
private PluginWrapper pluginWrapper; private PluginWrapper pluginWrapper;
private Path pluginsPath;
@Rule @TempDir
public TemporaryFolder pluginsFolder = new TemporaryFolder(); Path pluginsPath;
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
pluginsPath = pluginsFolder.getRoot().toPath();
pluginManager = new DefaultPluginManager(pluginsPath); pluginManager = new DefaultPluginManager(pluginsPath);
pluginDescriptor = new DefaultPluginDescriptor(); pluginDescriptor = new DefaultPluginDescriptor();
@ -59,7 +57,7 @@ public class DefaultPluginManagerTest {
pluginWrapper = new PluginWrapper(pluginManager, pluginDescriptor, Files.createTempDirectory("test"), getClass().getClassLoader()); pluginWrapper = new PluginWrapper(pluginManager, pluginDescriptor, Files.createTempDirectory("test"), getClass().getClassLoader());
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
pluginManager = null; pluginManager = null;
pluginDescriptor = null; pluginDescriptor = null;
@ -71,16 +69,16 @@ public class DefaultPluginManagerTest {
pluginManager.validatePluginDescriptor(pluginDescriptor); pluginManager.validatePluginDescriptor(pluginDescriptor);
} }
@Test(expected = PluginException.class) @Test
public void validateFailsOnId() throws PluginException { public void validateFailsOnId() {
pluginDescriptor.setPluginId(""); pluginDescriptor.setPluginId("");
pluginManager.validatePluginDescriptor(pluginDescriptor); assertThrows(PluginException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor));
} }
@Test(expected = PluginException.class) @Test
public void validateFailsOnVersion() throws PluginException { public void validateFailsOnVersion() {
pluginDescriptor.setPluginVersion(null); pluginDescriptor.setPluginVersion(null);
pluginManager.validatePluginDescriptor(pluginDescriptor); assertThrows(PluginException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor));
} }
@Test @Test
@ -132,7 +130,7 @@ public class DefaultPluginManagerTest {
*/ */
@Test @Test
public void testPluginDisabledNoStart() throws IOException { public void testPluginDisabledNoStart() throws IOException {
new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin") new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();

42
pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java

@ -15,20 +15,18 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Mario Franco * @author Mario Franco
@ -36,25 +34,21 @@ import static org.junit.Assert.assertTrue;
*/ */
public class DefaultPluginRepositoryTest { public class DefaultPluginRepositoryTest {
private Path pluginsPath; @TempDir
Path pluginsPath;
@Rule @BeforeEach
public TemporaryFolder pluginsFolder = new TemporaryFolder();
@Before
public void setUp() throws IOException { public void setUp() throws IOException {
pluginsPath = pluginsFolder.getRoot().toPath(); Path plugin1Path = Files.createDirectories(pluginsPath.resolve("plugin-1"));
pluginsFolder.newFolder("plugin-1");
// Prove that we can delete a folder with a file inside // Prove that we can delete a folder with a file inside
Files.createFile(Paths.get(pluginsFolder.getRoot().getAbsolutePath()).resolve("plugin-1").resolve("myfile")); Files.createFile(plugin1Path.resolve("myfile"));
// Create a zip file for plugin-1 to test that it is deleted when plugin is deleted // Create a zip file for plugin-1 to test that it is deleted when plugin is deleted
Files.createFile(Paths.get(pluginsFolder.getRoot().getAbsolutePath()).resolve("plugin-1.zip")); Files.createFile(pluginsPath.resolve("plugin-1.zip"));
pluginsFolder.newFolder("plugin-2"); Files.createDirectories(pluginsPath.resolve("plugin-2"));
pluginsFolder.newFolder("plugin-3"); Files.createDirectories(pluginsPath.resolve("plugin-3"));
// standard maven/gradle bin folder - these should be skipped in development mode because the cause errors // standard maven/gradle bin folder - these should be skipped in development mode because the cause errors
pluginsFolder.newFolder("target"); Files.createDirectories(pluginsPath.resolve("target"));
pluginsFolder.newFolder("build"); Files.createDirectories(pluginsPath.resolve("build"));
} }
/** /**
@ -109,11 +103,11 @@ public class DefaultPluginRepositoryTest {
} }
private void assertPathExists(List<Path> paths, Path path) { private void assertPathExists(List<Path> paths, Path path) {
assertTrue("The directory must contain the file " + path, paths.contains(path)); assertTrue(paths.contains(path), "The directory must contain the file " + path);
} }
private void assertPathDoesNotExists(List<Path> paths, Path path) { private void assertPathDoesNotExists(List<Path> paths, Path path) {
assertFalse("The directory must not contain the file " + path, paths.contains(path)); assertFalse(paths.contains(path), "The directory must not contain the file " + path);
} }
} }

30
pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java

@ -15,20 +15,17 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Rule; import org.junit.jupiter.api.io.TempDir;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.pf4j.util.FileUtils; import org.pf4j.util.FileUtils;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Mario Franco * @author Mario Franco
@ -36,15 +33,8 @@ import static org.junit.Assert.assertTrue;
*/ */
public class DefaultPluginStatusProviderTest { public class DefaultPluginStatusProviderTest {
private Path pluginsPath; @TempDir
Path pluginsPath;
@Rule
public TemporaryFolder pluginsFolder = new TemporaryFolder();
@Before
public void setUp() {
pluginsPath = pluginsFolder.getRoot().toPath();
}
@Test @Test
public void testIsPluginDisabled() throws IOException { public void testIsPluginDisabled() throws IOException {
@ -129,8 +119,8 @@ public class DefaultPluginStatusProviderTest {
List<String> disabledPlugins = new ArrayList<>(); List<String> disabledPlugins = new ArrayList<>();
disabledPlugins.add("plugin-2"); disabledPlugins.add("plugin-2");
File disabledFile = pluginsFolder.newFile("disabled.txt"); Path disabledPath = pluginsPath.resolve("disabled.txt");
FileUtils.writeLines(disabledPlugins, disabledFile); FileUtils.writeLines(disabledPlugins, disabledPath.toFile());
} }
private void createEnabledFile() throws IOException { private void createEnabledFile() throws IOException {
@ -138,8 +128,8 @@ public class DefaultPluginStatusProviderTest {
enabledPlugins.add("plugin-1"); enabledPlugins.add("plugin-1");
enabledPlugins.add("plugin-2"); enabledPlugins.add("plugin-2");
File enabledFile = pluginsFolder.newFile("enabled.txt"); Path enabledPath = pluginsPath.resolve("enabled.txt");
FileUtils.writeLines(enabledPlugins, enabledFile); FileUtils.writeLines(enabledPlugins, enabledPath.toFile());
} }
} }

18
pf4j/src/test/java/org/pf4j/DefaultVersionManagerTest.java

@ -16,10 +16,12 @@
package org.pf4j; package org.pf4j;
import com.github.zafarkhaja.semver.ParseException; import com.github.zafarkhaja.semver.ParseException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Decebal Suiu * @author Decebal Suiu
@ -28,7 +30,7 @@ public class DefaultVersionManagerTest {
private VersionManager versionManager; private VersionManager versionManager;
@Before @BeforeEach
public void init() { public void init() {
versionManager = new DefaultVersionManager(); versionManager = new DefaultVersionManager();
} }
@ -39,14 +41,14 @@ public class DefaultVersionManagerTest {
assertTrue(versionManager.checkVersionConstraint("1.4.3", ">=1.4.0 & <1.6.0")); // range assertTrue(versionManager.checkVersionConstraint("1.4.3", ">=1.4.0 & <1.6.0")); // range
} }
@Test(expected = IllegalArgumentException.class) @Test
public void nullOrEmptyVersion() { public void nullOrEmptyVersion() {
assertFalse(versionManager.checkVersionConstraint(null, ">2.0.0")); assertThrows(IllegalArgumentException.class, () -> versionManager.checkVersionConstraint(null, ">2.0.0"));
} }
@Test(expected = ParseException.class) @Test
public void invalidVersion() { public void invalidVersion() {
assertFalse(versionManager.checkVersionConstraint("1.0", ">2.0.0")); assertThrows(ParseException.class, () -> versionManager.checkVersionConstraint("1.0", ">2.0.0"));
} }
@Test @Test

10
pf4j/src/test/java/org/pf4j/DependencyResolverTest.java

@ -15,14 +15,16 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Decebal Suiu * @author Decebal Suiu
@ -31,7 +33,7 @@ public class DependencyResolverTest {
private DependencyResolver resolver; private DependencyResolver resolver;
@Before @BeforeEach
public void init() { public void init() {
VersionManager versionManager = new DefaultVersionManager(); VersionManager versionManager = new DefaultVersionManager();
resolver = new DependencyResolver(versionManager); resolver = new DependencyResolver(versionManager);

6
pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java

@ -15,13 +15,13 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.pf4j.processor.ExtensionAnnotationProcessor; import org.pf4j.processor.ExtensionAnnotationProcessor;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Mario Franco * @author Mario Franco

4
pf4j/src/test/java/org/pf4j/LegacyExtensionStorageTest.java

@ -15,7 +15,7 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.pf4j.processor.LegacyExtensionStorage; import org.pf4j.processor.LegacyExtensionStorage;
import java.io.IOException; import java.io.IOException;
@ -24,7 +24,7 @@ import java.io.StringReader;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* @author Decebal Suiu * @author Decebal Suiu

79
pf4j/src/test/java/org/pf4j/LoadPluginsTest.java

@ -15,37 +15,37 @@
*/ */
package org.pf4j; package org.pf4j;
import static org.hamcrest.CoreMatchers.containsString; import org.junit.jupiter.api.BeforeEach;
import static org.hamcrest.CoreMatchers.equalTo; import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.startsWith; import org.junit.jupiter.api.io.TempDir;
import static org.junit.Assert.assertEquals; import org.pf4j.plugin.PluginZip;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import org.junit.Before;
import org.junit.Rule; import static org.hamcrest.CoreMatchers.containsString;
import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo;
import org.junit.rules.TemporaryFolder; import static org.hamcrest.CoreMatchers.startsWith;
import org.pf4j.plugin.PluginZip; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class LoadPluginsTest { public class LoadPluginsTest {
private DefaultPluginManager pluginManager; private DefaultPluginManager pluginManager;
@Rule @TempDir
public TemporaryFolder pluginsFolder = new TemporaryFolder(); Path pluginsPath;
@Before @BeforeEach
public void setUp() { public void setUp() {
pluginManager = new DefaultPluginManager(pluginsFolder.getRoot().toPath()) { pluginManager = new DefaultPluginManager(pluginsPath) {
@Override @Override
protected PluginRepository createPluginRepository() { protected PluginRepository createPluginRepository() {
@ -62,7 +62,7 @@ public class LoadPluginsTest {
@Test @Test
public void load() throws Exception { public void load() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin") PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();
@ -76,31 +76,32 @@ public class LoadPluginsTest {
assertEquals(pluginZip.pluginId(), pluginManager.idForPath(pluginZip.unzippedPath())); assertEquals(pluginZip.pluginId(), pluginManager.idForPath(pluginZip.unzippedPath()));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void loadNonExisting() { public void loadNonExisting() {
pluginManager.loadPlugin(Paths.get("nonexisting")); assertThrows(IllegalArgumentException.class, () -> pluginManager.loadPlugin(Paths.get("nonexisting")));
} }
@Test(expected = PluginAlreadyLoadedException.class) @Test
public void loadTwiceFails() throws Exception { public void loadTwiceFails() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin") PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();
assertNotNull(pluginManager.loadPluginFromPath(pluginZip.path())); assertNotNull(pluginManager.loadPluginFromPath(pluginZip.path()));
assertNull(pluginManager.loadPluginFromPath(pluginZip.path()));
assertThrows(PluginAlreadyLoadedException.class, () -> pluginManager.loadPluginFromPath(pluginZip.path()));
} }
@Test @Test
public void loadPluginWithSameIdDifferentPathFails() throws Exception { public void loadPluginWithSameIdDifferentPathFails() throws Exception {
String pluginId = "myPlugin"; String pluginId = "myPlugin";
String pluginVersion = "1.2.3"; String pluginVersion = "1.2.3";
File plugin1Path = pluginsFolder.newFile("my-plugin-1.2.3.zip"); Path plugin1Path = pluginsPath.resolve("my-plugin-1.2.3.zip");
PluginZip plugin1 = new PluginZip.Builder(plugin1Path, pluginId) PluginZip plugin1 = new PluginZip.Builder(plugin1Path, pluginId)
.pluginVersion(pluginVersion) .pluginVersion(pluginVersion)
.build(); .build();
File plugin2Path = pluginsFolder.newFile("my-plugin-1.2.3-renamed.zip"); Path plugin2Path = pluginsPath.resolve("my-plugin-1.2.3-renamed.zip");
PluginZip plugin2 = new PluginZip.Builder(plugin2Path, pluginId) PluginZip plugin2 = new PluginZip.Builder(plugin2Path, pluginId)
.pluginVersion(pluginVersion) .pluginVersion(pluginVersion)
.build(); .build();
@ -134,13 +135,13 @@ public class LoadPluginsTest {
public void loadPluginWithSameIdDifferentVersionsFails() throws Exception { public void loadPluginWithSameIdDifferentVersionsFails() throws Exception {
String pluginId = "myPlugin"; String pluginId = "myPlugin";
String plugin1Version = "1.2.3"; String plugin1Version = "1.2.3";
File plugin1Path = pluginsFolder.newFile("my-plugin-1.2.3.zip"); Path plugin1Path = pluginsPath.resolve("my-plugin-1.2.3.zip");
PluginZip plugin1 = new PluginZip.Builder(plugin1Path, pluginId) PluginZip plugin1 = new PluginZip.Builder(plugin1Path, pluginId)
.pluginVersion(plugin1Version) .pluginVersion(plugin1Version)
.build(); .build();
String plugin2Version = "2.0.0"; String plugin2Version = "2.0.0";
File plugin2Path = pluginsFolder.newFile("my-plugin-2.0.0.zip"); Path plugin2Path = pluginsPath.resolve("my-plugin-2.0.0.zip");
PluginZip plugin2 = new PluginZip.Builder(plugin2Path, pluginId) PluginZip plugin2 = new PluginZip.Builder(plugin2Path, pluginId)
.pluginVersion(plugin2Version) .pluginVersion(plugin2Version)
.build(); .build();
@ -162,7 +163,7 @@ public class LoadPluginsTest {
@Test @Test
public void loadUnloadLoad() throws Exception { public void loadUnloadLoad() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin") PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();
@ -181,7 +182,7 @@ public class LoadPluginsTest {
public void upgrade() throws Exception { public void upgrade() throws Exception {
String pluginId = "myPlugin"; String pluginId = "myPlugin";
new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), pluginId) new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), pluginId)
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();
@ -191,7 +192,7 @@ public class LoadPluginsTest {
assertEquals(1, pluginManager.getPlugins().size()); assertEquals(1, pluginManager.getPlugins().size());
assertEquals(1, pluginManager.getStartedPlugins().size()); assertEquals(1, pluginManager.getStartedPlugins().size());
PluginZip pluginZip2 = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-2.0.0.ZIP"), pluginId) PluginZip pluginZip2 = new PluginZip.Builder(pluginsPath.resolve("my-plugin-2.0.0.ZIP"), pluginId)
.pluginVersion("2.0.0") .pluginVersion("2.0.0")
.build(); .build();
@ -208,12 +209,12 @@ public class LoadPluginsTest {
@Test @Test
public void getRoot() { public void getRoot() {
assertEquals(pluginsFolder.getRoot().toPath(), pluginManager.getPluginsRoot()); assertEquals(pluginsPath, pluginManager.getPluginsRoot());
} }
@Test @Test
public void notAPlugin() throws Exception { public void notAPlugin() {
pluginsFolder.newFile("not-a-zip"); pluginsPath.resolve("not-a-zip");
pluginManager.loadPlugins(); pluginManager.loadPlugins();
@ -222,11 +223,11 @@ public class LoadPluginsTest {
@Test @Test
public void deletePlugin() throws Exception { public void deletePlugin() throws Exception {
PluginZip pluginZip1 = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin") PluginZip pluginZip1 = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();
PluginZip pluginZip3 = new PluginZip.Builder(pluginsFolder.newFile("other-3.0.0.Zip"), "other") PluginZip pluginZip3 = new PluginZip.Builder(pluginsPath.resolve("other-3.0.0.Zip"), "other")
.pluginVersion("3.0.0") .pluginVersion("3.0.0")
.build(); .build();

39
pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java

@ -15,19 +15,21 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Mario Franco * @author Mario Franco
@ -36,40 +38,37 @@ import static org.junit.Assert.*;
public class ManifestPluginDescriptorFinderTest { public class ManifestPluginDescriptorFinderTest {
private VersionManager versionManager; private VersionManager versionManager;
private Path pluginsPath;
@Rule @TempDir
public TemporaryFolder pluginsFolder = new TemporaryFolder(); Path pluginsPath;
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
pluginsPath = pluginsFolder.getRoot().toPath();
Charset charset = Charset.forName("UTF-8"); Charset charset = Charset.forName("UTF-8");
Path pluginPath = pluginsFolder.newFolder("test-plugin-1", "classes", "META-INF").toPath(); Path pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-1", "classes", "META-INF")));
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin1Manifest(), charset); Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin1Manifest(), charset);
pluginPath = pluginsFolder.newFolder("test-plugin-2", "classes", "META-INF").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-2", "classes", "META-INF")));
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin2Manifest(), charset); Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin2Manifest(), charset);
// empty plugin // empty plugin
pluginsFolder.newFolder("test-plugin-3"); Files.createDirectories(pluginsPath.resolve("test-plugin-3"));
// no plugin class // no plugin class
pluginPath = pluginsFolder.newFolder("test-plugin-4", "classes", "META-INF").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-4", "classes", "META-INF")));
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin4Manifest(), charset); Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin4Manifest(), charset);
// no plugin version // no plugin version
pluginPath = pluginsFolder.newFolder("test-plugin-5", "classes", "META-INF").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-5", "classes", "META-INF")));
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin5Manifest(), charset); Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin5Manifest(), charset);
// no plugin id // no plugin id
pluginPath = pluginsFolder.newFolder("test-plugin-6", "classes", "META-INF").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve(Paths.get("test-plugin-6", "classes", "META-INF")));
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin6Manifest(), charset); Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin6Manifest(), charset);
@ -110,10 +109,10 @@ public class ManifestPluginDescriptorFinderTest {
/** /**
* Test of {@link ManifestPluginDescriptorFinder#find(Path)} method. * Test of {@link ManifestPluginDescriptorFinder#find(Path)} method.
*/ */
@Test(expected = PluginException.class) @Test
public void testFindNotFound() throws Exception { public void testFindNotFound() {
PluginDescriptorFinder descriptorFinder = new ManifestPluginDescriptorFinder(); PluginDescriptorFinder descriptorFinder = new ManifestPluginDescriptorFinder();
descriptorFinder.find(pluginsPath.resolve("test-plugin-3")); assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
} }
private List<String> getPlugin1Manifest() { private List<String> getPlugin1Manifest() {

19
pf4j/src/test/java/org/pf4j/PluginDependencyTest.java

@ -15,9 +15,12 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Test;
import static org.junit.Assert.*; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Mario Franco * @author Mario Franco
@ -32,33 +35,33 @@ public class PluginDependencyTest {
PluginDependency instance = new PluginDependency("test"); PluginDependency instance = new PluginDependency("test");
assertEquals("test", instance.getPluginId()); assertEquals("test", instance.getPluginId());
assertEquals("*", instance.getPluginVersionSupport()); assertEquals("*", instance.getPluginVersionSupport());
assertEquals(false, instance.isOptional()); assertFalse(instance.isOptional());
instance = new PluginDependency("test@"); instance = new PluginDependency("test@");
assertEquals("test", instance.getPluginId()); assertEquals("test", instance.getPluginId());
assertEquals("*", instance.getPluginVersionSupport()); assertEquals("*", instance.getPluginVersionSupport());
assertEquals(false, instance.isOptional()); assertFalse(instance.isOptional());
instance = new PluginDependency("test?"); instance = new PluginDependency("test?");
assertEquals("test", instance.getPluginId()); assertEquals("test", instance.getPluginId());
assertEquals("*", instance.getPluginVersionSupport()); assertEquals("*", instance.getPluginVersionSupport());
assertEquals(true, instance.isOptional()); assertTrue(instance.isOptional());
instance = new PluginDependency("test?@"); instance = new PluginDependency("test?@");
assertEquals("test", instance.getPluginId()); assertEquals("test", instance.getPluginId());
assertEquals("*", instance.getPluginVersionSupport()); assertEquals("*", instance.getPluginVersionSupport());
assertEquals(true, instance.isOptional()); assertTrue(instance.isOptional());
instance = new PluginDependency("test@1.0"); instance = new PluginDependency("test@1.0");
assertEquals("test", instance.getPluginId()); assertEquals("test", instance.getPluginId());
assertEquals("1.0", instance.getPluginVersionSupport()); assertEquals("1.0", instance.getPluginVersionSupport());
assertEquals(false, instance.isOptional()); assertFalse(instance.isOptional());
assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=false]", instance.toString()); assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=false]", instance.toString());
instance = new PluginDependency("test?@1.0"); instance = new PluginDependency("test?@1.0");
assertEquals("test", instance.getPluginId()); assertEquals("test", instance.getPluginId());
assertEquals("1.0", instance.getPluginVersionSupport()); assertEquals("1.0", instance.getPluginVersionSupport());
assertEquals(true, instance.isOptional()); assertTrue(instance.isOptional());
assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=true]", instance.toString()); assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=true]", instance.toString());
} }

42
pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java

@ -15,10 +15,9 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import org.pf4j.plugin.PluginZip; import org.pf4j.plugin.PluginZip;
import java.io.IOException; import java.io.IOException;
@ -28,41 +27,42 @@ import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class PropertiesPluginDescriptorFinderTest { public class PropertiesPluginDescriptorFinderTest {
private VersionManager versionManager; private VersionManager versionManager;
private Path pluginsPath;
@Rule @TempDir
public TemporaryFolder pluginsFolder = new TemporaryFolder(); Path pluginsPath;
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
pluginsPath = pluginsFolder.getRoot().toPath();
Charset charset = Charset.forName("UTF-8"); Charset charset = Charset.forName("UTF-8");
Path pluginPath = pluginsFolder.newFolder("test-plugin-1").toPath(); Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1"));
Files.write(pluginPath.resolve("plugin.properties"), getPlugin1Properties(), charset); Files.write(pluginPath.resolve("plugin.properties"), getPlugin1Properties(), charset);
pluginPath = pluginsFolder.newFolder("test-plugin-2").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-2"));
Files.write(pluginPath.resolve("plugin.properties"), getPlugin2Properties(), charset); Files.write(pluginPath.resolve("plugin.properties"), getPlugin2Properties(), charset);
// empty plugin // empty plugin
pluginsFolder.newFolder("test-plugin-3"); Files.createDirectories(pluginsPath.resolve("test-plugin-3"));
// no plugin class // no plugin class
pluginPath = pluginsFolder.newFolder("test-plugin-4").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-4"));
Files.write(pluginPath.resolve("plugin.properties"), getPlugin4Properties(), charset); Files.write(pluginPath.resolve("plugin.properties"), getPlugin4Properties(), charset);
// no plugin version // no plugin version
pluginPath = pluginsFolder.newFolder("test-plugin-5").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-5"));
Files.write(pluginPath.resolve("plugin.properties"), getPlugin5Properties(), charset); Files.write(pluginPath.resolve("plugin.properties"), getPlugin5Properties(), charset);
// no plugin id // no plugin id
pluginPath = pluginsFolder.newFolder("test-plugin-6").toPath(); pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-6"));
Files.write(pluginPath.resolve("plugin.properties"), getPlugin6Properties(), charset); Files.write(pluginPath.resolve("plugin.properties"), getPlugin6Properties(), charset);
versionManager = new DefaultVersionManager(); versionManager = new DefaultVersionManager();
@ -99,15 +99,15 @@ public class PropertiesPluginDescriptorFinderTest {
assertTrue(versionManager.checkVersionConstraint("1.0.0", plugin2.getRequires())); assertTrue(versionManager.checkVersionConstraint("1.0.0", plugin2.getRequires()));
} }
@Test(expected = PluginException.class) @Test
public void testNotFound() throws Exception { public void testNotFound() {
PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder(); PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
descriptorFinder.find(pluginsPath.resolve("test-plugin-3")); assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
} }
@Test @Test
public void findInJar() throws Exception { public void findInJar() throws Exception {
PluginZip pluginJar = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.jar"), "myPlugin") PluginZip pluginJar = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.jar"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();

5
pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java

@ -15,11 +15,12 @@
*/ */
package org.pf4j; package org.pf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.pf4j.plugin.FailTestExtension; import org.pf4j.plugin.FailTestExtension;
import org.pf4j.plugin.TestExtension; import org.pf4j.plugin.TestExtension;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
/** /**
* @author Decebal Suiu * @author Decebal Suiu

19
pf4j/src/test/java/org/pf4j/plugin/PluginZip.java

@ -15,7 +15,6 @@
*/ */
package org.pf4j.plugin; package org.pf4j.plugin;
import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
@ -31,22 +30,18 @@ import java.util.zip.ZipOutputStream;
*/ */
public class PluginZip { public class PluginZip {
private final File file; private final Path path;
private final String pluginId; private final String pluginId;
private final String pluginVersion; private final String pluginVersion;
protected PluginZip(Builder builder) { protected PluginZip(Builder builder) {
this.file = builder.file; this.path = builder.path;
this.pluginId = builder.pluginId; this.pluginId = builder.pluginId;
this.pluginVersion = builder.pluginVersion; this.pluginVersion = builder.pluginVersion;
} }
public File file() {
return file;
}
public Path path() { public Path path() {
return file.toPath(); return path;
} }
public String pluginId() { public String pluginId() {
@ -66,13 +61,13 @@ public class PluginZip {
public static class Builder { public static class Builder {
private final File file; private final Path path;
private final String pluginId; private final String pluginId;
private String pluginVersion; private String pluginVersion;
public Builder(File file, String pluginId) { public Builder(Path path, String pluginId) {
this.file = file; this.path = path;
this.pluginId = pluginId; this.pluginId = pluginId;
} }
@ -94,7 +89,7 @@ public class PluginZip {
properties.setProperty("plugin.version", pluginVersion); properties.setProperty("plugin.version", pluginVersion);
properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin");
ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(file)); ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(path.toFile()));
ZipEntry propertiesFile = new ZipEntry("plugin.properties"); ZipEntry propertiesFile = new ZipEntry("plugin.properties");
outputStream.putNextEntry(propertiesFile); outputStream.putNextEntry(propertiesFile);
properties.store(outputStream, ""); properties.store(outputStream, "");

4
pf4j/src/test/java/org/pf4j/processor/ServiceProviderExtensionStorageTest.java

@ -16,7 +16,7 @@
package org.pf4j.processor; package org.pf4j.processor;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.annotation.processing.Filer; import javax.annotation.processing.Filer;
import javax.tools.FileObject; import javax.tools.FileObject;
@ -29,8 +29,8 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

18
pf4j/src/test/java/org/pf4j/util/FileUtilsTest.java

@ -15,24 +15,24 @@
*/ */
package org.pf4j.util; package org.pf4j.util;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import org.pf4j.plugin.PluginZip; import org.pf4j.plugin.PluginZip;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.junit.Assert.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class FileUtilsTest { public class FileUtilsTest {
@Rule @TempDir
public TemporaryFolder testFolder = new TemporaryFolder(); Path pluginsPath;
@Test @Test
public void expandIfZip() throws Exception { public void expandIfZip() throws Exception {
PluginZip pluginZip = new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin") PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3") .pluginVersion("1.2.3")
.build(); .build();
@ -41,10 +41,10 @@ public class FileUtilsTest {
assertTrue(Files.exists(unzipped.resolve("plugin.properties"))); assertTrue(Files.exists(unzipped.resolve("plugin.properties")));
// File without .suffix // File without .suffix
Path extra = testFolder.newFile("extra").toPath(); Path extra = pluginsPath.resolve("extra");
assertEquals(extra, FileUtils.expandIfZip(extra)); assertEquals(extra, FileUtils.expandIfZip(extra));
// Folder // Folder
Path folder = testFolder.newFile("folder").toPath(); Path folder = pluginsPath.resolve("folder");
assertEquals(folder, FileUtils.expandIfZip(folder)); assertEquals(folder, FileUtils.expandIfZip(folder));
} }

2
pom.xml

@ -48,7 +48,7 @@
<slf4j.version>1.7.25</slf4j.version> <slf4j.version>1.7.25</slf4j.version>
<asm.version>7.1</asm.version> <asm.version>7.1</asm.version>
<junit.version>4.12</junit.version> <junit.version>5.4.0</junit.version>
<hamcrest.version>2.1</hamcrest.version> <hamcrest.version>2.1</hamcrest.version>
<mockito.version>2.24.0</mockito.version> <mockito.version>2.24.0</mockito.version>
<cobertura.version>2.7</cobertura.version> <cobertura.version>2.7</cobertura.version>

Loading…
Cancel
Save