16
16
17
17
package org .springframework .security .oauth2 .resourceserver ;
18
18
19
- import org .junit .Rule ;
20
19
import org .junit .Test ;
21
- import org . junit . rules . ExpectedException ;
20
+
22
21
import org .springframework .http .HttpStatus ;
23
22
24
23
import static org .assertj .core .api .Assertions .assertThat ;
24
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
25
25
26
26
/**
27
27
* Tests for {@link BearerTokenError}.
@@ -40,9 +40,6 @@ public class BearerTokenErrorTests {
40
40
41
41
private static final String TEST_SCOPE = "test-scope" ;
42
42
43
- @ Rule
44
- public ExpectedException thrown = ExpectedException .none ();
45
-
46
43
@ Test
47
44
public void constructorWithErrorCodeWhenErrorCodeIsValidThenCreated () {
48
45
BearerTokenError error = new BearerTokenError (TEST_ERROR_CODE , TEST_HTTP_STATUS );
@@ -56,26 +53,20 @@ public void constructorWithErrorCodeWhenErrorCodeIsValidThenCreated() {
56
53
57
54
@ Test
58
55
public void constructorWithErrorCodeAndHttpStatusWhenErrorCodeIsNullThenThrowIllegalArgumentException () {
59
- this .thrown .expect (IllegalArgumentException .class );
60
- this .thrown .expectMessage ("errorCode cannot be empty" );
61
-
62
- new BearerTokenError (null , TEST_HTTP_STATUS );
56
+ assertThatThrownBy (() -> new BearerTokenError (null , TEST_HTTP_STATUS ))
57
+ .isInstanceOf (IllegalArgumentException .class ).hasMessage ("errorCode cannot be empty" );
63
58
}
64
59
65
60
@ Test
66
61
public void constructorWithErrorCodeAndHttpStatusWhenErrorCodeIsEmptyThenThrowIllegalArgumentException () {
67
- this .thrown .expect (IllegalArgumentException .class );
68
- this .thrown .expectMessage ("errorCode cannot be empty" );
69
-
70
- new BearerTokenError ("" , TEST_HTTP_STATUS );
62
+ assertThatThrownBy (() -> new BearerTokenError ("" , TEST_HTTP_STATUS ))
63
+ .isInstanceOf (IllegalArgumentException .class ).hasMessage ("errorCode cannot be empty" );
71
64
}
72
65
73
66
@ Test
74
67
public void constructorWithErrorCodeAndHttpStatusWhenHttpStatusIsNullThenThrowIllegalArgumentException () {
75
- this .thrown .expect (IllegalArgumentException .class );
76
- this .thrown .expectMessage ("httpStatus must not be null" );
77
-
78
- new BearerTokenError (TEST_ERROR_CODE , null );
68
+ assertThatThrownBy (() -> new BearerTokenError (TEST_ERROR_CODE , null ))
69
+ .isInstanceOf (IllegalArgumentException .class ).hasMessage ("httpStatus must not be null" );
79
70
}
80
71
81
72
@ Test
@@ -92,26 +83,20 @@ public void constructorWithAllParametersWhenAllParametersAreValidThenCreated() {
92
83
93
84
@ Test
94
85
public void constructorWithAllParametersWhenErrorCodeIsNullThenThrowIllegalArgumentException () {
95
- this .thrown .expect (IllegalArgumentException .class );
96
- this .thrown .expectMessage ("errorCode cannot be empty" );
97
-
98
- new BearerTokenError (null , TEST_HTTP_STATUS , TEST_DESCRIPTION , TEST_URI , TEST_SCOPE );
86
+ assertThatThrownBy (() -> new BearerTokenError (null , TEST_HTTP_STATUS , TEST_DESCRIPTION , TEST_URI , TEST_SCOPE ))
87
+ .isInstanceOf (IllegalArgumentException .class ).hasMessage ("errorCode cannot be empty" );
99
88
}
100
89
101
90
@ Test
102
91
public void constructorWithAllParametersWhenErrorCodeIsEmptyThenThrowIllegalArgumentException () {
103
- this .thrown .expect (IllegalArgumentException .class );
104
- this .thrown .expectMessage ("errorCode cannot be empty" );
105
-
106
- new BearerTokenError ("" , TEST_HTTP_STATUS , TEST_DESCRIPTION , TEST_URI , TEST_SCOPE );
92
+ assertThatThrownBy (() -> new BearerTokenError ("" , TEST_HTTP_STATUS , TEST_DESCRIPTION , TEST_URI , TEST_SCOPE ))
93
+ .isInstanceOf (IllegalArgumentException .class ).hasMessage ("errorCode cannot be empty" );
107
94
}
108
95
109
96
@ Test
110
97
public void constructorWithAllParametersWhenHttpStatusIsNullThenThrowIllegalArgumentException () {
111
- this .thrown .expect (IllegalArgumentException .class );
112
- this .thrown .expectMessage ("httpStatus must not be null" );
113
-
114
- new BearerTokenError (TEST_ERROR_CODE , null , TEST_DESCRIPTION , TEST_URI , TEST_SCOPE );
98
+ assertThatThrownBy (() -> new BearerTokenError (TEST_ERROR_CODE , null , TEST_DESCRIPTION , TEST_URI , TEST_SCOPE ))
99
+ .isInstanceOf (IllegalArgumentException .class ).hasMessage ("httpStatus must not be null" );
115
100
}
116
101
117
102
}
0 commit comments