Skip to content

Commit 18068c9

Browse files
kmw10693rwinch
authored andcommitted
fix compile warning in spring-security-test
Signed-off-by: Minu Kim <kmw106933@naver.com>
1 parent a539f05 commit 18068c9

8 files changed

Lines changed: 47 additions & 9 deletions

File tree

config/src/test/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ public void loadConfigWhenMultipleWebSecurityConfigurationThenContextLoads() {
222222
// SEC-2773
223223
@Test
224224
public void getMethodDelegatingApplicationListenerWhenWebSecurityConfigurationThenIsStatic() {
225-
Method method = ClassUtils.getMethod(WebSecurityConfiguration.class, "delegatingApplicationListener", null);
225+
Method method = ClassUtils.getMethod(WebSecurityConfiguration.class, "delegatingApplicationListener",
226+
(Class<?>[]) null);
226227
assertThat(Modifier.isStatic(method.getModifiers())).isTrue();
227228
}
228229

core/src/test/java/org/springframework/security/authentication/ott/OneTimeTokenAuthenticationTokenTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class OneTimeTokenAuthenticationTokenTests {
3131

3232
// gh-18095
3333
@Test
34+
@SuppressWarnings("removal")
3435
void shouldBeAbleToDeserializeFromJsonWithDefaultTypingActivated() throws IOException {
3536
ObjectMapper mapper = new ObjectMapper();
3637
mapper.registerModules(SecurityJackson2Modules.getModules(getClass().getClassLoader()));

core/src/test/java/org/springframework/security/authentication/ott/reactive/OneTimeTokenReactiveAuthenticationManagerTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
5959
private static final String TOKEN = "token";
6060

6161
@Test
62+
@SuppressWarnings("removal")
6263
public void constructorWhenOneTimeTokenServiceNullThenIllegalArgumentException() {
6364
ReactiveUserDetailsService userDetailsService = mock(ReactiveUserDetailsService.class);
6465
// @formatter:off
@@ -68,6 +69,7 @@ public void constructorWhenOneTimeTokenServiceNullThenIllegalArgumentException()
6869
}
6970

7071
@Test
72+
@SuppressWarnings("removal")
7173
public void constructorWhenUserDetailsServiceNullThenIllegalArgumentException() {
7274
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
7375
// @formatter:off
@@ -77,6 +79,7 @@ public void constructorWhenUserDetailsServiceNullThenIllegalArgumentException()
7779
}
7880

7981
@Test
82+
@SuppressWarnings("removal")
8083
void authenticateWhenOneTimeTokenAuthenticationTokenIsPresentThenSuccess() {
8184
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
8285
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
@@ -103,6 +106,7 @@ void authenticateWhenOneTimeTokenAuthenticationTokenIsPresentThenSuccess() {
103106
}
104107

105108
@Test
109+
@SuppressWarnings("removal")
106110
void authenticateWhenInvalidOneTimeTokenAuthenticationTokenIsPresentThenFail() {
107111
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
108112
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
@@ -120,6 +124,7 @@ void authenticateWhenInvalidOneTimeTokenAuthenticationTokenIsPresentThenFail() {
120124
}
121125

122126
@Test
127+
@SuppressWarnings("removal")
123128
void authenticateWhenIncorrectTypeOfAuthenticationIsPresentThenFail() {
124129
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
125130
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))

core/src/test/java/org/springframework/security/authorization/AuthorityAuthorizationManagerTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void hasAuthorityWhenNullThenException() {
6161

6262
@Test
6363
public void hasAnyRoleWhenNullThenException() {
64-
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(null))
64+
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole((String[]) null))
6565
.withMessage("roles cannot be empty");
6666
}
6767

@@ -97,7 +97,8 @@ public void hasAnyRoleWhenContainRoleWithRolePrefixThenException() {
9797

9898
@Test
9999
public void hasAnyAuthorityWhenNullThenException() {
100-
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority(null))
100+
assertThatIllegalArgumentException()
101+
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority((String[]) null))
101102
.withMessage("authorities cannot be empty");
102103
}
103104

core/src/test/kotlin/org/springframework/security/access/expression/method/DefaultMethodSecurityExpressionHandlerKotlinTests.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
7373
)
7474

7575
assertThat(filtered).isInstanceOf(Map::class.java)
76-
val result = (filtered as Map<String, String>)
76+
@Suppress("UNCHECKED_CAST")
77+
val result = filtered as Map<String, String>
7778
assertThat(result).hasSize(1)
7879
assertThat(result).containsKey("key2")
7980
assertThat(result).containsValue("value2")
@@ -95,7 +96,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
9596
)
9697

9798
assertThat(filtered).isInstanceOf(Map::class.java)
98-
val result = (filtered as Map<String, String>)
99+
@Suppress("UNCHECKED_CAST")
100+
val result = filtered as Map<String, String>
99101
assertThat(result).hasSize(0)
100102
}
101103

@@ -119,7 +121,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
119121
)
120122

121123
assertThat(filtered).isInstanceOf(Collection::class.java)
122-
val result = (filtered as Collection<String>)
124+
@Suppress("UNCHECKED_CAST")
125+
val result = filtered as Collection<String>
123126
assertThat(result).hasSize(1)
124127
assertThat(result).contains("string2")
125128
}
@@ -140,7 +143,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
140143
)
141144

142145
assertThat(filtered).isInstanceOf(Collection::class.java)
143-
val result = (filtered as Collection<String>)
146+
@Suppress("UNCHECKED_CAST")
147+
val result = filtered as Collection<String>
144148
assertThat(result).hasSize(0)
145149
}
146150

@@ -164,7 +168,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
164168
)
165169

166170
assertThat(filtered).isInstanceOf(Array<String>::class.java)
167-
val result = (filtered as Array<String>)
171+
@Suppress("UNCHECKED_CAST")
172+
val result = filtered as Array<String>
168173
assertThat(result).hasSize(1)
169174
assertThat(result).contains("string2")
170175
}
@@ -185,7 +190,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
185190
)
186191

187192
assertThat(filtered).isInstanceOf(Array<String>::class.java)
188-
val result = (filtered as Array<String>)
193+
@Suppress("UNCHECKED_CAST")
194+
val result = filtered as Array<String>
189195
assertThat(result).hasSize(0)
190196
}
191197

@@ -209,6 +215,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
209215
)
210216

211217
assertThat(filtered).isInstanceOf(Stream::class.java)
218+
@Suppress("UNCHECKED_CAST")
212219
val result = (filtered as Stream<String>).toList()
213220
assertThat(result).hasSize(1)
214221
assertThat(result).contains("string2")
@@ -230,6 +237,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
230237
)
231238

232239
assertThat(filtered).isInstanceOf(Stream::class.java)
240+
@Suppress("UNCHECKED_CAST")
233241
val result = (filtered as Stream<String>).toList()
234242
assertThat(result).hasSize(0)
235243
}

test/spring-security-test.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'security-nullability'
33
id 'javadoc-warnings-error'
4+
id 'compile-warnings-error'
45
}
56

67
apply plugin: 'io.spring.convention.spring-module'

web/src/test/java/org/springframework/security/web/authentication/DelegatingAuthenticationEntryPointTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void before() {
6565
}
6666

6767
@Test
68+
@SuppressWarnings("removal")
6869
public void testDefaultEntryPoint() throws Exception {
6970
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
7071
RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -78,6 +79,7 @@ public void testDefaultEntryPoint() throws Exception {
7879
}
7980

8081
@Test
82+
@SuppressWarnings("removal")
8183
public void testFirstEntryPoint() throws Exception {
8284
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
8385
RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -96,6 +98,7 @@ public void testFirstEntryPoint() throws Exception {
9698
}
9799

98100
@Test
101+
@SuppressWarnings("removal")
99102
public void testSecondEntryPoint() throws Exception {
100103
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
101104
RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -114,20 +117,23 @@ public void testSecondEntryPoint() throws Exception {
114117
}
115118

116119
@Test
120+
@SuppressWarnings("removal")
117121
public void constructorAepListWhenNullEntryPoints() {
118122
List<RequestMatcherEntry<AuthenticationEntryPoint>> entryPoints = null;
119123
assertThatIllegalArgumentException().isThrownBy(
120124
() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class), entryPoints));
121125
}
122126

123127
@Test
128+
@SuppressWarnings("removal")
124129
public void constructorAepListWhenEmptyEntryPoints() {
125130
assertThatIllegalArgumentException()
126131
.isThrownBy(() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class),
127132
Collections.emptyList()));
128133
}
129134

130135
@Test
136+
@SuppressWarnings("removal")
131137
public void constructorAepListWhenNullDefaultEntryPoint() {
132138
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
133139
RequestMatcher matcher = mock(RequestMatcher.class);
@@ -138,20 +144,23 @@ public void constructorAepListWhenNullDefaultEntryPoint() {
138144
}
139145

140146
@Test
147+
@SuppressWarnings("removal")
141148
public void constructorAepVargsWhenNullEntryPoints() {
142149
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = null;
143150
assertThatIllegalArgumentException().isThrownBy(
144151
() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class), entryPoints));
145152
}
146153

147154
@Test
155+
@SuppressWarnings("removal")
148156
public void constructorAepVargsWhenEmptyEntryPoints() {
149157
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = new RequestMatcherEntry[0];
150158
assertThatIllegalArgumentException().isThrownBy(
151159
() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class), entryPoints));
152160
}
153161

154162
@Test
163+
@SuppressWarnings("removal")
155164
public void constructorAepVargsWhenNullDefaultEntryPoint() {
156165
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
157166
RequestMatcher matcher = mock(RequestMatcher.class);
@@ -162,6 +171,7 @@ public void constructorAepVargsWhenNullDefaultEntryPoint() {
162171
}
163172

164173
@Test
174+
@SuppressWarnings("removal")
165175
public void commenceWhenNoMatchThenDefaultEntryPoint() throws Exception {
166176
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
167177
RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -174,6 +184,7 @@ public void commenceWhenNoMatchThenDefaultEntryPoint() throws Exception {
174184
}
175185

176186
@Test
187+
@SuppressWarnings("removal")
177188
public void commenceWhenMatchFirstEntryPointThenOthersNotInvoked() throws Exception {
178189
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
179190
RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -192,6 +203,7 @@ public void commenceWhenMatchFirstEntryPointThenOthersNotInvoked() throws Except
192203
}
193204

194205
@Test
206+
@SuppressWarnings("removal")
195207
public void commenceWhenSecondMatchesThenDefaultNotInvoked() throws Exception {
196208
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
197209
RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -220,6 +232,7 @@ void builderWhenDefaultNullAndSingleEntryPointThenReturnsSingle() {
220232
}
221233

222234
@Test
235+
@SuppressWarnings("removal")
223236
void builderWhenDefaultNullThenFirstIsDefault() throws ServletException, IOException {
224237
AuthenticationEntryPoint firstEntryPoint = mock(AuthenticationEntryPoint.class);
225238
AuthenticationEntryPoint secondEntryPoint = mock(AuthenticationEntryPoint.class);
@@ -237,6 +250,7 @@ void builderWhenDefaultNullThenFirstIsDefault() throws ServletException, IOExcep
237250
}
238251

239252
@Test
253+
@SuppressWarnings("removal")
240254
void builderWhenDefaultAndEmptyEntryPointsThenReturnsDefault() {
241255
AuthenticationEntryPoint defaultEntryPoint = mock(AuthenticationEntryPoint.class);
242256

@@ -248,6 +262,7 @@ void builderWhenDefaultAndEmptyEntryPointsThenReturnsDefault() {
248262
}
249263

250264
@Test
265+
@SuppressWarnings("removal")
251266
void builderWhenNoEntryPointsThenIllegalStateException() {
252267
DelegatingAuthenticationEntryPoint.Builder builder = DelegatingAuthenticationEntryPoint.builder();
253268
assertThatIllegalStateException().isThrownBy(builder::build);

web/src/test/java/org/springframework/security/web/authentication/ott/OneTimeTokenAuthenticationFilterTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ void setUp() {
7070
}
7171

7272
@Test
73+
@SuppressWarnings("removal")
7374
void setAuthenticationConverterWhenNullThenIllegalArgumentException() {
7475
assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setAuthenticationConverter(null));
7576
}
7677

7778
@Test
79+
@SuppressWarnings("removal")
7880
void doFilterWhenUrlDoesNotMatchThenContinues() throws ServletException, IOException {
7981
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
8082
HttpServletResponse response = mock(HttpServletResponse.class);
@@ -85,6 +87,7 @@ void doFilterWhenUrlDoesNotMatchThenContinues() throws ServletException, IOExcep
8587
}
8688

8789
@Test
90+
@SuppressWarnings("removal")
8891
void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOException {
8992
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
9093
HttpServletResponse response = mock(HttpServletResponse.class);
@@ -95,13 +98,15 @@ void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOEx
9598
}
9699

97100
@Test
101+
@SuppressWarnings("removal")
98102
void doFilterWhenMissingTokenThenPropagatesRequest() throws ServletException, IOException {
99103
FilterChain chain = mock(FilterChain.class);
100104
this.filter.doFilter(post("/login/ott").buildRequest(new MockServletContext()), this.response, chain);
101105
verify(chain).doFilter(any(), any());
102106
}
103107

104108
@Test
109+
@SuppressWarnings("removal")
105110
void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOException {
106111
given(this.authenticationManager.authenticate(any())).willThrow(new BadCredentialsException("invalid token"));
107112
this.filter.doFilter(
@@ -112,6 +117,7 @@ void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOExcep
112117
}
113118

114119
@Test
120+
@SuppressWarnings("removal")
115121
void doFilterWhenValidThenRedirectsToSavedRequest() throws ServletException, IOException {
116122
given(this.authenticationManager.authenticate(any()))
117123
.willReturn(OneTimeTokenAuthenticationToken.authenticated("username", AuthorityUtils.NO_AUTHORITIES));

0 commit comments

Comments
 (0)