fix compile warning in spring-security-test

Signed-off-by: Minu Kim <kmw106933@naver.com>
This commit is contained in:
Minu Kim 2026-01-26 23:50:41 +09:00 committed by Rob Winch
parent a539f056f7
commit 18068c9099
8 changed files with 47 additions and 9 deletions

View File

@ -222,7 +222,8 @@ public class WebSecurityConfigurationTests {
// SEC-2773
@Test
public void getMethodDelegatingApplicationListenerWhenWebSecurityConfigurationThenIsStatic() {
Method method = ClassUtils.getMethod(WebSecurityConfiguration.class, "delegatingApplicationListener", null);
Method method = ClassUtils.getMethod(WebSecurityConfiguration.class, "delegatingApplicationListener",
(Class<?>[]) null);
assertThat(Modifier.isStatic(method.getModifiers())).isTrue();
}

View File

@ -31,6 +31,7 @@ class OneTimeTokenAuthenticationTokenTests {
// gh-18095
@Test
@SuppressWarnings("removal")
void shouldBeAbleToDeserializeFromJsonWithDefaultTypingActivated() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModules(SecurityJackson2Modules.getModules(getClass().getClassLoader()));

View File

@ -59,6 +59,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
private static final String TOKEN = "token";
@Test
@SuppressWarnings("removal")
public void constructorWhenOneTimeTokenServiceNullThenIllegalArgumentException() {
ReactiveUserDetailsService userDetailsService = mock(ReactiveUserDetailsService.class);
// @formatter:off
@ -68,6 +69,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
}
@Test
@SuppressWarnings("removal")
public void constructorWhenUserDetailsServiceNullThenIllegalArgumentException() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
// @formatter:off
@ -77,6 +79,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
}
@Test
@SuppressWarnings("removal")
void authenticateWhenOneTimeTokenAuthenticationTokenIsPresentThenSuccess() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
@ -103,6 +106,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
}
@Test
@SuppressWarnings("removal")
void authenticateWhenInvalidOneTimeTokenAuthenticationTokenIsPresentThenFail() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
@ -120,6 +124,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
}
@Test
@SuppressWarnings("removal")
void authenticateWhenIncorrectTypeOfAuthenticationIsPresentThenFail() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))

View File

@ -61,7 +61,7 @@ public class AuthorityAuthorizationManagerTests {
@Test
public void hasAnyRoleWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(null))
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole((String[]) null))
.withMessage("roles cannot be empty");
}
@ -97,7 +97,8 @@ public class AuthorityAuthorizationManagerTests {
@Test
public void hasAnyAuthorityWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority(null))
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority((String[]) null))
.withMessage("authorities cannot be empty");
}

View File

@ -73,7 +73,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Map::class.java)
val result = (filtered as Map<String, String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Map<String, String>
assertThat(result).hasSize(1)
assertThat(result).containsKey("key2")
assertThat(result).containsValue("value2")
@ -95,7 +96,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Map::class.java)
val result = (filtered as Map<String, String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Map<String, String>
assertThat(result).hasSize(0)
}
@ -119,7 +121,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Collection::class.java)
val result = (filtered as Collection<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Collection<String>
assertThat(result).hasSize(1)
assertThat(result).contains("string2")
}
@ -140,7 +143,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Collection::class.java)
val result = (filtered as Collection<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Collection<String>
assertThat(result).hasSize(0)
}
@ -164,7 +168,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Array<String>::class.java)
val result = (filtered as Array<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Array<String>
assertThat(result).hasSize(1)
assertThat(result).contains("string2")
}
@ -185,7 +190,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Array<String>::class.java)
val result = (filtered as Array<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Array<String>
assertThat(result).hasSize(0)
}
@ -209,6 +215,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Stream::class.java)
@Suppress("UNCHECKED_CAST")
val result = (filtered as Stream<String>).toList()
assertThat(result).hasSize(1)
assertThat(result).contains("string2")
@ -230,6 +237,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)
assertThat(filtered).isInstanceOf(Stream::class.java)
@Suppress("UNCHECKED_CAST")
val result = (filtered as Stream<String>).toList()
assertThat(result).hasSize(0)
}

View File

@ -1,6 +1,7 @@
plugins {
id 'security-nullability'
id 'javadoc-warnings-error'
id 'compile-warnings-error'
}
apply plugin: 'io.spring.convention.spring-module'

View File

@ -65,6 +65,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void testDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
@ -78,6 +79,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void testFirstEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
@ -96,6 +98,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void testSecondEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
@ -114,6 +117,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void constructorAepListWhenNullEntryPoints() {
List<RequestMatcherEntry<AuthenticationEntryPoint>> entryPoints = null;
assertThatIllegalArgumentException().isThrownBy(
@ -121,6 +125,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void constructorAepListWhenEmptyEntryPoints() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class),
@ -128,6 +133,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void constructorAepListWhenNullDefaultEntryPoint() {
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
RequestMatcher matcher = mock(RequestMatcher.class);
@ -138,6 +144,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenNullEntryPoints() {
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = null;
assertThatIllegalArgumentException().isThrownBy(
@ -145,6 +152,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenEmptyEntryPoints() {
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = new RequestMatcherEntry[0];
assertThatIllegalArgumentException().isThrownBy(
@ -152,6 +160,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenNullDefaultEntryPoint() {
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
RequestMatcher matcher = mock(RequestMatcher.class);
@ -162,6 +171,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void commenceWhenNoMatchThenDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
@ -174,6 +184,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void commenceWhenMatchFirstEntryPointThenOthersNotInvoked() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
@ -192,6 +203,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
public void commenceWhenSecondMatchesThenDefaultNotInvoked() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
@ -220,6 +232,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
void builderWhenDefaultNullThenFirstIsDefault() throws ServletException, IOException {
AuthenticationEntryPoint firstEntryPoint = mock(AuthenticationEntryPoint.class);
AuthenticationEntryPoint secondEntryPoint = mock(AuthenticationEntryPoint.class);
@ -237,6 +250,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
void builderWhenDefaultAndEmptyEntryPointsThenReturnsDefault() {
AuthenticationEntryPoint defaultEntryPoint = mock(AuthenticationEntryPoint.class);
@ -248,6 +262,7 @@ public class DelegatingAuthenticationEntryPointTests {
}
@Test
@SuppressWarnings("removal")
void builderWhenNoEntryPointsThenIllegalStateException() {
DelegatingAuthenticationEntryPoint.Builder builder = DelegatingAuthenticationEntryPoint.builder();
assertThatIllegalStateException().isThrownBy(builder::build);

View File

@ -70,11 +70,13 @@ class OneTimeTokenAuthenticationFilterTests {
}
@Test
@SuppressWarnings("removal")
void setAuthenticationConverterWhenNullThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setAuthenticationConverter(null));
}
@Test
@SuppressWarnings("removal")
void doFilterWhenUrlDoesNotMatchThenContinues() throws ServletException, IOException {
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
HttpServletResponse response = mock(HttpServletResponse.class);
@ -85,6 +87,7 @@ class OneTimeTokenAuthenticationFilterTests {
}
@Test
@SuppressWarnings("removal")
void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOException {
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
HttpServletResponse response = mock(HttpServletResponse.class);
@ -95,6 +98,7 @@ class OneTimeTokenAuthenticationFilterTests {
}
@Test
@SuppressWarnings("removal")
void doFilterWhenMissingTokenThenPropagatesRequest() throws ServletException, IOException {
FilterChain chain = mock(FilterChain.class);
this.filter.doFilter(post("/login/ott").buildRequest(new MockServletContext()), this.response, chain);
@ -102,6 +106,7 @@ class OneTimeTokenAuthenticationFilterTests {
}
@Test
@SuppressWarnings("removal")
void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOException {
given(this.authenticationManager.authenticate(any())).willThrow(new BadCredentialsException("invalid token"));
this.filter.doFilter(
@ -112,6 +117,7 @@ class OneTimeTokenAuthenticationFilterTests {
}
@Test
@SuppressWarnings("removal")
void doFilterWhenValidThenRedirectsToSavedRequest() throws ServletException, IOException {
given(this.authenticationManager.authenticate(any()))
.willReturn(OneTimeTokenAuthenticationToken.authenticated("username", AuthorityUtils.NO_AUTHORITIES));