From a226198a1319e738bb64b2cd44a610a4db8a2ea2 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Wed, 25 Mar 2020 16:47:39 +0100 Subject: [PATCH] WIP adopting junit5 --- .../GenerateOoziePropertiesMojoTest.java | 14 ++-- .../WritePredefinedProjectPropertiesTest.java | 74 ++++++++----------- dhp-schemas/pom.xml | 6 -- pom.xml | 22 ++++-- 4 files changed, 54 insertions(+), 62 deletions(-) diff --git a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java index 6f55828ef..c9c519189 100644 --- a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java +++ b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/GenerateOoziePropertiesMojoTest.java @@ -1,12 +1,12 @@ package eu.dnetlib.maven.plugin.properties; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import static eu.dnetlib.maven.plugin.properties.GenerateOoziePropertiesMojo.PROPERTY_NAME_SANDBOX_NAME; import static eu.dnetlib.maven.plugin.properties.GenerateOoziePropertiesMojo.PROPERTY_NAME_WF_SOURCE_DIR; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Before; -import org.junit.Test; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; /** * @author mhorst @@ -16,7 +16,7 @@ public class GenerateOoziePropertiesMojoTest { private GenerateOoziePropertiesMojo mojo = new GenerateOoziePropertiesMojo(); - @Before + @BeforeAll public void clearSystemProperties() { System.clearProperty(PROPERTY_NAME_SANDBOX_NAME); System.clearProperty(PROPERTY_NAME_WF_SOURCE_DIR); @@ -28,7 +28,7 @@ public class GenerateOoziePropertiesMojoTest { mojo.execute(); // assert - assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME)); + assertNull(System.getProperty(PROPERTY_NAME_SANDBOX_NAME)); } @Test diff --git a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java index 51d9575ff..bbf94f0f3 100644 --- a/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java +++ b/dhp-build/dhp-build-properties-maven-plugin/src/test/java/eu/dnetlib/maven/plugin/properties/WritePredefinedProjectPropertiesTest.java @@ -1,49 +1,37 @@ package eu.dnetlib.maven.plugin.properties; -import static eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.PROPERTY_PREFIX_ENV; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doReturn; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Properties; - import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import java.io.*; +import java.util.Properties; + +import static eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.PROPERTY_PREFIX_ENV; +import static junit.framework.Assert.*; +import static org.mockito.Mockito.doReturn; /** * @author mhorst * */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class WritePredefinedProjectPropertiesTest { - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - @Mock private MavenProject mavenProject; private WritePredefinedProjectProperties mojo; - @Before - public void init() { + @BeforeAll + public void init(@TempDir File testFolder) { mojo = new WritePredefinedProjectProperties(); - mojo.outputFile = getPropertiesFileLocation(); + mojo.outputFile = getPropertiesFileLocation(testFolder); mojo.project = mavenProject; doReturn(new Properties()).when(mavenProject).getProperties(); } @@ -82,14 +70,14 @@ public class WritePredefinedProjectPropertiesTest { } @Test(expected=MojoExecutionException.class) - public void testExecuteWithProjectPropertiesAndInvalidOutputFile() throws Exception { + public void testExecuteWithProjectPropertiesAndInvalidOutputFile(@TempDir File testFolder) throws Exception { // given String key = "projectPropertyKey"; String value = "projectPropertyValue"; Properties projectProperties = new Properties(); projectProperties.setProperty(key, value); doReturn(projectProperties).when(mavenProject).getProperties(); - mojo.outputFile = testFolder.getRoot(); + mojo.outputFile = testFolder; // execute mojo.execute(); @@ -144,7 +132,7 @@ public class WritePredefinedProjectPropertiesTest { } @Test - public void testExecuteIncludingPropertyKeysFromFile() throws Exception { + public void testExecuteIncludingPropertyKeysFromFile(@TempDir File testFolder) throws Exception { // given String key = "projectPropertyKey"; String value = "projectPropertyValue"; @@ -155,7 +143,7 @@ public class WritePredefinedProjectPropertiesTest { projectProperties.setProperty(includedKey, includedValue); doReturn(projectProperties).when(mavenProject).getProperties(); - File includedPropertiesFile = new File(testFolder.getRoot(), "included.properties"); + File includedPropertiesFile = new File(testFolder, "included.properties"); Properties includedProperties = new Properties(); includedProperties.setProperty(includedKey, "irrelevantValue"); includedProperties.store(new FileWriter(includedPropertiesFile), null); @@ -217,7 +205,7 @@ public class WritePredefinedProjectPropertiesTest { } @Test - public void testExecuteIncludingPropertyKeysFromXmlFile() throws Exception { + public void testExecuteIncludingPropertyKeysFromXmlFile(@TempDir File testFolder) throws Exception { // given String key = "projectPropertyKey"; String value = "projectPropertyValue"; @@ -228,7 +216,7 @@ public class WritePredefinedProjectPropertiesTest { projectProperties.setProperty(includedKey, includedValue); doReturn(projectProperties).when(mavenProject).getProperties(); - File includedPropertiesFile = new File(testFolder.getRoot(), "included.xml"); + File includedPropertiesFile = new File(testFolder, "included.xml"); Properties includedProperties = new Properties(); includedProperties.setProperty(includedKey, "irrelevantValue"); includedProperties.storeToXML(new FileOutputStream(includedPropertiesFile), null); @@ -247,7 +235,7 @@ public class WritePredefinedProjectPropertiesTest { } @Test(expected=MojoExecutionException.class) - public void testExecuteIncludingPropertyKeysFromInvalidXmlFile() throws Exception { + public void testExecuteIncludingPropertyKeysFromInvalidXmlFile(@TempDir File testFolder) throws Exception { // given String key = "projectPropertyKey"; String value = "projectPropertyValue"; @@ -258,7 +246,7 @@ public class WritePredefinedProjectPropertiesTest { projectProperties.setProperty(includedKey, includedValue); doReturn(projectProperties).when(mavenProject).getProperties(); - File includedPropertiesFile = new File(testFolder.getRoot(), "included.xml"); + File includedPropertiesFile = new File(testFolder, "included.xml"); Properties includedProperties = new Properties(); includedProperties.setProperty(includedKey, "irrelevantValue"); includedProperties.store(new FileOutputStream(includedPropertiesFile), null); @@ -294,7 +282,7 @@ public class WritePredefinedProjectPropertiesTest { } @Test - public void testExecuteWithEnvironmentProperties() throws Exception { + public void testExecuteWithEnvironmentProperties(@TempDir File testFolder) throws Exception { // given mojo.setIncludeEnvironmentVariables(true); @@ -303,7 +291,7 @@ public class WritePredefinedProjectPropertiesTest { // assert assertTrue(mojo.outputFile.exists()); - Properties storedProperties = getStoredProperties(); + Properties storedProperties = getStoredProperties(testFolder); assertTrue(storedProperties.size() > 0); for (Object currentKey : storedProperties.keySet()) { assertTrue(((String)currentKey).startsWith(PROPERTY_PREFIX_ENV)); @@ -330,7 +318,7 @@ public class WritePredefinedProjectPropertiesTest { } @Test - public void testExecuteWithSystemPropertiesAndEscapeChars() throws Exception { + public void testExecuteWithSystemPropertiesAndEscapeChars(@TempDir File testFolder) throws Exception { // given String key = "systemPropertyKey "; String value = "systemPropertyValue"; @@ -344,7 +332,7 @@ public class WritePredefinedProjectPropertiesTest { // assert assertTrue(mojo.outputFile.exists()); - Properties storedProperties = getStoredProperties(); + Properties storedProperties = getStoredProperties(testFolder); assertTrue(storedProperties.size() > 0); assertFalse(storedProperties.containsKey(key)); assertTrue(storedProperties.containsKey(key.trim())); @@ -353,13 +341,13 @@ public class WritePredefinedProjectPropertiesTest { // ----------------------------------- PRIVATE ------------------------------------------- - private File getPropertiesFileLocation() { - return new File(testFolder.getRoot(), "test.properties"); + private File getPropertiesFileLocation(File testFolder) { + return new File(testFolder, "test.properties"); } - private Properties getStoredProperties() throws FileNotFoundException, IOException { + private Properties getStoredProperties(File testFolder) throws FileNotFoundException, IOException { Properties properties = new Properties(); - properties.load(new FileInputStream(getPropertiesFileLocation())); + properties.load(new FileInputStream(getPropertiesFileLocation(testFolder))); return properties; } } diff --git a/dhp-schemas/pom.xml b/dhp-schemas/pom.xml index 8338f69e4..14881a222 100644 --- a/dhp-schemas/pom.xml +++ b/dhp-schemas/pom.xml @@ -36,12 +36,6 @@ guava - - junit - junit - ${junit.version} - - eu.dnetlib.dhp dhp-common diff --git a/pom.xml b/pom.xml index 1ae078128..6594943a8 100644 --- a/pom.xml +++ b/pom.xml @@ -74,19 +74,28 @@ - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} test org.mockito mockito-core - 2.7.22 + ${mockito-core.version} test + + org.mockito + mockito-junit-jupiter + ${mockito-core.version} + test + + + + @@ -397,7 +406,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.19.1 + 3.0.0-M4 true @@ -505,7 +514,8 @@ 3.5 11.0.2 2.11.12 - 4.12 + 5.6.1 + 3.3.3 3.4.2