]> source.dussan.org Git - pf4j.git/commitdiff
Migrate to JUnit 5
authorDecebal Suiu <decebal.suiu@gmail.com>
Wed, 20 Mar 2019 20:53:20 +0000 (22:53 +0200)
committerDecebal Suiu <decebal.suiu@gmail.com>
Wed, 20 Mar 2019 20:53:20 +0000 (22:53 +0200)
21 files changed:
pf4j/pom.xml
pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java
pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
pf4j/src/test/java/org/pf4j/DefaultVersionManagerTest.java
pf4j/src/test/java/org/pf4j/DependencyResolverTest.java
pf4j/src/test/java/org/pf4j/ExtensionAnnotationProcessorTest.java
pf4j/src/test/java/org/pf4j/LegacyExtensionStorageTest.java
pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/PluginDependencyTest.java
pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java
pf4j/src/test/java/org/pf4j/plugin/PluginZip.java
pf4j/src/test/java/org/pf4j/processor/ServiceProviderExtensionStorageTest.java
pf4j/src/test/java/org/pf4j/util/FileUtilsTest.java
pom.xml

index 1d078361adfde918ec70fdc2d0cabb0fd36fcdb0..0a78ed2afad5b817577eaa7d67edeafb77ece97c 100644 (file)
         </dependency>
 
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
             <version>${junit.version}</version>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
index 2acabeea635b4e6b100fc88f2daea4adcb45081d..63837560c00401652263c81c021f7eabfb51bd65 100644 (file)
@@ -15,9 +15,9 @@
  */
 package org.pf4j;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+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;
 
@@ -28,7 +28,7 @@ import java.util.List;
 import java.util.Map;
 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.mock;
 import static org.mockito.Mockito.when;
@@ -40,7 +40,7 @@ public class AbstractExtensionFinderTest {
 
     private PluginManager pluginManager;
 
-    @Before
+    @BeforeEach
     public void setUp() {
         PluginWrapper pluginStarted = mock(PluginWrapper.class);
         when(pluginStarted.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
@@ -57,7 +57,7 @@ public class AbstractExtensionFinderTest {
         when(pluginManager.getExtensionFactory()).thenReturn(new DefaultExtensionFactory());
     }
 
-    @After
+    @AfterEach
     public void tearDown() {
         pluginManager = null;
     }
index a30a4ff464279c8e0779169bc80548b8692cef0b..518ba1e9bde59d60ba617007945c6983fbad94b5 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 import org.pf4j.plugin.PluginZip;
 
-import java.io.File;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.List;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
  * @author Decebal Suiu
  */
 public class CompoundPluginDescriptorFinderTest {
 
-    @Rule
-    public TemporaryFolder pluginsFolder = new TemporaryFolder();
+    @TempDir
+    Path pluginsPath;
 
     @Test
     public void add() {
@@ -49,7 +48,8 @@ public class CompoundPluginDescriptorFinderTest {
 
     @Test
     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);
 
         PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
@@ -66,7 +66,7 @@ public class CompoundPluginDescriptorFinderTest {
         PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
             .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")
             .build();
 
@@ -76,19 +76,17 @@ public class CompoundPluginDescriptorFinderTest {
         assertEquals("1.2.3", pluginJar.pluginVersion());
     }
 
-    @Test(expected = PluginException.class)
-    public void testNotFound() throws Exception {
+    @Test
+    public void testNotFound() {
         PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder();
-        Path pluginsPath = pluginsFolder.getRoot().toPath();
-        descriptorFinder.find(pluginsPath.resolve("test-plugin-3"));
+        assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
     }
 
     @Test
     public void testSpaceCharacterInFileName() throws Exception {
         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")
             .build();
 
index 71ffa9382d574965106bb9f08d28a4bf95823172..13327cc171fabad9f6765d77231078038693fd3d 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Test;
-import org.pf4j.plugin.TestExtension;
+import org.junit.jupiter.api.Test;
 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;
 
 /**
  *
index f105aa80433c40458932e1b2f27c2fd107ed856e..eccfca2f2ea84218d5ede8819bde35aa413584ce 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.pf4j.plugin.AnotherFailTestPlugin;
 import org.pf4j.plugin.FailTestPlugin;
 import org.pf4j.plugin.TestPlugin;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
index 3e6fd04735b8a0d1c8c300d31a0f5b5950886630..ced9b4e7f8a33dae9fe8f386b7114c70a43c1313 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 import org.pf4j.plugin.PluginZip;
 
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+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.when;
 
@@ -38,14 +38,12 @@ public class DefaultPluginManagerTest {
     private DefaultPluginManager pluginManager;
     private DefaultPluginDescriptor pluginDescriptor;
     private PluginWrapper pluginWrapper;
-    private Path pluginsPath;
 
-    @Rule
-    public TemporaryFolder pluginsFolder = new TemporaryFolder();
+    @TempDir
+    Path pluginsPath;
 
-    @Before
+    @BeforeEach
     public void setUp() throws IOException {
-        pluginsPath = pluginsFolder.getRoot().toPath();
         pluginManager = new DefaultPluginManager(pluginsPath);
 
         pluginDescriptor = new DefaultPluginDescriptor();
@@ -59,7 +57,7 @@ public class DefaultPluginManagerTest {
         pluginWrapper = new PluginWrapper(pluginManager, pluginDescriptor, Files.createTempDirectory("test"), getClass().getClassLoader());
     }
 
-    @After
+    @AfterEach
     public void tearDown() {
         pluginManager = null;
         pluginDescriptor = null;
@@ -71,16 +69,16 @@ public class DefaultPluginManagerTest {
         pluginManager.validatePluginDescriptor(pluginDescriptor);
     }
 
-    @Test(expected = PluginException.class)
-    public void validateFailsOnId() throws PluginException {
+    @Test
+    public void validateFailsOnId() {
         pluginDescriptor.setPluginId("");
-        pluginManager.validatePluginDescriptor(pluginDescriptor);
+        assertThrows(PluginException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor));
     }
 
-    @Test(expected = PluginException.class)
-    public void validateFailsOnVersion() throws PluginException {
+    @Test
+    public void validateFailsOnVersion() {
         pluginDescriptor.setPluginVersion(null);
-        pluginManager.validatePluginDescriptor(pluginDescriptor);
+        assertThrows(PluginException.class, () -> pluginManager.validatePluginDescriptor(pluginDescriptor));
     }
 
     @Test
@@ -132,7 +130,7 @@ public class DefaultPluginManagerTest {
      */
     @Test
     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")
             .build();
 
index 4f39f2473b2abaff214401389dcb468ba2428c9c..91a35f5e58ffb738a40c334bc51eb363d09dbce2 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.List;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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
@@ -36,25 +34,21 @@ import static org.junit.Assert.assertTrue;
  */
 public class DefaultPluginRepositoryTest {
 
-    private Path pluginsPath;
+    @TempDir
+    Path pluginsPath;
 
-    @Rule
-    public TemporaryFolder pluginsFolder = new TemporaryFolder();
-
-    @Before
+    @BeforeEach
     public void setUp() throws IOException {
-        pluginsPath = pluginsFolder.getRoot().toPath();
-
-        pluginsFolder.newFolder("plugin-1");
+        Path plugin1Path = Files.createDirectories(pluginsPath.resolve("plugin-1"));
         // 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
-        Files.createFile(Paths.get(pluginsFolder.getRoot().getAbsolutePath()).resolve("plugin-1.zip"));
-        pluginsFolder.newFolder("plugin-2");
-        pluginsFolder.newFolder("plugin-3");
+        Files.createFile(pluginsPath.resolve("plugin-1.zip"));
+        Files.createDirectories(pluginsPath.resolve("plugin-2"));
+        Files.createDirectories(pluginsPath.resolve("plugin-3"));
         // standard maven/gradle bin folder - these should be skipped in development mode because the cause errors
-        pluginsFolder.newFolder("target");
-        pluginsFolder.newFolder("build");
+        Files.createDirectories(pluginsPath.resolve("target"));
+        Files.createDirectories(pluginsPath.resolve("build"));
     }
 
     /**
@@ -109,11 +103,11 @@ public class DefaultPluginRepositoryTest {
     }
 
     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) {
-        assertFalse("The directory must not contain the file " + path, paths.contains(path));
+        assertFalse(paths.contains(path), "The directory must not contain the file " + path);
     }
 
 }
index b3f8d2b2082b809919aa106c970bb101480e28b1..635e41cf9357bc4c99e6055b79f050cbe38cd004 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 import org.pf4j.util.FileUtils;
 
-import java.io.File;
 import java.io.IOException;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * @author Mario Franco
@@ -36,15 +33,8 @@ import static org.junit.Assert.assertTrue;
  */
 public class DefaultPluginStatusProviderTest {
 
-    private Path pluginsPath;
-
-    @Rule
-    public TemporaryFolder pluginsFolder = new TemporaryFolder();
-
-    @Before
-    public void setUp() {
-        pluginsPath = pluginsFolder.getRoot().toPath();
-    }
+    @TempDir
+    Path pluginsPath;
 
     @Test
     public void testIsPluginDisabled() throws IOException {
@@ -129,8 +119,8 @@ public class DefaultPluginStatusProviderTest {
         List<String> disabledPlugins = new ArrayList<>();
         disabledPlugins.add("plugin-2");
 
-        File disabledFile = pluginsFolder.newFile("disabled.txt");
-        FileUtils.writeLines(disabledPlugins, disabledFile);
+        Path disabledPath = pluginsPath.resolve("disabled.txt");
+        FileUtils.writeLines(disabledPlugins, disabledPath.toFile());
     }
 
     private void createEnabledFile() throws IOException {
@@ -138,8 +128,8 @@ public class DefaultPluginStatusProviderTest {
         enabledPlugins.add("plugin-1");
         enabledPlugins.add("plugin-2");
 
-        File enabledFile = pluginsFolder.newFile("enabled.txt");
-        FileUtils.writeLines(enabledPlugins, enabledFile);
+        Path enabledPath = pluginsPath.resolve("enabled.txt");
+        FileUtils.writeLines(enabledPlugins, enabledPath.toFile());
     }
 
 }
index 795d3cf1d1851838bf09973a7bda9527b4ed4725..3a277db78f66afbbb9c1712022b21822b6b674d5 100644 (file)
 package org.pf4j;
 
 import com.github.zafarkhaja.semver.ParseException;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+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
@@ -28,7 +30,7 @@ public class DefaultVersionManagerTest {
 
     private VersionManager versionManager;
 
-    @Before
+    @BeforeEach
     public void init() {
         versionManager = new DefaultVersionManager();
     }
@@ -39,14 +41,14 @@ public class DefaultVersionManagerTest {
         assertTrue(versionManager.checkVersionConstraint("1.4.3", ">=1.4.0 & <1.6.0")); // range
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     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() {
-        assertFalse(versionManager.checkVersionConstraint("1.0", ">2.0.0"));
+        assertThrows(ParseException.class, () -> versionManager.checkVersionConstraint("1.0", ">2.0.0"));
     }
 
     @Test
index f7752d45dbf4bf9d48ff4a3a12d1767b86ae7513..6e35780b607f038baafe1e89bf089d24af9b7508 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 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
@@ -31,7 +33,7 @@ public class DependencyResolverTest {
 
     private DependencyResolver resolver;
 
-    @Before
+    @BeforeEach
     public void init() {
         VersionManager versionManager = new DefaultVersionManager();
         resolver = new DependencyResolver(versionManager);
index 9edd6b90592f53c86b53b74a886a1d5eac762bf2..47efca89810cbbe49261ebad4f8728c26444de72 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.pf4j.processor.ExtensionAnnotationProcessor;
 
 import java.util.Set;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * @author Mario Franco
index 57125bdfd96737eeb27df0ec325ff2d9d19aca10..1acc567ea1ff9430b0e2c5b66a9da67201e78f52 100644 (file)
@@ -15,7 +15,7 @@
  */
 package org.pf4j;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.pf4j.processor.LegacyExtensionStorage;
 
 import java.io.IOException;
@@ -24,7 +24,7 @@ import java.io.StringReader;
 import java.util.HashSet;
 import java.util.Set;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
  * @author Decebal Suiu
index 46980bc0e8b07f85efc769ad20ef1797ae85c929..f86cee40d9dbe4bcab086457c1148bf4a92db167 100644 (file)
  */
 package org.pf4j;
 
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
-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 org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.pf4j.plugin.PluginZip;
+
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.pf4j.plugin.PluginZip;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.startsWith;
+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 {
 
     private DefaultPluginManager pluginManager;
 
-    @Rule
-    public TemporaryFolder pluginsFolder = new TemporaryFolder();
+    @TempDir
+    Path pluginsPath;
 
-    @Before
+    @BeforeEach
     public void setUp() {
-        pluginManager = new DefaultPluginManager(pluginsFolder.getRoot().toPath()) {
+        pluginManager = new DefaultPluginManager(pluginsPath) {
 
             @Override
             protected PluginRepository createPluginRepository() {
@@ -62,7 +62,7 @@ public class LoadPluginsTest {
 
     @Test
     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")
             .build();
 
@@ -76,31 +76,32 @@ public class LoadPluginsTest {
         assertEquals(pluginZip.pluginId(), pluginManager.idForPath(pluginZip.unzippedPath()));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     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 {
-        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")
             .build();
 
         assertNotNull(pluginManager.loadPluginFromPath(pluginZip.path()));
-        assertNull(pluginManager.loadPluginFromPath(pluginZip.path()));
+
+        assertThrows(PluginAlreadyLoadedException.class, () -> pluginManager.loadPluginFromPath(pluginZip.path()));
     }
 
     @Test
     public void loadPluginWithSameIdDifferentPathFails() throws Exception {
         String pluginId = "myPlugin";
         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)
             .pluginVersion(pluginVersion)
             .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)
             .pluginVersion(pluginVersion)
             .build();
@@ -134,13 +135,13 @@ public class LoadPluginsTest {
     public void loadPluginWithSameIdDifferentVersionsFails() throws Exception {
         String pluginId = "myPlugin";
         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)
             .pluginVersion(plugin1Version)
             .build();
 
         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)
             .pluginVersion(plugin2Version)
             .build();
@@ -162,7 +163,7 @@ public class LoadPluginsTest {
 
     @Test
     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")
             .build();
 
@@ -181,7 +182,7 @@ public class LoadPluginsTest {
     public void upgrade() throws Exception {
         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")
             .build();
 
@@ -191,7 +192,7 @@ public class LoadPluginsTest {
         assertEquals(1, pluginManager.getPlugins().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")
             .build();
 
@@ -208,12 +209,12 @@ public class LoadPluginsTest {
 
     @Test
     public void getRoot() {
-        assertEquals(pluginsFolder.getRoot().toPath(), pluginManager.getPluginsRoot());
+        assertEquals(pluginsPath, pluginManager.getPluginsRoot());
     }
 
     @Test
-    public void notAPlugin() throws Exception {
-        pluginsFolder.newFile("not-a-zip");
+    public void notAPlugin() {
+        pluginsPath.resolve("not-a-zip");
 
         pluginManager.loadPlugins();
 
@@ -222,11 +223,11 @@ public class LoadPluginsTest {
 
     @Test
     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")
             .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")
             .build();
 
index bc4eb5feab12808a0fdbf659554d29222feb1477..1d83c9f3b2180279f0e62b5564c6718f9fb114d6 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Arrays;
 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
@@ -36,40 +38,37 @@ import static org.junit.Assert.*;
 public class ManifestPluginDescriptorFinderTest {
 
     private VersionManager versionManager;
-    private Path pluginsPath;
 
-    @Rule
-    public TemporaryFolder pluginsFolder = new TemporaryFolder();
+    @TempDir
+    Path pluginsPath;
 
-    @Before
+    @BeforeEach
     public void setUp() throws IOException {
-        pluginsPath = pluginsFolder.getRoot().toPath();
-
         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("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("MANIFEST.MF"), getPlugin2Manifest(), charset);
 
         // empty plugin
-        pluginsFolder.newFolder("test-plugin-3");
+        Files.createDirectories(pluginsPath.resolve("test-plugin-3"));
 
         // 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("MANIFEST.MF"), getPlugin4Manifest(), charset);
 
         // 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("MANIFEST.MF"), getPlugin5Manifest(), charset);
 
         // 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("MANIFEST.MF"), getPlugin6Manifest(), charset);
 
@@ -110,10 +109,10 @@ public class ManifestPluginDescriptorFinderTest {
     /**
      * Test of {@link ManifestPluginDescriptorFinder#find(Path)} method.
      */
-    @Test(expected = PluginException.class)
-    public void testFindNotFound() throws Exception {
+    @Test
+    public void testFindNotFound() {
         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() {
index dbd5fd9a9b997c6ffeea20c3757862262b4f1445..a351c4b983f9b68d14ffb0d28b8abca807274187 100644 (file)
  */
 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
@@ -32,33 +35,33 @@ public class PluginDependencyTest {
         PluginDependency instance = new PluginDependency("test");
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
-        assertEquals(false, instance.isOptional());
+        assertFalse(instance.isOptional());
 
         instance = new PluginDependency("test@");
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
-        assertEquals(false, instance.isOptional());
+        assertFalse(instance.isOptional());
 
         instance = new PluginDependency("test?");
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
-        assertEquals(true, instance.isOptional());
+        assertTrue(instance.isOptional());
 
         instance = new PluginDependency("test?@");
         assertEquals("test", instance.getPluginId());
         assertEquals("*", instance.getPluginVersionSupport());
-        assertEquals(true, instance.isOptional());
+        assertTrue(instance.isOptional());
 
         instance = new PluginDependency("test@1.0");
         assertEquals("test", instance.getPluginId());
         assertEquals("1.0", instance.getPluginVersionSupport());
-        assertEquals(false, instance.isOptional());
+        assertFalse(instance.isOptional());
         assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=false]", instance.toString());
 
         instance = new PluginDependency("test?@1.0");
         assertEquals("test", instance.getPluginId());
         assertEquals("1.0", instance.getPluginVersionSupport());
-        assertEquals(true, instance.isOptional());
+        assertTrue(instance.isOptional());
         assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=true]", instance.toString());
     }
 
index 377d5cab6b5cbbf82187ca3f0cff0bf2e4f1ed1e..78459525d4164c7654a286cbcbc0eea3fd3090e4 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 import org.pf4j.plugin.PluginZip;
 
 import java.io.IOException;
@@ -28,41 +27,42 @@ import java.nio.file.Path;
 import java.util.Arrays;
 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 {
 
     private VersionManager versionManager;
-    private Path pluginsPath;
 
-    @Rule
-    public TemporaryFolder pluginsFolder = new TemporaryFolder();
+    @TempDir
+    Path pluginsPath;
 
-    @Before
+    @BeforeEach
     public void setUp() throws IOException {
-        pluginsPath = pluginsFolder.getRoot().toPath();
-
         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);
 
-        pluginPath = pluginsFolder.newFolder("test-plugin-2").toPath();
+        pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-2"));
         Files.write(pluginPath.resolve("plugin.properties"), getPlugin2Properties(), charset);
 
         // empty plugin
-        pluginsFolder.newFolder("test-plugin-3");
+        Files.createDirectories(pluginsPath.resolve("test-plugin-3"));
 
         // 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);
 
         // 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);
 
         // 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);
 
         versionManager = new DefaultVersionManager();
@@ -99,15 +99,15 @@ public class PropertiesPluginDescriptorFinderTest {
         assertTrue(versionManager.checkVersionConstraint("1.0.0", plugin2.getRequires()));
     }
 
-    @Test(expected = PluginException.class)
-    public void testNotFound() throws Exception {
+    @Test
+    public void testNotFound() {
         PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
-        descriptorFinder.find(pluginsPath.resolve("test-plugin-3"));
+        assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
     }
 
     @Test
     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")
             .build();
 
index 500dd84d300c057b026d0565231ae840b0383910..80e7ab0bc837cc8784609096554967064a4b4717 100644 (file)
  */
 package org.pf4j;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.pf4j.plugin.FailTestExtension;
 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
index f0693659047c92224c97f9dbccbb8a720ee1db56..72e32416e4f866864d6cd859dcdad38c4eac3bdb 100644 (file)
@@ -15,7 +15,6 @@
  */
 package org.pf4j.plugin;
 
-import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.file.Path;
@@ -31,22 +30,18 @@ import java.util.zip.ZipOutputStream;
  */
 public class PluginZip {
 
-    private final File file;
+    private final Path path;
     private final String pluginId;
     private final String pluginVersion;
 
     protected PluginZip(Builder builder) {
-        this.file = builder.file;
+        this.path = builder.path;
         this.pluginId = builder.pluginId;
         this.pluginVersion = builder.pluginVersion;
     }
 
-    public File file() {
-        return file;
-    }
-
     public Path path() {
-        return file.toPath();
+        return path;
     }
 
     public String pluginId() {
@@ -66,13 +61,13 @@ public class PluginZip {
 
     public static class Builder {
 
-        private final File file;
+        private final Path path;
         private final String pluginId;
 
         private String pluginVersion;
 
-        public Builder(File file, String pluginId) {
-            this.file = file;
+        public Builder(Path path, String pluginId) {
+            this.path = path;
             this.pluginId = pluginId;
         }
 
@@ -94,7 +89,7 @@ public class PluginZip {
             properties.setProperty("plugin.version", pluginVersion);
             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");
             outputStream.putNextEntry(propertiesFile);
             properties.store(outputStream, "");
index d15208151724d29351991ae0e05198f83776e81f..ac16b2311aad5745da20e3236f646bd8843c9663 100644 (file)
@@ -16,7 +16,7 @@
 
 package org.pf4j.processor;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import javax.annotation.processing.Filer;
 import javax.tools.FileObject;
@@ -29,8 +29,8 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.BDDMockito.given;
 import static org.mockito.Mockito.mock;
index 76d0c2ec7d36f8e67faaca65e41a6be1af1466aa..5f9a3a71404d4d73d1026ecf64ce305a9131e110 100644 (file)
  */
 package org.pf4j.util;
 
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 import org.pf4j.plugin.PluginZip;
 
 import java.nio.file.Files;
 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 {
 
-    @Rule
-    public TemporaryFolder testFolder = new TemporaryFolder();
+    @TempDir
+    Path pluginsPath;
 
     @Test
     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")
             .build();
 
@@ -41,10 +41,10 @@ public class FileUtilsTest {
         assertTrue(Files.exists(unzipped.resolve("plugin.properties")));
 
         // File without .suffix
-        Path extra = testFolder.newFile("extra").toPath();
+        Path extra = pluginsPath.resolve("extra");
         assertEquals(extra, FileUtils.expandIfZip(extra));
         // Folder
-        Path folder = testFolder.newFile("folder").toPath();
+        Path folder = pluginsPath.resolve("folder");
         assertEquals(folder, FileUtils.expandIfZip(folder));
     }
 
diff --git a/pom.xml b/pom.xml
index ddfde0fb8ba4a3dc15b9104dfd82f616df4e5353..46a432d901fa5d5a8cfa651c9ddff0cd96f10c12 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,7 @@
         <slf4j.version>1.7.25</slf4j.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>
         <mockito.version>2.24.0</mockito.version>
         <cobertura.version>2.7</cobertura.version>