Skip to content

Commit fd352b8

Browse files
committed
PoC: migrate from JUnit 4 to JUnit Jupiter Assertions
1 parent 8658a35 commit fd352b8

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.concurrent.TimeUnit;
2323

2424
import org.junit.Test;
25+
import org.junit.jupiter.api.Assertions;
26+
import org.junit.jupiter.api.function.Executable;
2527
import reactor.core.publisher.MonoProcessor;
2628

2729
import org.springframework.http.CacheControl;
@@ -33,7 +35,7 @@
3335
import org.springframework.mock.http.client.reactive.MockClientHttpResponse;
3436

3537
import static org.hamcrest.CoreMatchers.*;
36-
import static org.junit.Assert.*;
38+
import static org.junit.jupiter.api.Assertions.*;
3739
import static org.mockito.Mockito.*;
3840

3941
/**
@@ -51,32 +53,11 @@ public void valueEquals() {
5153
headers.add("foo", "bar");
5254
HeaderAssertions assertions = headerAssertions(headers);
5355

54-
// Success
55-
assertions.valueEquals("foo", "bar");
56-
57-
try {
58-
assertions.valueEquals("what?!", "bar");
59-
fail("Missing header expected");
60-
}
61-
catch (AssertionError error) {
62-
// expected
63-
}
56+
assertDoesNotThrow(() -> assertions.valueEquals("foo", "bar"));
6457

65-
try {
66-
assertions.valueEquals("foo", "what?!");
67-
fail("Wrong value expected");
68-
}
69-
catch (AssertionError error) {
70-
// expected
71-
}
72-
73-
try {
74-
assertions.valueEquals("foo", "bar", "what?!");
75-
fail("Wrong # of values expected");
76-
}
77-
catch (AssertionError error) {
78-
// expected
79-
}
58+
assertThrows(() -> assertions.valueEquals("what?!", "bar"), "Missing header expected");
59+
assertThrows(() -> assertions.valueEquals("foo", "what?!"), "Wrong value expected");
60+
assertThrows(() -> assertions.valueEquals("foo", "bar", "what?!"), "Wrong # of values expected");
8061
}
8162

8263
@Test
@@ -104,7 +85,6 @@ public void valueEqualsWithMultipeValues() {
10485
catch (AssertionError error) {
10586
// expected
10687
}
107-
10888
}
10989

11090
@Test
@@ -263,4 +243,8 @@ private HeaderAssertions headerAssertions(HttpHeaders responseHeaders) {
263243
return new HeaderAssertions(result, mock(WebTestClient.ResponseSpec.class));
264244
}
265245

246+
public static AssertionError assertThrows(Executable executable, String message) {
247+
return Assertions.assertThrows(AssertionError.class, executable, message);
248+
}
249+
266250
}

0 commit comments

Comments
 (0)