46
46
import static org .mockito .Mockito .verify ;
47
47
48
48
@ ExtendWith (MockitoExtension .class )
49
- public class DefaultMethodSecurityExpressionHandlerTests {
49
+ class DefaultMethodSecurityExpressionHandlerTests {
50
50
51
51
private DefaultMethodSecurityExpressionHandler handler ;
52
52
@@ -75,12 +75,12 @@ public void cleanup() {
75
75
}
76
76
77
77
@ Test
78
- public void setTrustResolverNull () {
78
+ void setTrustResolverNull () {
79
79
assertThatIllegalArgumentException ().isThrownBy (() -> this .handler .setTrustResolver (null ));
80
80
}
81
81
82
82
@ Test
83
- public void createEvaluationContextCustomTrustResolver () {
83
+ void createEvaluationContextCustomTrustResolver () {
84
84
setupMocks ();
85
85
this .handler .setTrustResolver (this .trustResolver );
86
86
Expression expression = this .handler .getExpressionParser ().parseExpression ("anonymous" );
@@ -91,7 +91,7 @@ public void createEvaluationContextCustomTrustResolver() {
91
91
92
92
@ Test
93
93
@ SuppressWarnings ("unchecked" )
94
- public void filterByKeyWhenUsingMapThenFiltersMap () {
94
+ void filterByKeyWhenUsingMapThenFiltersMap () {
95
95
setupMocks ();
96
96
final Map <String , String > map = new HashMap <>();
97
97
map .put ("key1" , "value1" );
@@ -100,16 +100,16 @@ public void filterByKeyWhenUsingMapThenFiltersMap() {
100
100
Expression expression = this .handler .getExpressionParser ().parseExpression ("filterObject.key eq 'key2'" );
101
101
EvaluationContext context = this .handler .createEvaluationContext (this .authentication , this .methodInvocation );
102
102
Object filtered = this .handler .filter (map , expression , context );
103
- assertThat (filtered == map );
103
+ assertThat (filtered ). isSameAs ( map );
104
104
Map <String , String > result = ((Map <String , String >) filtered );
105
- assertThat (result . size () == 1 );
106
- assertThat ( result ). containsKey ("key2" );
107
- assertThat ( result ) .containsValue ("value2" );
105
+ assertThat (result ). hasSize ( 1 )
106
+ . containsOnlyKeys ("key2" )
107
+ .containsValue ("value2" );
108
108
}
109
109
110
110
@ Test
111
111
@ SuppressWarnings ("unchecked" )
112
- public void filterByValueWhenUsingMapThenFiltersMap () {
112
+ void filterByValueWhenUsingMapThenFiltersMap () {
113
113
setupMocks ();
114
114
final Map <String , String > map = new HashMap <>();
115
115
map .put ("key1" , "value1" );
@@ -118,16 +118,16 @@ public void filterByValueWhenUsingMapThenFiltersMap() {
118
118
Expression expression = this .handler .getExpressionParser ().parseExpression ("filterObject.value eq 'value3'" );
119
119
EvaluationContext context = this .handler .createEvaluationContext (this .authentication , this .methodInvocation );
120
120
Object filtered = this .handler .filter (map , expression , context );
121
- assertThat (filtered == map );
121
+ assertThat (filtered ). isSameAs ( map );
122
122
Map <String , String > result = ((Map <String , String >) filtered );
123
- assertThat (result . size () == 1 );
124
- assertThat ( result ). containsKey ("key3" );
125
- assertThat ( result ) .containsValue ("value3" );
123
+ assertThat (result ). hasSize ( 1 )
124
+ . containsOnlyKeys ("key3" )
125
+ .containsValue ("value3" );
126
126
}
127
127
128
128
@ Test
129
129
@ SuppressWarnings ("unchecked" )
130
- public void filterByKeyAndValueWhenUsingMapThenFiltersMap () {
130
+ void filterByKeyAndValueWhenUsingMapThenFiltersMap () {
131
131
setupMocks ();
132
132
final Map <String , String > map = new HashMap <>();
133
133
map .put ("key1" , "value1" );
@@ -137,16 +137,16 @@ public void filterByKeyAndValueWhenUsingMapThenFiltersMap() {
137
137
.parseExpression ("(filterObject.key eq 'key1') or (filterObject.value eq 'value2')" );
138
138
EvaluationContext context = this .handler .createEvaluationContext (this .authentication , this .methodInvocation );
139
139
Object filtered = this .handler .filter (map , expression , context );
140
- assertThat (filtered == map );
140
+ assertThat (filtered ). isSameAs ( map );
141
141
Map <String , String > result = ((Map <String , String >) filtered );
142
- assertThat (result . size () == 2 );
143
- assertThat ( result ). containsKeys ("key1" , "key2" );
144
- assertThat ( result ) .containsValues ("value1" , "value2" );
142
+ assertThat (result ). hasSize ( 2 )
143
+ . containsOnlyKeys ("key1" , "key2" )
144
+ .containsValues ("value1" , "value2" );
145
145
}
146
146
147
147
@ Test
148
148
@ SuppressWarnings ("unchecked" )
149
- public void filterWhenUsingStreamThenFiltersStream () {
149
+ void filterWhenUsingStreamThenFiltersStream () {
150
150
setupMocks ();
151
151
final Stream <String > stream = Stream .of ("1" , "2" , "3" );
152
152
Expression expression = this .handler .getExpressionParser ().parseExpression ("filterObject ne '2'" );
@@ -158,19 +158,19 @@ public void filterWhenUsingStreamThenFiltersStream() {
158
158
}
159
159
160
160
@ Test
161
- public void filterStreamWhenClosedThenUpstreamGetsClosed () {
161
+ void filterStreamWhenClosedThenUpstreamGetsClosed () {
162
162
setupMocks ();
163
163
final Stream <?> upstream = mock (Stream .class );
164
164
doReturn (Stream .<String >empty ()).when (upstream ).filter (any ());
165
165
Expression expression = this .handler .getExpressionParser ().parseExpression ("true" );
166
166
EvaluationContext context = this .handler .createEvaluationContext (this .authentication , this .methodInvocation );
167
- ((Stream ) this .handler .filter (upstream , expression , context )).close ();
167
+ ((Stream <?> ) this .handler .filter (upstream , expression , context )).close ();
168
168
verify (upstream ).close ();
169
169
}
170
170
171
171
@ Test
172
172
@ SuppressWarnings ("unchecked" )
173
- public void filterMatchingOptional () {
173
+ void filterMatchingOptional () {
174
174
final Optional <String > optional = Optional .of ("1" );
175
175
Expression expression = this .handler .getExpressionParser ().parseExpression ("filterObject ne '2'" );
176
176
EvaluationContext context = this .handler .createEvaluationContext (this .authentication , this .methodInvocation );
@@ -181,7 +181,7 @@ public void filterMatchingOptional() {
181
181
182
182
@ Test
183
183
@ SuppressWarnings ("unchecked" )
184
- public void filterNotMatchingOptional () {
184
+ void filterNotMatchingOptional () {
185
185
final Optional <String > optional = Optional .of ("2" );
186
186
Expression expression = this .handler .getExpressionParser ().parseExpression ("filterObject ne '2'" );
187
187
EvaluationContext context = this .handler .createEvaluationContext (this .authentication , this .methodInvocation );
@@ -192,7 +192,7 @@ public void filterNotMatchingOptional() {
192
192
193
193
@ Test
194
194
@ SuppressWarnings ("unchecked" )
195
- public void filterEmptyOptional () {
195
+ void filterEmptyOptional () {
196
196
final Optional <String > optional = Optional .empty ();
197
197
Expression expression = this .handler .getExpressionParser ().parseExpression ("filterObject ne '2'" );
198
198
EvaluationContext context = this .handler .createEvaluationContext (this .authentication , this .methodInvocation );
0 commit comments