22
22
import java .util .concurrent .TimeUnit ;
23
23
24
24
import org .junit .Test ;
25
+ import org .junit .jupiter .api .Assertions ;
26
+ import org .junit .jupiter .api .function .Executable ;
25
27
import reactor .core .publisher .MonoProcessor ;
26
28
27
29
import org .springframework .http .CacheControl ;
33
35
import org .springframework .mock .http .client .reactive .MockClientHttpResponse ;
34
36
35
37
import static org .hamcrest .CoreMatchers .*;
36
- import static org .junit .Assert .*;
38
+ import static org .junit .jupiter . api . Assertions .*;
37
39
import static org .mockito .Mockito .*;
38
40
39
41
/**
@@ -51,32 +53,11 @@ public void valueEquals() {
51
53
headers .add ("foo" , "bar" );
52
54
HeaderAssertions assertions = headerAssertions (headers );
53
55
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" ));
64
57
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" );
80
61
}
81
62
82
63
@ Test
@@ -104,7 +85,6 @@ public void valueEqualsWithMultipeValues() {
104
85
catch (AssertionError error ) {
105
86
// expected
106
87
}
107
-
108
88
}
109
89
110
90
@ Test
@@ -263,4 +243,8 @@ private HeaderAssertions headerAssertions(HttpHeaders responseHeaders) {
263
243
return new HeaderAssertions (result , mock (WebTestClient .ResponseSpec .class ));
264
244
}
265
245
246
+ public static AssertionError assertThrows (Executable executable , String message ) {
247
+ return Assertions .assertThrows (AssertionError .class , executable , message );
248
+ }
249
+
266
250
}
0 commit comments