diff --git a/.gitignore b/.gitignore
index 13a344f89a..279ad586c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,7 +5,6 @@
target/
work/
-.@tmp/
.vs/
.vscode/
diff --git a/pom.xml b/pom.xml
index a092b0496b..2a7c677b21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,7 @@
Max
Low
false
+ false
@@ -206,11 +207,6 @@
test-harness
test
-
- junit
- junit
- test
-
nl.jqno.equalsverifier
equalsverifier
@@ -238,7 +234,7 @@
org.mockito
- mockito-core
+ mockito-junit-jupiter
test
@@ -247,12 +243,6 @@
3.4
test
-
- org.testcontainers
- testcontainers
- 1.21.3
- test
-
diff --git a/src/test/java/hudson/plugins/git/BranchTest.java b/src/test/java/hudson/plugins/git/BranchTest.java
index febb240d2e..5851ee3236 100644
--- a/src/test/java/hudson/plugins/git/BranchTest.java
+++ b/src/test/java/hudson/plugins/git/BranchTest.java
@@ -7,56 +7,45 @@
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.Ref;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class BranchTest {
+class BranchTest {
- private final String branchSHA1;
- private final String branchName;
- private final ObjectId branchHead;
- private final Branch branch;
- private final String refPrefix;
- private final Ref branchRef;
- private final Branch branchFromRef;
-
- private static final String REMOTE_BRANCH_NAME = "origin/master";
-
- public BranchTest() {
- this.branchSHA1 = "fa71f704f9b90fa1f857d1623f3fe33fa2277ca9";
- this.branchName = REMOTE_BRANCH_NAME;
- this.branchHead = ObjectId.fromString(branchSHA1);
- this.refPrefix = "refs/remotes/";
- this.branchRef = new ObjectIdRef.PeeledNonTag(Ref.Storage.NEW, refPrefix + branchName, branchHead);
- this.branch = new Branch(branchName, branchHead);
- this.branchFromRef = new Branch(branchRef);
- }
+ private static final String BRANCH_SHA_1 = "fa71f704f9b90fa1f857d1623f3fe33fa2277ca9";
+ private static final String BRANCH_NAME = "origin/master";
+ private static final ObjectId BRANCH_HEAD = ObjectId.fromString(BRANCH_SHA_1);
+ private static final Branch BRANCH = new Branch(BRANCH_NAME, BRANCH_HEAD);
+ private static final String REF_PREFIX = "refs/remotes/";
+ private static final Ref BRANCH_REF =
+ new ObjectIdRef.PeeledNonTag(Ref.Storage.NEW, REF_PREFIX + BRANCH_NAME, BRANCH_HEAD);
+ private static final Branch BRANCH_FROM_REF = new Branch(BRANCH_REF);
@Test
- public void testToString() {
- assertThat(branch.toString(), is(branchFromRef.toString()));
+ void testToString() {
+ assertThat(BRANCH.toString(), is(BRANCH_FROM_REF.toString()));
}
@Test
- public void testToString_Contents() {
- String expected = "Branch " + branchName + "(" + branchSHA1 + ")";
- assertThat(branch.toString(), is(expected));
+ void testToString_Contents() {
+ String expected = "Branch " + BRANCH_NAME + "(" + BRANCH_SHA_1 + ")";
+ assertThat(BRANCH.toString(), is(expected));
}
@Test
- public void hashCodeContract() {
- assertThat(branch, is(branchFromRef));
- assertThat(branch.hashCode(), is(branchFromRef.hashCode()));
+ void hashCodeContract() {
+ assertThat(BRANCH, is(BRANCH_FROM_REF));
+ assertThat(BRANCH.hashCode(), is(BRANCH_FROM_REF.hashCode()));
}
@Test
- public void constructorRefArgStripped() {
- Ref ref = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, refPrefix + branchName, branchHead);
+ void constructorRefArgStripped() {
+ Ref ref = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, REF_PREFIX + BRANCH_NAME, BRANCH_HEAD);
Branch strippedBranch = new Branch(ref);
- assertThat(strippedBranch.getName(), is(branchName));
+ assertThat(strippedBranch.getName(), is(BRANCH_NAME));
}
@Test
- public void equalsContract() {
+ void equalsContract() {
EqualsVerifier.forClass(Branch.class)
.usingGetClass()
.withRedefinedSuperclass()
diff --git a/src/test/java/hudson/plugins/git/GitAPIBadInitTest.java b/src/test/java/hudson/plugins/git/GitAPIBadInitTest.java
index f3fb672e68..07bc91fe3c 100644
--- a/src/test/java/hudson/plugins/git/GitAPIBadInitTest.java
+++ b/src/test/java/hudson/plugins/git/GitAPIBadInitTest.java
@@ -2,8 +2,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import hudson.EnvVars;
import hudson.model.TaskListener;
@@ -13,46 +13,50 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.jenkinsci.plugins.gitclient.GitClient;
-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;
-public class GitAPIBadInitTest {
+class GitAPIBadInitTest {
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir
+ private File tempFolder;
- private final EnvVars env;
-
- public GitAPIBadInitTest() {
- env = new EnvVars();
- }
+ private final EnvVars env = new EnvVars();
private File tempDir;
private TaskListener listener;
- @Before
- public void setUp() throws IOException, InterruptedException {
- tempDir = tempFolder.newFolder();
+ @BeforeEach
+ void setUp() throws Exception {
+ tempDir = newFolder(tempFolder, "junit");
listener = StreamTaskListener.fromStderr();
}
@Test
- public void testInitExistingDirectory() throws Exception {
+ void testInitExistingDirectory() throws Exception {
GitClient git = new GitAPI("git", tempDir, listener, env);
git.init();
File gitDir = new File(tempDir, ".git");
- assertTrue(gitDir + " not created", gitDir.exists());
- assertTrue(gitDir + " not a directory", gitDir.isDirectory());
+ assertTrue(gitDir.exists(), gitDir + " not created");
+ assertTrue(gitDir.isDirectory(), gitDir + " not a directory");
}
@Test
- public void testInitExistingFile() throws Exception {
+ void testInitExistingFile() throws Exception {
File existingFile = new File(tempDir, "file-exists");
Files.writeString(existingFile.toPath(), "git init should fail due to this file", StandardCharsets.UTF_8);
GitClient git = new GitAPI("git", existingFile, listener, env);
GitException e = assertThrows(GitException.class, git::init);
assertThat(e.getMessage(), is("Could not init " + existingFile.getAbsolutePath()));
}
+
+ private static File newFolder(File root, String... subDirs) throws Exception {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + result);
+ }
+ return result;
+ }
}
diff --git a/src/test/java/hudson/plugins/git/GitExceptionTest.java b/src/test/java/hudson/plugins/git/GitExceptionTest.java
index cebdd5d28f..7cf328d059 100644
--- a/src/test/java/hudson/plugins/git/GitExceptionTest.java
+++ b/src/test/java/hudson/plugins/git/GitExceptionTest.java
@@ -5,29 +5,27 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import hudson.EnvVars;
import hudson.model.TaskListener;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
-public class GitExceptionTest {
+class GitExceptionTest {
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
+ @TempDir
+ private File folder;
@Test
- public void throwsGitException() {
+ void throwsGitException() {
GitException e = assertThrows(GitException.class, () -> {
throw new GitException();
});
@@ -35,7 +33,7 @@ public void throwsGitException() {
}
@Test
- public void throwsGitExceptionExpectedMessage() {
+ void throwsGitExceptionExpectedMessage() {
String message = "My custom git exception message";
GitException e = assertThrows(GitException.class, () -> {
throw new GitException(message);
@@ -44,7 +42,7 @@ public void throwsGitExceptionExpectedMessage() {
}
@Test
- public void throwsGitExceptionExpectedMessageWithCause() {
+ void throwsGitExceptionExpectedMessageWithCause() {
String message = "My custom git exception message";
GitException e = assertThrows(GitException.class, () -> {
throw new GitException(message, new IOException("Custom IOException message"));
@@ -54,7 +52,7 @@ public void throwsGitExceptionExpectedMessageWithCause() {
}
@Test
- public void initCliImplThrowsGitException() throws IOException, InterruptedException {
+ void initCliImplThrowsGitException() throws Exception {
if (new File("/").canWrite()) { // running as root?
return;
}
@@ -72,7 +70,7 @@ public void initCliImplThrowsGitException() throws IOException, InterruptedExcep
}
@Test
- public void initJGitImplThrowsGitException() throws IOException, InterruptedException {
+ void initJGitImplThrowsGitException() throws Exception {
if (new File("/").canWrite()) { // running as root?
return;
}
@@ -91,10 +89,10 @@ public void initJGitImplThrowsGitException() throws IOException, InterruptedExce
}
@Test
- public void initCliImplCollisionThrowsGitException() throws IOException, InterruptedException {
- File dir = folder.getRoot();
- File dotGit = folder.newFile(".git");
- Files.write(dotGit.toPath(), "file named .git".getBytes(StandardCharsets.UTF_8), APPEND);
+ void initCliImplCollisionThrowsGitException() throws Exception {
+ File dir = folder;
+ File dotGit = newFile(folder, ".git");
+ Files.writeString(dotGit.toPath(), "file named .git", APPEND);
GitClient defaultClient =
Git.with(TaskListener.NULL, new EnvVars()).in(dir).using("git").getClient();
assertThrows(
@@ -103,10 +101,10 @@ public void initCliImplCollisionThrowsGitException() throws IOException, Interru
}
@Test
- public void initJGitImplCollisionThrowsGitException() throws IOException, InterruptedException {
- File dir = folder.getRoot();
- File dotGit = folder.newFile(".git");
- Files.write(dotGit.toPath(), "file named .git".getBytes(StandardCharsets.UTF_8), APPEND);
+ void initJGitImplCollisionThrowsGitException() throws Exception {
+ File dir = folder;
+ File dotGit = newFile(folder, ".git");
+ Files.writeString(dotGit.toPath(), "file named .git", APPEND);
GitClient defaultClient =
Git.with(TaskListener.NULL, new EnvVars()).in(dir).using("jgit").getClient();
JGitInternalException e = assertThrows(
@@ -122,4 +120,12 @@ public void initJGitImplCollisionThrowsGitException() throws IOException, Interr
private static boolean isWindows() {
return File.pathSeparatorChar == ';';
}
+
+ private static File newFile(File parent, String child) throws Exception {
+ File result = new File(parent, child);
+ if (!result.createNewFile()) {
+ throw new IOException("Couldn't create file " + result);
+ }
+ return result;
+ }
}
diff --git a/src/test/java/hudson/plugins/git/GitLockFailedExceptionTest.java b/src/test/java/hudson/plugins/git/GitLockFailedExceptionTest.java
index ba01459319..e53ba8089e 100644
--- a/src/test/java/hudson/plugins/git/GitLockFailedExceptionTest.java
+++ b/src/test/java/hudson/plugins/git/GitLockFailedExceptionTest.java
@@ -3,14 +3,14 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class GitLockFailedExceptionTest {
+class GitLockFailedExceptionTest {
@Test
- public void throwsGitLockFailedException() {
+ void throwsGitLockFailedException() {
GitLockFailedException lockFailed = assertThrows(GitLockFailedException.class, () -> {
throw new GitLockFailedException();
});
@@ -18,7 +18,7 @@ public void throwsGitLockFailedException() {
}
@Test
- public void throwsGitLockFailedExceptionWithMessage() {
+ void throwsGitLockFailedExceptionWithMessage() {
String message = "My local exception message";
GitLockFailedException lockFailed = assertThrows(GitLockFailedException.class, () -> {
throw new GitLockFailedException(message);
@@ -27,7 +27,7 @@ public void throwsGitLockFailedExceptionWithMessage() {
}
@Test
- public void throwsGitLockFailedExceptionWithCause() {
+ void throwsGitLockFailedExceptionWithCause() {
String message = "My git exception message";
GitException e = new GitException(message);
GitLockFailedException lockFailed = assertThrows(GitLockFailedException.class, () -> {
@@ -37,7 +37,7 @@ public void throwsGitLockFailedExceptionWithCause() {
}
@Test
- public void throwsGitLockFailedExceptionWithCauseAndMessage() {
+ void throwsGitLockFailedExceptionWithCauseAndMessage() {
String message = "My git exception message";
GitException e = new GitException(message);
String lockMessage = "My lock message that is not part of the GitException";
diff --git a/src/test/java/hudson/plugins/git/GitObjectTest.java b/src/test/java/hudson/plugins/git/GitObjectTest.java
index d3087f4e4a..e6ea4d48aa 100644
--- a/src/test/java/hudson/plugins/git/GitObjectTest.java
+++ b/src/test/java/hudson/plugins/git/GitObjectTest.java
@@ -1,65 +1,66 @@
package hudson.plugins.git;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.eclipse.jgit.lib.ObjectId;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.Parameter;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
-@RunWith(Parameterized.class)
-public class GitObjectTest {
+@ParameterizedClass(name = "{0}-{1}")
+@MethodSource("gitObjects")
+class GitObjectTest {
- private final String sha1String;
- private final String name;
- private final ObjectId sha1;
+ @Parameter(0)
+ private String name;
- private final GitObject gitObject;
+ @Parameter(1)
+ private String sha1String;
- public GitObjectTest(String name, String sha1String) {
- this.name = name;
- this.sha1String = sha1String;
- this.sha1 = sha1String != null ? ObjectId.fromString(sha1String) : null;
- gitObject = new GitObject(name, sha1);
- }
+ @Parameter(2)
+ private ObjectId sha1;
+
+ @Parameter(3)
+ private GitObject gitObject;
- @Parameterized.Parameters(name = "{0}-{1}")
- public static Collection gitObjects() {
- List