</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>
*/
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;
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;
private PluginManager pluginManager;
- @Before
+ @BeforeEach
public void setUp() {
PluginWrapper pluginStarted = mock(PluginWrapper.class);
when(pluginStarted.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
when(pluginManager.getExtensionFactory()).thenReturn(new DefaultExtensionFactory());
}
- @After
+ @AfterEach
public void tearDown() {
pluginManager = null;
}
*/
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() {
@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()
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();
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();
*/
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;
/**
*
*/
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;
*/
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;
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();
pluginWrapper = new PluginWrapper(pluginManager, pluginDescriptor, Files.createTempDirectory("test"), getClass().getClassLoader());
}
- @After
+ @AfterEach
public void tearDown() {
pluginManager = null;
pluginDescriptor = null;
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
*/
@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();
*/
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
*/
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"));
}
/**
}
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);
}
}
*/
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
*/
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 {
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 {
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());
}
}
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
private VersionManager versionManager;
- @Before
+ @BeforeEach
public void init() {
versionManager = new DefaultVersionManager();
}
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
*/
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
private DependencyResolver resolver;
- @Before
+ @BeforeEach
public void init() {
VersionManager versionManager = new DefaultVersionManager();
resolver = new DependencyResolver(versionManager);
*/
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
*/
package org.pf4j;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.pf4j.processor.LegacyExtensionStorage;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Decebal Suiu
*/
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() {
@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();
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();
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();
@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();
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();
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();
@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();
@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();
*/
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
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);
/**
* 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() {
*/
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
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());
}
*/
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;
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();
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();
*/
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
*/
package org.pf4j.plugin;
-import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
*/
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() {
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;
}
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, "");
package org.pf4j.processor;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.annotation.processing.Filer;
import javax.tools.FileObject;
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;
*/
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();
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));
}
<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>