summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordecebals <decebal.suiu@gmail.com>2019-06-04 13:17:43 +0300
committerdecebals <decebal.suiu@gmail.com>2019-06-04 13:17:43 +0300
commita0a645ffdd924d17f431a5db49ce4b24e9c88e58 (patch)
tree9998f75d842df3d7cb5af3dd90c3b117a839f2b5
parent1bd6b801d45193b660d59656fafe6ea6cde77975 (diff)
downloadpf4j-a0a645ffdd924d17f431a5db49ce4b24e9c88e58.tar.gz
pf4j-a0a645ffdd924d17f431a5db49ce4b24e9c88e58.zip
Polishing #321
-rw-r--r--pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java92
1 files changed, 48 insertions, 44 deletions
diff --git a/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java b/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java
index fe2cac2..8f5a727 100644
--- a/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java
+++ b/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java
@@ -1,69 +1,73 @@
+/*
+ * Copyright (C) 2012-present the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.pf4j;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.io.TempDir;
+import org.pf4j.plugin.PluginJar;
+import org.pf4j.plugin.TestExtension;
+import org.pf4j.plugin.TestPlugin;
-import java.io.IOException;
import java.nio.file.Path;
-import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginJar;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+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.assertTrue;
+import static org.junit.jupiter.api.condition.OS.WINDOWS;
public class LegacyExtensionFinderTest {
@TempDir
- public Path pluginsPath;
-
- public static class TestPlugin extends Plugin {
-
- public TestPlugin(PluginWrapper wrapper) {
- super(wrapper);
- }
- }
-
- @Extension
- public static class TestExtension implements ExtensionPoint {
-
- }
-
- private static boolean systemIsWindows() {
- String os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
- return os.startsWith("win");
- }
+ Path pluginsPath;
@Test
- public void shouldUnlockFileAfterReadingExtensionsFromPlugin() throws IOException, PluginException {
-
- assumeTrue(systemIsWindows());
- final Path pluginJarPath = pluginsPath.resolve("test-plugin.jar");
- PluginJar pluginJar = new PluginJar.Builder(pluginJarPath, "test-plugin")
+ @EnabledOnOs(WINDOWS)
+ public void shouldUnlockFileAfterReadingExtensionsFromPlugin() throws Exception {
+ PluginJar pluginJar = new PluginJar.Builder(pluginsPath.resolve("test-plugin.jar"), "test-plugin")
.pluginClass(TestPlugin.class.getName())
.pluginVersion("1.2.3")
.extension(TestExtension.class.getName())
.build();
- JarPluginManager pluginManager = new JarPluginManager(pluginsPath);
+ assertTrue(pluginJar.file().exists());
+ PluginManager pluginManager = new JarPluginManager(pluginsPath);
pluginManager.loadPlugins();
+
+ assertEquals(1, pluginManager.getPlugins().size());
+
LegacyExtensionFinder extensionFinder = new LegacyExtensionFinder(pluginManager);
- Map<String, Set<String>> pluginStorages = extensionFinder.readPluginsStorages();
- pluginManager.unloadPlugin(pluginJar.pluginId());
- boolean fileDeleted = pluginJarPath.toFile().delete();
+ Map<String, Set<String>> pluginsStorages = extensionFinder.readPluginsStorages();
+ assertNotNull(pluginsStorages);
- assertThat(pluginStorages, is(notNullValue()));
- assertThat(pluginStorages.get(pluginJar.pluginId()), is(notNullValue()));
- assertThat(pluginStorages.get(pluginJar.pluginId()).size(), is(equalTo(1)));
- assertThat(pluginStorages.get(pluginJar.pluginId()),
- contains("org.pf4j.LegacyExtensionFinderTest$TestExtension"));
- assertThat(fileDeleted, is(equalTo(true)));
+ pluginManager.unloadPlugin(pluginJar.pluginId());
+ boolean fileDeleted = pluginJar.file().delete();
+
+ Set<String> pluginStorages = pluginsStorages.get(pluginJar.pluginId());
+ assertNotNull(pluginStorages);
+ assertEquals(1, pluginStorages.size());
+ assertThat(pluginStorages, contains(TestExtension.class.getName()));
+ assertTrue(fileDeleted);
+ assertFalse(pluginJar.file().exists());
}
}