Switch to JUnit Jupiter (#61)
* Switch to JUnit Jupiter
Using https://docs.openrewrite.org/reference/recipes/java/testing/junit5/junit5bestpractices
```
mvn org.openrewrite.maven:rewrite-maven-plugin:4.38.2:run \
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:1.32.0
\
-DactiveRecipes=org.openrewrite.java.testing.junit5.JUnit5BestPractices
```
```
Changes have been made to maven-wrapper/pom.xml by:
org.openrewrite.java.testing.junit5.JUnit5BestPractices
org.openrewrite.java.testing.junit5.JUnit4to5Migration
org.openrewrite.java.testing.junit5.UseMockitoExtension
org.openrewrite.java.testing.mockito.Mockito1to4Migration
org.openrewrite.maven.UpgradeDependencyVersion:
{groupId=org.mockito, artifactId=*, newVersion=4.x, retainVersions=[]}
org.openrewrite.maven.RemoveDependency: {groupId=junit,
artifactId=junit}
org.openrewrite.maven.AddDependency:
{groupId=org.junit.jupiter, artifactId=junit-jupiter, version=5.x,
onlyIfUsing=org.junit.jupiter.api.Test}
Changes have been made to
maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java
by:
org.openrewrite.java.testing.junit5.JUnit5BestPractices
org.openrewrite.java.testing.junit5.JUnit4to5Migration
org.openrewrite.java.testing.junit5.AssertToAssertions
org.openrewrite.java.testing.junit5.UpdateTestAnnotation
org.openrewrite.java.testing.junit5.StaticImports
org.openrewrite.java.UseStaticImport:
{methodPattern=org.junit.jupiter.api.Assertions *(..)}
Changes have been made to
maven-wrapper/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java
by:
org.openrewrite.java.testing.junit5.JUnit5BestPractices
org.openrewrite.java.testing.junit5.JUnit4to5Migration
org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations
org.openrewrite.java.testing.junit5.UpdateTestAnnotation
org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to
maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java
by:
org.openrewrite.java.testing.junit5.JUnit5BestPractices
org.openrewrite.java.testing.junit5.JUnit4to5Migration
org.openrewrite.java.testing.junit5.AssertToAssertions
org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations
org.openrewrite.java.testing.junit5.UpdateTestAnnotation
org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to
maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java
by:
org.openrewrite.java.testing.junit5.JUnit5BestPractices
org.openrewrite.java.testing.junit5.JUnit4to5Migration
org.openrewrite.java.testing.junit5.AssertToAssertions
org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations
org.openrewrite.java.testing.junit5.UpdateTestAnnotation
org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to
maven-wrapper/src/test/java/org/apache/maven/wrapper/HashAlgorithmVerifierTest.java
by:
org.openrewrite.java.testing.junit5.JUnit5BestPractices
org.openrewrite.java.testing.junit5.JUnit4to5Migration
org.openrewrite.java.testing.junit5.AssertToAssertions
org.openrewrite.java.testing.junit5.TemporaryFolderToTempDir
org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations
org.openrewrite.java.testing.junit5.UpdateTestAnnotation
org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
org.openrewrite.java.testing.junit5.StaticImports
org.openrewrite.java.UseStaticImport:
{methodPattern=org.junit.jupiter.api.Assertions *(..)}
Changes have been made to
maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java
by:
org.openrewrite.java.testing.junit5.JUnit5BestPractices
org.openrewrite.java.testing.junit5.JUnit4to5Migration
org.openrewrite.java.testing.junit5.AssertToAssertions
org.openrewrite.java.testing.junit5.TemporaryFolderToTempDir
org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations
org.openrewrite.java.testing.junit5.UpdateTestAnnotation
org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
org.openrewrite.java.testing.junit5.StaticImports
org.openrewrite.java.UseStaticImport:
{methodPattern=org.junit.jupiter.api.Assertions *(..)}
```
* Spotless apply
* Introduce properties for JUnit and Mockito versionsdiff --git a/maven-wrapper/pom.xml b/maven-wrapper/pom.xml
index 7a01936..284f200 100644
--- a/maven-wrapper/pom.xml
+++ b/maven-wrapper/pom.xml
@@ -31,23 +31,39 @@
<name>Maven Wrapper Jar</name>
<description>Maven Wrapper Jar download, installs and launches installed target Maven distribution as part of Maven Wrapper scripts run.</description>
+ <properties>
+ <junit.version>5.9.1</junit.version>
+ <mockito.version>4.11.0</mockito.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>${junit.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
- <version>4.10.0</version>
+ <version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java
index 6826615..3b19ca2 100644
--- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java
+++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/DownloaderTest.java
@@ -26,13 +26,13 @@
import java.nio.file.Path;
import java.nio.file.Paths;
-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.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class DownloaderTest {
+class DownloaderTest {
private DefaultDownloader download;
@@ -46,8 +46,8 @@
private Path remoteFile;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
download = new DefaultDownloader("mvnw", "aVersion");
testDir = Paths.get("target/test-files/DownloadTest");
Files.createDirectories(testDir);
@@ -62,7 +62,7 @@
}
@Test
- public void testDownload() throws Exception {
+ void testDownload() throws Exception {
assertTrue(Files.notExists(downloadFile));
download.download(sourceRoot, downloadFile);
assertTrue(Files.exists(downloadFile));
diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/HashAlgorithmVerifierTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/HashAlgorithmVerifierTest.java
index 6c90c27..fc9823a 100644
--- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/HashAlgorithmVerifierTest.java
+++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/HashAlgorithmVerifierTest.java
@@ -19,35 +19,37 @@
package org.apache.maven.wrapper;
import java.io.BufferedWriter;
+import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
-import org.junit.Assert;
-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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
public class HashAlgorithmVerifierTest {
- @Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @TempDir
+ public File temporaryFolder;
private Verifier verifier = new HashAlgorithmVerifier();
private Path file;
- @Before
- public void setUp() throws Exception {
- file = temporaryFolder.newFile().toPath();
+ @BeforeEach
+ void setUp() throws Exception {
+ file = File.createTempFile("junit", null, temporaryFolder).toPath();
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
writer.write("Sample file with content");
}
}
@Test
- public void sha256SumsMatch() throws Exception {
+ void sha256SumsMatch() throws Exception {
verifier.verify(
file,
"property",
@@ -56,16 +58,16 @@
}
@Test
- public void sha256SumsDoNotMatch() throws Exception {
+ void sha256SumsDoNotMatch() throws Exception {
try {
verifier.verify(
file,
"prop",
Verifier.SHA_256_ALGORITHM,
"d3b572c45972921782287d8edafa5b19533212f2ebbc61c13c375a67c8f2c48f");
- Assert.fail("Expected RuntimeException");
+ fail("Expected RuntimeException");
} catch (RuntimeException e) {
- Assert.assertEquals(
+ assertEquals(
"Failed to validate Maven distribution SHA-256, your Maven "
+ "distribution might be compromised. If you updated your Maven version, "
+ "you need to update the specified prop property.",
diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java
index 1ec6cac..154a265 100644
--- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java
+++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/InstallerTest.java
@@ -19,6 +19,7 @@
package org.apache.maven.wrapper;
import java.io.BufferedWriter;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
@@ -38,14 +39,14 @@
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;
-import org.junit.Assert;
-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 static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -53,9 +54,8 @@
* @author Hans Dockter
*/
public class InstallerTest {
- @Rule
- public TemporaryFolder tempFolder =
- TemporaryFolder.builder().assureDeletion().build();
+ @TempDir
+ public File tempFolder;
private Path testDir;
@@ -79,9 +79,9 @@
private PathAssembler.LocalDistribution localDistribution;
- @Before
- public void setup() throws Exception {
- testDir = tempFolder.getRoot().toPath();
+ @BeforeEach
+ void setup() throws Exception {
+ testDir = tempFolder.toPath();
configuration.setZipBase(PathAssembler.PROJECT_STRING);
configuration.setZipPath(Paths.get("someZipPath"));
@@ -131,21 +131,21 @@
public void testCreateDist() throws Exception {
Path homeDir = install.createDist(configuration);
- Assert.assertEquals(mavenHomeDir, homeDir);
- Assert.assertTrue(Files.isDirectory(homeDir));
- Assert.assertTrue(Files.exists(homeDir.resolve("bin/mvn")));
- Assert.assertTrue(Files.exists(zipDestination));
+ assertEquals(mavenHomeDir, homeDir);
+ assertTrue(Files.isDirectory(homeDir));
+ assertTrue(Files.exists(homeDir.resolve("bin/mvn")));
+ assertTrue(Files.exists(zipDestination));
- Assert.assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
- Assert.assertEquals(distributionDir, localDistribution.getDistributionDir());
- Assert.assertEquals(zipDestination, localDistribution.getZipFile());
+ assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
+ assertEquals(distributionDir, localDistribution.getDistributionDir());
+ assertEquals(zipDestination, localDistribution.getZipFile());
// download.download(new URI("http://some/test"), distributionDir);
// verify(download).download(new URI("http://some/test"), distributionDir);
}
@Test
- public void testCreateDistWithExistingDistribution() throws Exception {
+ void testCreateDistWithExistingDistribution() throws Exception {
createTestZip(zipDestination);
Files.createDirectories(mavenHomeDir);
@@ -154,18 +154,18 @@
Path homeDir = install.createDist(configuration);
- Assert.assertEquals(mavenHomeDir, homeDir);
- Assert.assertTrue(Files.isDirectory(mavenHomeDir));
- Assert.assertTrue(Files.exists(homeDir.resolve("some-file")));
- Assert.assertTrue(Files.exists(zipDestination));
+ assertEquals(mavenHomeDir, homeDir);
+ assertTrue(Files.isDirectory(mavenHomeDir));
+ assertTrue(Files.exists(homeDir.resolve("some-file")));
+ assertTrue(Files.exists(zipDestination));
- Assert.assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
- Assert.assertEquals(distributionDir, localDistribution.getDistributionDir());
- Assert.assertEquals(zipDestination, localDistribution.getZipFile());
+ assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
+ assertEquals(distributionDir, localDistribution.getDistributionDir());
+ assertEquals(zipDestination, localDistribution.getZipFile());
}
@Test
- public void testCreateDistWithExistingDistAndZipAndAlwaysUnpackTrue() throws Exception {
+ void testCreateDistWithExistingDistAndZipAndAlwaysUnpackTrue() throws Exception {
createTestZip(zipDestination);
Files.createDirectories(mavenHomeDir);
@@ -175,18 +175,18 @@
Path homeDir = install.createDist(configuration);
- Assert.assertEquals(mavenHomeDir, homeDir);
- Assert.assertTrue(Files.isDirectory(mavenHomeDir));
- Assert.assertFalse(Files.exists(homeDir.resolve("garbage")));
- Assert.assertTrue(Files.exists(zipDestination));
+ assertEquals(mavenHomeDir, homeDir);
+ assertTrue(Files.isDirectory(mavenHomeDir));
+ assertFalse(Files.exists(homeDir.resolve("garbage")));
+ assertTrue(Files.exists(zipDestination));
- Assert.assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
- Assert.assertEquals(distributionDir, localDistribution.getDistributionDir());
- Assert.assertEquals(zipDestination, localDistribution.getZipFile());
+ assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
+ assertEquals(distributionDir, localDistribution.getDistributionDir());
+ assertEquals(zipDestination, localDistribution.getZipFile());
}
@Test
- public void testCreateDistWithExistingZipAndDistAndAlwaysDownloadTrue() throws Exception {
+ void testCreateDistWithExistingZipAndDistAndAlwaysDownloadTrue() throws Exception {
createTestZip(zipDestination);
Path garbage = mavenHomeDir.resolve("garbage");
@@ -195,22 +195,22 @@
Path homeDir = install.createDist(configuration);
- Assert.assertEquals(mavenHomeDir, homeDir);
- Assert.assertTrue(Files.isDirectory(mavenHomeDir));
- Assert.assertTrue(Files.exists(homeDir.resolve("bin/mvn")));
- Assert.assertFalse(Files.exists(homeDir.resolve("garbage")));
- Assert.assertTrue(Files.exists(zipDestination));
+ assertEquals(mavenHomeDir, homeDir);
+ assertTrue(Files.isDirectory(mavenHomeDir));
+ assertTrue(Files.exists(homeDir.resolve("bin/mvn")));
+ assertFalse(Files.exists(homeDir.resolve("garbage")));
+ assertTrue(Files.exists(zipDestination));
- Assert.assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
- Assert.assertEquals(distributionDir, localDistribution.getDistributionDir());
- Assert.assertEquals(zipDestination, localDistribution.getZipFile());
+ assertEquals(localDistribution, pathAssembler.getDistribution(configuration));
+ assertEquals(distributionDir, localDistribution.getDistributionDir());
+ assertEquals(zipDestination, localDistribution.getZipFile());
// download.download(new URI("http://some/test"), distributionDir);
// verify(download).download(new URI("http://some/test"), distributionDir);
}
@Test
- public void testZipSlip() throws URISyntaxException {
+ void testZipSlip() throws URISyntaxException {
URL resource = getClass().getClassLoader().getResource("zip-slip.zip");
Path zipSlip = Paths.get(resource.toURI());
when(localDistribution.getZipFile()).thenReturn(zipSlip);
diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java
index 03f6158..9b450bf 100644
--- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java
+++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/PathAssemblerTest.java
@@ -26,13 +26,13 @@
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Hans Dockter
@@ -44,8 +44,8 @@
final WrapperConfiguration configuration = new WrapperConfiguration();
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
configuration.setDistributionBase(PathAssembler.MAVEN_USER_HOME_STRING);
configuration.setDistributionPath(Paths.get("somePath"));
configuration.setZipBase(PathAssembler.MAVEN_USER_HOME_STRING);
@@ -53,7 +53,7 @@
}
@Test
- public void distributionDirWithMavenUserHomeBase() throws Exception {
+ void distributionDirWithMavenUserHomeBase() throws Exception {
configuration.setDistribution(new URI("http://server/dist/maven-0.9-bin.zip"));
Path distributionDir = pathAssembler.getDistribution(configuration).getDistributionDir();
@@ -62,7 +62,7 @@
}
@Test
- public void distributionDirWithProjectBase() throws Exception {
+ void distributionDirWithProjectBase() throws Exception {
configuration.setDistributionBase(PathAssembler.PROJECT_STRING);
configuration.setDistribution(new URI("http://server/dist/maven-0.9-bin.zip"));
@@ -72,7 +72,7 @@
}
@Test
- public void distributionDirWithUnknownBase() throws Exception {
+ void distributionDirWithUnknownBase() throws Exception {
configuration.setDistribution(new URI("http://server/dist/maven-1.0.zip"));
configuration.setDistributionBase("unknownBase");
@@ -85,7 +85,7 @@
}
@Test
- public void distZipWithMavenUserHomeBase() throws Exception {
+ void distZipWithMavenUserHomeBase() throws Exception {
configuration.setDistribution(new URI("http://server/dist/maven-1.0.zip"));
Path dist = pathAssembler.getDistribution(configuration).getZipFile();
@@ -95,7 +95,7 @@
}
@Test
- public void distZipWithProjectBase() throws Exception {
+ void distZipWithProjectBase() throws Exception {
configuration.setZipBase(PathAssembler.PROJECT_STRING);
configuration.setDistribution(new URI("http://server/dist/maven-1.0.zip"));
diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java
index 1bd8c9a..9aa17fb 100644
--- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java
+++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/SystemPropertiesHandlerTest.java
@@ -27,23 +27,23 @@
import java.util.Map;
import java.util.Properties;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
-public class SystemPropertiesHandlerTest {
+class SystemPropertiesHandlerTest {
private Path tmpDir = Paths.get("target/test-files/SystemPropertiesHandlerTest");
- @Before
- public void setupTempDir() throws IOException {
+ @BeforeEach
+ void setupTempDir() throws IOException {
Files.createDirectories(tmpDir);
}
@Test
- public void testParsePropertiesFile() throws Exception {
+ void testParsePropertiesFile() throws Exception {
Path propFile = tmpDir.resolve("props");
Properties props = new Properties();
props.put("a", "b");
@@ -61,7 +61,7 @@
}
@Test
- public void ifNoPropertyFileExistShouldReturnEmptyMap() {
+ void ifNoPropertyFileExistShouldReturnEmptyMap() {
Map<String, String> expected = new HashMap<>();
assertThat(SystemPropertiesHandler.getSystemProperties(tmpDir.resolve("unknown")), equalTo(expected));
}
diff --git a/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java b/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java
index 18da3a6..0f43bc8 100644
--- a/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java
+++ b/maven-wrapper/src/test/java/org/apache/maven/wrapper/WrapperExecutorTest.java
@@ -27,11 +27,15 @@
import java.util.Map;
import java.util.Properties;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_REPOURL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -67,55 +71,53 @@
}
@Test
- public void loadWrapperMetadataFromFile() throws Exception {
+ void loadWrapperMetadataFromFile() throws Exception {
WrapperExecutor wrapper = WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
- Assert.assertEquals(new URI("http://server/test/maven.zip"), wrapper.getDistribution());
- Assert.assertEquals(
+ assertEquals(new URI("http://server/test/maven.zip"), wrapper.getDistribution());
+ assertEquals(
new URI("http://server/test/maven.zip"),
wrapper.getConfiguration().getDistribution());
- Assert.assertEquals("testDistBase", wrapper.getConfiguration().getDistributionBase());
- Assert.assertEquals(
+ assertEquals("testDistBase", wrapper.getConfiguration().getDistributionBase());
+ assertEquals(
"testDistPath", wrapper.getConfiguration().getDistributionPath().toString());
- Assert.assertEquals("testZipBase", wrapper.getConfiguration().getZipBase());
- Assert.assertEquals(
- "testZipPath", wrapper.getConfiguration().getZipPath().toString());
+ assertEquals("testZipBase", wrapper.getConfiguration().getZipBase());
+ assertEquals("testZipPath", wrapper.getConfiguration().getZipPath().toString());
}
@Test
- public void loadWrapperMetadataFromDirectory() throws Exception {
+ void loadWrapperMetadataFromDirectory() throws Exception {
WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory(testDir);
- Assert.assertEquals(new URI("http://server/test/maven.zip"), wrapper.getDistribution());
- Assert.assertEquals(
+ assertEquals(new URI("http://server/test/maven.zip"), wrapper.getDistribution());
+ assertEquals(
new URI("http://server/test/maven.zip"),
wrapper.getConfiguration().getDistribution());
- Assert.assertEquals("testDistBase", wrapper.getConfiguration().getDistributionBase());
- Assert.assertEquals(
+ assertEquals("testDistBase", wrapper.getConfiguration().getDistributionBase());
+ assertEquals(
"testDistPath", wrapper.getConfiguration().getDistributionPath().toString());
- Assert.assertEquals("testZipBase", wrapper.getConfiguration().getZipBase());
- Assert.assertEquals(
- "testZipPath", wrapper.getConfiguration().getZipPath().toString());
+ assertEquals("testZipBase", wrapper.getConfiguration().getZipBase());
+ assertEquals("testZipPath", wrapper.getConfiguration().getZipPath().toString());
}
@Test
- public void useDefaultMetadataNoProeprtiesFile() throws Exception {
+ void useDefaultMetadataNoProeprtiesFile() throws Exception {
WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory(testDir.resolve("unknown"));
- Assert.assertNull(wrapper.getDistribution());
- Assert.assertNull(wrapper.getConfiguration().getDistribution());
- Assert.assertEquals(
+ assertNull(wrapper.getDistribution());
+ assertNull(wrapper.getConfiguration().getDistribution());
+ assertEquals(
PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getDistributionBase());
- Assert.assertEquals(
+ assertEquals(
Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getDistributionPath());
- Assert.assertEquals(
+ assertEquals(
PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getZipBase());
- Assert.assertEquals(
+ assertEquals(
Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getZipPath());
}
@Test
- public void propertiesFileOnlyContainsDistURL() throws Exception {
+ void propertiesFileOnlyContainsDistURL() throws Exception {
properties = new Properties();
properties.put("distributionUrl", "http://server/test/maven.zip");
@@ -123,22 +125,22 @@
WrapperExecutor wrapper = WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
- Assert.assertEquals(new URI("http://server/test/maven.zip"), wrapper.getDistribution());
- Assert.assertEquals(
+ assertEquals(new URI("http://server/test/maven.zip"), wrapper.getDistribution());
+ assertEquals(
new URI("http://server/test/maven.zip"),
wrapper.getConfiguration().getDistribution());
- Assert.assertEquals(
+ assertEquals(
PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getDistributionBase());
- Assert.assertEquals(
+ assertEquals(
Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getDistributionPath());
- Assert.assertEquals(
+ assertEquals(
PathAssembler.MAVEN_USER_HOME_STRING, wrapper.getConfiguration().getZipBase());
- Assert.assertEquals(
+ assertEquals(
Installer.DEFAULT_DISTRIBUTION_PATH, wrapper.getConfiguration().getZipPath());
}
@Test
- public void executeInstallAndLaunch() throws Exception {
+ void executeInstallAndLaunch() throws Exception {
WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory(propertiesFile);
wrapper.execute(new String[] {"arg"}, install, start);
@@ -146,17 +148,17 @@
verify(start).start(new String[] {"arg"}, mockInstallDir);
}
- @Test()
- public void failWhenDistNotSetInProperties() throws Exception {
+ @Test
+ void failWhenDistNotSetInProperties() throws Exception {
properties = new Properties();
writePropertiesFile(properties, propertiesFile, "header");
try {
WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
- Assert.fail("Expected RuntimeException");
+ fail("Expected RuntimeException");
} catch (RuntimeException e) {
- Assert.assertEquals("Could not load wrapper properties from '" + propertiesFile + "'.", e.getMessage());
- Assert.assertEquals(
+ assertEquals("Could not load wrapper properties from '" + propertiesFile + "'.", e.getMessage());
+ assertEquals(
"No value with key 'distributionUrl' specified in wrapper properties file '" + propertiesFile
+ "'.",
e.getCause().getMessage());
@@ -164,32 +166,32 @@
}
@Test
- public void failWhenPropertiesFileDoesNotExist() {
+ void failWhenPropertiesFileDoesNotExist() {
propertiesFile = testDir.resolve("unknown.properties");
try {
WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
- Assert.fail("Expected RuntimeException");
+ fail("Expected RuntimeException");
} catch (RuntimeException e) {
- Assert.assertEquals("Wrapper properties file '" + propertiesFile + "' does not exist.", e.getMessage());
+ assertEquals("Wrapper properties file '" + propertiesFile + "' does not exist.", e.getMessage());
}
}
@Test
- public void testRelativeDistUrl() throws Exception {
+ void testRelativeDistUrl() throws Exception {
properties = new Properties();
properties.put("distributionUrl", "some/relative/url/to/bin.zip");
writePropertiesFile(properties, propertiesFile, "header");
WrapperExecutor wrapper = WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
- Assert.assertNotEquals(
+ assertNotEquals(
"some/relative/url/to/bin.zip", wrapper.getDistribution().getSchemeSpecificPart());
- Assert.assertTrue(wrapper.getDistribution().getSchemeSpecificPart().endsWith("some/relative/url/to/bin.zip"));
+ assertTrue(wrapper.getDistribution().getSchemeSpecificPart().endsWith("some/relative/url/to/bin.zip"));
}
@Test
- public void testEnvironmentVariableOverwrite_simpleCase() throws Exception {
+ void testEnvironmentVariableOverwrite_simpleCase() throws Exception {
final Map<String, String> environmentVariables = new HashMap<>();
environmentVariables.put(MVNW_REPOURL, "https://repo/test");
@@ -199,12 +201,12 @@
WrapperExecutor wrapper = prepareWrapperExecutorWithEnvironmentVariables(environmentVariables);
- Assert.assertEquals(
+ assertEquals(
"https://repo/test/path/to/bin.zip", wrapper.getDistribution().toString());
}
@Test
- public void testEnvironmentVariableOverwrite_mvnwRepoUrl_trailingSlash() throws Exception {
+ void testEnvironmentVariableOverwrite_mvnwRepoUrl_trailingSlash() throws Exception {
final Map<String, String> environmentVariables = new HashMap<>();
environmentVariables.put(MVNW_REPOURL, "https://repo/test/");
properties = new Properties();
@@ -213,12 +215,12 @@
WrapperExecutor wrapper = prepareWrapperExecutorWithEnvironmentVariables(environmentVariables);
- Assert.assertEquals(
+ assertEquals(
"https://repo/test/path/to/bin.zip", wrapper.getDistribution().toString());
}
@Test
- public void testEnvironmentVariableOverwrite_packageName() throws Exception {
+ void testEnvironmentVariableOverwrite_packageName() throws Exception {
final Map<String, String> environmentVariables = new HashMap<>();
environmentVariables.put(MVNW_REPOURL, "https://repo/test");
properties = new Properties();
@@ -227,13 +229,13 @@
WrapperExecutor wrapper = prepareWrapperExecutorWithEnvironmentVariables(environmentVariables);
- Assert.assertEquals(
+ assertEquals(
"https://repo/test/org/apache/maven/to/bin.zip",
wrapper.getDistribution().toString());
}
@Test
- public void testEnvironmentVariableOverwrite_packageName_trailingSpace() throws Exception {
+ void testEnvironmentVariableOverwrite_packageName_trailingSpace() throws Exception {
final Map<String, String> environmentVariables = new HashMap<>();
environmentVariables.put(MVNW_REPOURL, "https://repo/test/");
properties = new Properties();
@@ -242,7 +244,7 @@
WrapperExecutor wrapper = prepareWrapperExecutorWithEnvironmentVariables(environmentVariables);
- Assert.assertEquals(
+ assertEquals(
"https://repo/test/org/apache/maven/to/bin.zip",
wrapper.getDistribution().toString());
}