Browse Source

Improve readability of PropertiesPluginDescriptorFinderTest

async
Decebal Suiu 6 years ago
parent
commit
f149b2e8ae
  1. 137
      pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java

137
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.Test;
import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.api.io.TempDir;
import java.io.FileOutputStream;
import java.io.IOException; 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.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Properties;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
@ -40,28 +42,26 @@ public class PropertiesPluginDescriptorFinderTest {
@BeforeEach @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
Charset charset = Charset.forName("UTF-8");
Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1")); 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")); pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-2"));
Files.write(pluginPath.resolve("plugin.properties"), getPlugin2Properties(), charset); storePropertiesToPath(getPlugin2Properties(), pluginPath.resolve("plugin.properties"));
// empty plugin // empty plugin
Files.createDirectories(pluginsPath.resolve("test-plugin-3")); Files.createDirectories(pluginsPath.resolve("test-plugin-3"));
// no plugin class // no plugin class
pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-4")); 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 // no plugin version
pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-5")); 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 // no plugin id
pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-6")); 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(); versionManager = new DefaultVersionManager();
} }
@ -103,77 +103,68 @@ public class PropertiesPluginDescriptorFinderTest {
assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); assertThrows(PluginException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
} }
private List<String> getPlugin1Properties() { private Properties getPlugin1Properties() {
String[] lines = new String[] { Properties properties = new Properties();
"plugin.id=test-plugin-1\n" properties.setProperty("plugin.id", "test-plugin-1");
+ "plugin.version=0.0.1\n" properties.setProperty("plugin.version", "0.0.1");
+ "plugin.description=Test Plugin 1\n" properties.setProperty("plugin.description", "Test Plugin 1");
+ "plugin.provider=Decebal Suiu\n" properties.setProperty("plugin.provider", "Decebal Suiu");
+ "plugin.class=org.pf4j.plugin.TestPlugin\n" properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin");
+ "plugin.dependencies=test-plugin-2,test-plugin-3@~1.0\n" properties.setProperty("plugin.dependencies", "test-plugin-2,test-plugin-3@~1.0");
+ "plugin.requires=>=1\n" properties.setProperty("plugin.requires", ">=1");
+ "plugin.license=Apache-2.0\n" properties.setProperty("plugin.license", "Apache-2.0");
+ "\n"
+ "" return properties;
};
return Arrays.asList(lines);
} }
private List<String> getPlugin2Properties() { private Properties getPlugin2Properties() {
String[] lines = new String[] { Properties properties = new Properties();
"plugin.id=test-plugin-2\n" properties.setProperty("plugin.id", "test-plugin-2");
+ "plugin.version=0.0.1\n" properties.setProperty("plugin.version", "0.0.1");
+ "plugin.provider=Decebal Suiu\n" properties.setProperty("plugin.provider", "Decebal Suiu");
+ "plugin.class=org.pf4j.plugin.TestPlugin\n" properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin");
+ "plugin.dependencies=\n" properties.setProperty("plugin.dependencies", "");
+ "\n"
+ "" return properties;
};
return Arrays.asList(lines);
} }
private List<String> getPlugin4Properties() { private Properties getPlugin4Properties() {
String[] lines = new String[] { Properties properties = new Properties();
"plugin.id=test-plugin-2\n" properties.setProperty("plugin.id", "test-plugin-2");
+ "plugin.version=0.0.1\n" properties.setProperty("plugin.version", "0.0.1");
+ "plugin.provider=Decebal Suiu\n" properties.setProperty("plugin.provider", "Decebal Suiu");
+ "plugin.dependencies=\n" properties.setProperty("plugin.dependencies", "");
+ "plugin.requires=*\n" properties.setProperty("plugin.requires", "*");
+ "\n"
+ "" return properties;
};
return Arrays.asList(lines);
} }
private List<String> getPlugin5Properties() { private Properties getPlugin5Properties() {
String[] lines = new String[] { Properties properties = new Properties();
"plugin.id=test-plugin-2\n" properties.setProperty("plugin.id", "test-plugin-2");
+ "plugin.provider=Decebal Suiu\n" properties.setProperty("plugin.provider", "Decebal Suiu");
+ "plugin.class=org.pf4j.plugin.TestPlugin\n" properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin");
+ "plugin.dependencies=\n" properties.setProperty("plugin.dependencies", "");
+ "plugin.requires=*\n" properties.setProperty("plugin.requires", "*");
+ "\n"
+ "" return properties;
}; }
return Arrays.asList(lines); 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() { private void storePropertiesToPath(Properties properties, Path path) throws IOException {
String[] lines = new String[] { try (Writer writer = new OutputStreamWriter(new FileOutputStream(path.toFile()), StandardCharsets.UTF_8)) {
"plugin.version=0.0.1\n" properties.store(writer, "");
+ "plugin.provider=Decebal Suiu\n" }
+ "plugin.class=org.pf4j.plugin.TestPlugin\n"
+ "plugin.dependencies=\n"
+ "plugin.requires=*\n"
+ "\n"
+ ""
};
return Arrays.asList(lines);
} }
} }

Loading…
Cancel
Save