Skip to content

Commit f935a30

Browse files
committed
Migrate to JUnit 5
1 parent 0fc8bb4 commit f935a30

11 files changed

+258
-263
lines changed

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ dependencies {
2323

2424
runtimeOnly 'org.slf4j:slf4j-simple:2.0.16'
2525

26-
testImplementation 'org.junit.vintage:junit-vintage-engine:5.11.3'
26+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
27+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.3'
28+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.3'
2729
testImplementation 'org.dstadler:commons-test:1.0.0.21'
2830
}
2931

32+
test {
33+
useJUnitPlatform()
34+
}
35+
3036
wrapper {
3137
gradleVersion = '8.5'
3238
}

src/test/java/org/dstadler/jgit/JGitReproducerTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@
1212
import org.eclipse.jgit.revwalk.RevWalk;
1313
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
1414
import org.eclipse.jgit.treewalk.TreeWalk;
15-
import org.junit.Assume;
16-
import org.junit.Test;
15+
import org.junit.jupiter.api.Assumptions;
16+
import org.junit.jupiter.api.Test;
1717

1818
import java.io.File;
1919
import java.io.FileNotFoundException;
2020
import java.io.IOException;
2121
import java.nio.file.Files;
2222
import java.nio.file.Path;
23-
import java.nio.file.Paths;
2423

2524
/**
2625
* Some tests to try to narrow down/reproduce some problems in JGit itself.
2726
*/
2827
public class JGitReproducerTest {
2928
@Test
3029
public void testSymlink() throws Exception {
31-
Assume.assumeFalse("Symbolic links do not work on Windows", SystemUtils.IS_OS_WINDOWS);
30+
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS, "Symbolic links do not work on Windows");
3231

3332
try (Repository repository = createNewRepository()) {
3433
commitSymbolicLink(repository);
@@ -71,8 +70,8 @@ private TreeWalk buildTreeWalk(Repository repository, RevTree tree, @SuppressWar
7170
private void commitSymbolicLink(Repository repository) throws IOException, GitAPIException {
7271
try (Git git = new Git(repository)) {
7372
// create a symbolic link
74-
Path newLink = Paths.get(repository.getDirectory().getParentFile().getAbsolutePath(), "link");
75-
Path target = Paths.get("/tmp");
73+
Path newLink = Path.of(repository.getDirectory().getParentFile().getAbsolutePath(), "link");
74+
Path target = Path.of("/tmp");
7675
Files.createSymbolicLink(newLink, target);
7776

7877
// run the add-call

src/test/java/org/dstadler/jgit/ValidateGitRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.List;
1111
import java.util.Set;
1212

13-
import static org.junit.Assert.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
1414

1515

1616
public class ValidateGitRepository {

src/test/java/org/dstadler/jgitfs/JGitFSTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import org.apache.commons.io.FileUtils;
44
import org.apache.commons.lang3.SystemUtils;
5+
import org.apache.commons.lang3.exception.ExceptionUtils;
56
import org.dstadler.commons.testing.PrivateConstructorCoverage;
67
import org.dstadler.commons.testing.TestHelpers;
7-
import org.junit.Assume;
8-
import org.junit.Test;
8+
import org.junit.jupiter.api.Assumptions;
9+
import org.junit.jupiter.api.Test;
910

1011
import java.io.File;
1112
import java.io.IOException;
1213

13-
import static org.junit.Assert.*;
14+
import static org.junit.jupiter.api.Assertions.*;
1415

1516
public class JGitFSTest {
1617

@@ -39,8 +40,8 @@ public void testMainOneArgFileDot() {
3940

4041
@Test
4142
public void testMainOneArgDot() throws Exception {
42-
Assume.assumeFalse("Not executed on Windows for now because of https://github.com/EtiennePerot/fuse-jna/issues/40",
43-
SystemUtils.IS_OS_WINDOWS);
43+
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS,
44+
"Not executed on Windows for now because of https://github.com/EtiennePerot/fuse-jna/issues/40");
4445

4546
try {
4647
JGitFS.main("--test-only", ".");
@@ -73,8 +74,8 @@ public void testMainCurrentProject() {
7374

7475
@Test
7576
public void testMainMultiple() throws Exception {
76-
Assume.assumeFalse("Not executed on Windows for now because of https://github.com/EtiennePerot/fuse-jna/issues/44",
77-
SystemUtils.IS_OS_WINDOWS);
77+
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS,
78+
"Not executed on Windows for now because of https://github.com/EtiennePerot/fuse-jna/issues/44");
7879

7980
try {
8081
// if we have one that works and the last one an invalid one we get an exception, but did the mounting
@@ -90,7 +91,7 @@ public void testMainMultiple() throws Exception {
9091
} catch (@SuppressWarnings("unused") IOException e) {
9192
// happens when run in CloudBees, but could not find out details...
9293
} catch (IllegalStateException e) {
93-
assertTrue("Had: " + e.getMessage(), e.getMessage().contains("invalidrepo"));
94+
assertTrue(e.getMessage().contains("invalidrepo"), "Had: " + e.getMessage());
9495
}
9596
}
9697

@@ -125,9 +126,9 @@ public void testMount() throws Exception {
125126
}
126127
} catch (IOException e) {
127128
// happens when run in CloudBees, but could not find out details...
128-
Assume.assumeNoException("In some CI environments this will fail", e);
129+
Assumptions.abort("In some CI environments this will fail\n" + ExceptionUtils.getStackTrace(e));
129130
} catch (UnsatisfiedLinkError e) {
130-
Assume.assumeNoException("Will fail on Windows", e);
131+
Assumptions.abort("Will fail on Windows\n" + ExceptionUtils.getStackTrace(e));
131132
}
132133
}
133134

@@ -157,9 +158,9 @@ public void testMountGitDirTwice() throws Exception {
157158
}
158159
} catch (IOException e) {
159160
// happens when run in CloudBees, but could not find out details...
160-
Assume.assumeNoException("In some CI environments this will fail", e);
161+
Assumptions.abort("In some CI environments this will fail\n" + ExceptionUtils.getStackTrace(e));
161162
} catch (UnsatisfiedLinkError e) {
162-
Assume.assumeNoException("Will fail on Windows", e);
163+
Assumptions.abort("Will fail on Windows\n" + ExceptionUtils.getStackTrace(e));
163164
}
164165
}
165166

@@ -189,9 +190,9 @@ public void testMountPointTwice() throws Exception {
189190
}
190191
} catch (IOException e) {
191192
// happens when run in CloudBees, but could not find out details...
192-
Assume.assumeNoException("In some CI environments this will fail", e);
193+
Assumptions.abort("In some CI environments this will fail\n" + ExceptionUtils.getStackTrace(e));
193194
} catch (UnsatisfiedLinkError e) {
194-
Assume.assumeNoException("Will fail on Windows", e);
195+
Assumptions.abort("Will fail on Windows\n" + ExceptionUtils.getStackTrace(e));
195196
}
196197
}
197198
}

src/test/java/org/dstadler/jgitfs/JGitFilesystemSubmoduleTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
import net.fusejna.types.TypeMode.NodeType;
77
import org.eclipse.jgit.api.Git;
88
import org.eclipse.jgit.api.errors.GitAPIException;
9-
import org.junit.After;
10-
import org.junit.Before;
11-
import org.junit.BeforeClass;
12-
import org.junit.Test;
9+
import org.junit.jupiter.api.AfterEach;
10+
import org.junit.jupiter.api.BeforeAll;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
1313

1414
import java.io.File;
1515
import java.io.IOException;
1616
import java.nio.ByteBuffer;
1717
import java.util.ArrayList;
1818
import java.util.List;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2222

2323
public class JGitFilesystemSubmoduleTest {
2424
private static final String CLONE_URL = "https://github.com/githubtraining/example-dependency.git";
@@ -28,7 +28,7 @@ public class JGitFilesystemSubmoduleTest {
2828

2929
private JGitFilesystem fs;
3030

31-
@BeforeClass
31+
@BeforeAll
3232
public static void setUpClass() throws GitAPIException {
3333
// clone sample repo if not available yet
3434
if (!CLONE_DIR.exists()) {
@@ -42,12 +42,12 @@ public static void setUpClass() throws GitAPIException {
4242
}
4343
}
4444

45-
@Before
45+
@BeforeEach
4646
public void setUp() throws IOException {
4747
fs = new JGitFilesystem(CLONE_DIR.getAbsolutePath(), false);
4848
}
4949

50-
@After
50+
@AfterEach
5151
public void tearDown() throws IOException {
5252
fs.close();
5353
}
@@ -57,8 +57,7 @@ public void testSimple() {
5757
ByteBuffer buffer = ByteBuffer.allocate(1000);
5858
assertEquals(0, fs.readlink("/branch/master", buffer, 1000));
5959

60-
assertEquals("A commit-ish link should be written to the buffer, but had: " + new String(buffer.array(), 0, buffer.position()),
61-
1000 - 51, buffer.remaining());
60+
assertEquals(1000 - 51, buffer.remaining(), "A commit-ish link should be written to the buffer, but had: " + new String(buffer.array(), 0, buffer.position()));
6261
// e.g. ../commit/43/27273e69afcd040ba1b4d3766ea1f43e0024f3
6362
String commit = new String(buffer.array(), 0, buffer.position()).substring(2);
6463

@@ -78,15 +77,14 @@ public void testSubmodulesGitLink() {
7877
ByteBuffer buffer = ByteBuffer.allocate(1000);
7978

8079
assertEquals(0, fs.readlink("/branch/master", buffer, 1000));
81-
assertEquals("A commit-ish link should be written to the buffer, but had: " + new String(buffer.array(), 0, buffer.position()),
82-
1000 - 51, buffer.remaining());
80+
assertEquals(1000 - 51, buffer.remaining(), "A commit-ish link should be written to the buffer, but had: " + new String(buffer.array(), 0, buffer.position()));
8381
// e.g. ../commit/43/27273e69afcd040ba1b4d3766ea1f43e0024f3
8482
String commit = new String(buffer.array(), 0, buffer.position()).substring(2);
8583

8684
// check that we can read the gitlink
8785
buffer = ByteBuffer.allocate(1000);
8886
assertEquals(0, fs.readlink(commit + "/js", buffer, 1000));
89-
assertEquals("Incorrect number of bytes written to the buffer", 930, buffer.remaining());
87+
assertEquals(930, buffer.remaining(), "Incorrect number of bytes written to the buffer");
9088

9189
assertEquals("../../../submodule/js/commit/c3/c588713233609f5bbbb2d9e7f3fb4a660f3f72",
9290
new String(buffer.array(), 0, buffer.position()));

0 commit comments

Comments
 (0)