diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2019-04-12 22:26:55 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2019-04-12 22:26:55 +0300 |
commit | f149b2e8ae37e7d3f41187221011f2419fd3c2b6 (patch) | |
tree | 04f195e51f8ae873814389a8237e0ea27d9bf936 | |
parent | 4907d01093b447044d24b158daaaded0f4757948 (diff) | |
download | pf4j-f149b2e8ae37e7d3f41187221011f2419fd3c2b6.tar.gz pf4j-f149b2e8ae37e7d3f41187221011f2419fd3c2b6.zip |
Improve readability of PropertiesPluginDescriptorFinderTest
-rw-r--r-- | pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java | 137 |
1 files changed, 64 insertions, 73 deletions
diff --git a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java index 8b484b4..a65c84e 100644 --- a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java @@ -19,12 +19,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import java.io.FileOutputStream; import java.io.IOException; -import java.nio.charset.Charset; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; +import java.util.Properties; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -40,28 +42,26 @@ public class PropertiesPluginDescriptorFinderTest { @BeforeEach public void setUp() throws IOException { - Charset charset = Charset.forName("UTF-8"); - Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1")); - Files.write(pluginPath.resolve("plugin.properties"), getPlugin1Properties(), charset); + storePropertiesToPath(getPlugin1Properties(), pluginPath.resolve("plugin.properties")); pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-2")); - Files.write(pluginPath.resolve("plugin.properties"), getPlugin2Properties(), charset); + storePropertiesToPath(getPlugin2Properties(), pluginPath.resolve("plugin.properties")); // empty plugin Files.createDirectories(pluginsPath.resolve("test-plugin-3")); // no plugin class pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-4")); - Files.write(pluginPath.resolve("plugin.properties"), getPlugin4Properties(), charset); + storePropertiesToPath(getPlugin4Properties(), pluginPath.resolve("plugin.properties")); // no plugin version pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-5")); - Files.write(pluginPath.resolve("plugin.properties"), getPlugin5Properties(), charset); + storePropertiesToPath(getPlugin5Properties(), pluginPath.resolve("plugin.properties")); // no plugin id pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-6")); - Files.write(pluginPath.resolve("plugin.properties"), getPlugin6Properties(), charset); + storePropertiesToPath(getPlugin6Properties(), pluginPath.resolve("plugin.properties")); versionManager = new DefaultVersionManager(); } @@ -103,77 +103,68 @@ public class PropertiesPluginDescriptorFinderTest { assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); } - private List<String> getPlugin1Properties() { - String[] lines = new String[] { - "plugin.id=test-plugin-1\n" - + "plugin.version=0.0.1\n" - + "plugin.description=Test Plugin 1\n" - + "plugin.provider=Decebal Suiu\n" - + "plugin.class=org.pf4j.plugin.TestPlugin\n" - + "plugin.dependencies=test-plugin-2,test-plugin-3@~1.0\n" - + "plugin.requires=>=1\n" - + "plugin.license=Apache-2.0\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Properties getPlugin1Properties() { + Properties properties = new Properties(); + properties.setProperty("plugin.id", "test-plugin-1"); + properties.setProperty("plugin.version", "0.0.1"); + properties.setProperty("plugin.description", "Test Plugin 1"); + properties.setProperty("plugin.provider", "Decebal Suiu"); + properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); + properties.setProperty("plugin.dependencies", "test-plugin-2,test-plugin-3@~1.0"); + properties.setProperty("plugin.requires", ">=1"); + properties.setProperty("plugin.license", "Apache-2.0"); + + return properties; } - private List<String> getPlugin2Properties() { - String[] lines = new String[] { - "plugin.id=test-plugin-2\n" - + "plugin.version=0.0.1\n" - + "plugin.provider=Decebal Suiu\n" - + "plugin.class=org.pf4j.plugin.TestPlugin\n" - + "plugin.dependencies=\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Properties getPlugin2Properties() { + Properties properties = new Properties(); + properties.setProperty("plugin.id", "test-plugin-2"); + properties.setProperty("plugin.version", "0.0.1"); + properties.setProperty("plugin.provider", "Decebal Suiu"); + properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); + properties.setProperty("plugin.dependencies", ""); + + return properties; } - private List<String> getPlugin4Properties() { - String[] lines = new String[] { - "plugin.id=test-plugin-2\n" - + "plugin.version=0.0.1\n" - + "plugin.provider=Decebal Suiu\n" - + "plugin.dependencies=\n" - + "plugin.requires=*\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Properties getPlugin4Properties() { + Properties properties = new Properties(); + properties.setProperty("plugin.id", "test-plugin-2"); + properties.setProperty("plugin.version", "0.0.1"); + properties.setProperty("plugin.provider", "Decebal Suiu"); + properties.setProperty("plugin.dependencies", ""); + properties.setProperty("plugin.requires", "*"); + + return properties; } - private List<String> getPlugin5Properties() { - String[] lines = new String[] { - "plugin.id=test-plugin-2\n" - + "plugin.provider=Decebal Suiu\n" - + "plugin.class=org.pf4j.plugin.TestPlugin\n" - + "plugin.dependencies=\n" - + "plugin.requires=*\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private Properties getPlugin5Properties() { + Properties properties = new Properties(); + properties.setProperty("plugin.id", "test-plugin-2"); + properties.setProperty("plugin.provider", "Decebal Suiu"); + properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); + properties.setProperty("plugin.dependencies", ""); + properties.setProperty("plugin.requires", "*"); + + return properties; + } + + private Properties getPlugin6Properties() { + Properties properties = new Properties(); + properties.setProperty("plugin.version", "0.0.1"); + properties.setProperty("plugin.provider", "Decebal Suiu"); + properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); + properties.setProperty("plugin.dependencies", ""); + properties.setProperty("plugin.requires", "*"); + + return properties; } - private List<String> getPlugin6Properties() { - String[] lines = new String[] { - "plugin.version=0.0.1\n" - + "plugin.provider=Decebal Suiu\n" - + "plugin.class=org.pf4j.plugin.TestPlugin\n" - + "plugin.dependencies=\n" - + "plugin.requires=*\n" - + "\n" - + "" - }; - - return Arrays.asList(lines); + private void storePropertiesToPath(Properties properties, Path path) throws IOException { + try (Writer writer = new OutputStreamWriter(new FileOutputStream(path.toFile()), StandardCharsets.UTF_8)) { + properties.store(writer, ""); + } } } |