1
0
mirror of synced 2026-05-22 21:33:16 +00:00

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
@@ -222,7 +222,8 @@ public class WebSecurityConfigurationTests {
// SEC-2773 // SEC-2773
@Test @Test
public void getMethodDelegatingApplicationListenerWhenWebSecurityConfigurationThenIsStatic() { 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(); assertThat(Modifier.isStatic(method.getModifiers())).isTrue();
} }
@@ -31,6 +31,7 @@ class OneTimeTokenAuthenticationTokenTests {
// gh-18095 // gh-18095
@Test @Test
@SuppressWarnings("removal")
void shouldBeAbleToDeserializeFromJsonWithDefaultTypingActivated() throws IOException { void shouldBeAbleToDeserializeFromJsonWithDefaultTypingActivated() throws IOException {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.registerModules(SecurityJackson2Modules.getModules(getClass().getClassLoader())); mapper.registerModules(SecurityJackson2Modules.getModules(getClass().getClassLoader()));
@@ -59,6 +59,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
private static final String TOKEN = "token"; private static final String TOKEN = "token";
@Test @Test
@SuppressWarnings("removal")
public void constructorWhenOneTimeTokenServiceNullThenIllegalArgumentException() { public void constructorWhenOneTimeTokenServiceNullThenIllegalArgumentException() {
ReactiveUserDetailsService userDetailsService = mock(ReactiveUserDetailsService.class); ReactiveUserDetailsService userDetailsService = mock(ReactiveUserDetailsService.class);
// @formatter:off // @formatter:off
@@ -68,6 +69,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void constructorWhenUserDetailsServiceNullThenIllegalArgumentException() { public void constructorWhenUserDetailsServiceNullThenIllegalArgumentException() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class); ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
// @formatter:off // @formatter:off
@@ -77,6 +79,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
} }
@Test @Test
@SuppressWarnings("removal")
void authenticateWhenOneTimeTokenAuthenticationTokenIsPresentThenSuccess() { void authenticateWhenOneTimeTokenAuthenticationTokenIsPresentThenSuccess() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class); ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class))) given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
@@ -103,6 +106,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
} }
@Test @Test
@SuppressWarnings("removal")
void authenticateWhenInvalidOneTimeTokenAuthenticationTokenIsPresentThenFail() { void authenticateWhenInvalidOneTimeTokenAuthenticationTokenIsPresentThenFail() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class); ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class))) given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
@@ -120,6 +124,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
} }
@Test @Test
@SuppressWarnings("removal")
void authenticateWhenIncorrectTypeOfAuthenticationIsPresentThenFail() { void authenticateWhenIncorrectTypeOfAuthenticationIsPresentThenFail() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class); ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class))) given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
@@ -61,7 +61,7 @@ public class AuthorityAuthorizationManagerTests {
@Test @Test
public void hasAnyRoleWhenNullThenException() { public void hasAnyRoleWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(null)) assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole((String[]) null))
.withMessage("roles cannot be empty"); .withMessage("roles cannot be empty");
} }
@@ -97,7 +97,8 @@ public class AuthorityAuthorizationManagerTests {
@Test @Test
public void hasAnyAuthorityWhenNullThenException() { public void hasAnyAuthorityWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority(null)) assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority((String[]) null))
.withMessage("authorities cannot be empty"); .withMessage("authorities cannot be empty");
} }
@@ -73,7 +73,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Map::class.java) 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).hasSize(1)
assertThat(result).containsKey("key2") assertThat(result).containsKey("key2")
assertThat(result).containsValue("value2") assertThat(result).containsValue("value2")
@@ -95,7 +96,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Map::class.java) 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) assertThat(result).hasSize(0)
} }
@@ -119,7 +121,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Collection::class.java) 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).hasSize(1)
assertThat(result).contains("string2") assertThat(result).contains("string2")
} }
@@ -140,7 +143,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Collection::class.java) 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) assertThat(result).hasSize(0)
} }
@@ -164,7 +168,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Array<String>::class.java) 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).hasSize(1)
assertThat(result).contains("string2") assertThat(result).contains("string2")
} }
@@ -185,7 +190,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Array<String>::class.java) 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) assertThat(result).hasSize(0)
} }
@@ -209,6 +215,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Stream::class.java) assertThat(filtered).isInstanceOf(Stream::class.java)
@Suppress("UNCHECKED_CAST")
val result = (filtered as Stream<String>).toList() val result = (filtered as Stream<String>).toList()
assertThat(result).hasSize(1) assertThat(result).hasSize(1)
assertThat(result).contains("string2") assertThat(result).contains("string2")
@@ -230,6 +237,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
) )
assertThat(filtered).isInstanceOf(Stream::class.java) assertThat(filtered).isInstanceOf(Stream::class.java)
@Suppress("UNCHECKED_CAST")
val result = (filtered as Stream<String>).toList() val result = (filtered as Stream<String>).toList()
assertThat(result).hasSize(0) assertThat(result).hasSize(0)
} }
+1
View File
@@ -1,6 +1,7 @@
plugins { plugins {
id 'security-nullability' id 'security-nullability'
id 'javadoc-warnings-error' id 'javadoc-warnings-error'
id 'compile-warnings-error'
} }
apply plugin: 'io.spring.convention.spring-module' apply plugin: 'io.spring.convention.spring-module'
@@ -65,6 +65,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void testDefaultEntryPoint() throws Exception { public void testDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class); RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -78,6 +79,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void testFirstEntryPoint() throws Exception { public void testFirstEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class); RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -96,6 +98,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void testSecondEntryPoint() throws Exception { public void testSecondEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class); RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -114,6 +117,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void constructorAepListWhenNullEntryPoints() { public void constructorAepListWhenNullEntryPoints() {
List<RequestMatcherEntry<AuthenticationEntryPoint>> entryPoints = null; List<RequestMatcherEntry<AuthenticationEntryPoint>> entryPoints = null;
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(
@@ -121,6 +125,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void constructorAepListWhenEmptyEntryPoints() { public void constructorAepListWhenEmptyEntryPoints() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class), .isThrownBy(() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class),
@@ -128,6 +133,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void constructorAepListWhenNullDefaultEntryPoint() { public void constructorAepListWhenNullDefaultEntryPoint() {
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
RequestMatcher matcher = mock(RequestMatcher.class); RequestMatcher matcher = mock(RequestMatcher.class);
@@ -138,6 +144,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenNullEntryPoints() { public void constructorAepVargsWhenNullEntryPoints() {
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = null; RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = null;
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(
@@ -145,6 +152,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenEmptyEntryPoints() { public void constructorAepVargsWhenEmptyEntryPoints() {
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = new RequestMatcherEntry[0]; RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = new RequestMatcherEntry[0];
assertThatIllegalArgumentException().isThrownBy( assertThatIllegalArgumentException().isThrownBy(
@@ -152,6 +160,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenNullDefaultEntryPoint() { public void constructorAepVargsWhenNullDefaultEntryPoint() {
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
RequestMatcher matcher = mock(RequestMatcher.class); RequestMatcher matcher = mock(RequestMatcher.class);
@@ -162,6 +171,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void commenceWhenNoMatchThenDefaultEntryPoint() throws Exception { public void commenceWhenNoMatchThenDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class); RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -174,6 +184,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void commenceWhenMatchFirstEntryPointThenOthersNotInvoked() throws Exception { public void commenceWhenMatchFirstEntryPointThenOthersNotInvoked() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class); RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -192,6 +203,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
public void commenceWhenSecondMatchesThenDefaultNotInvoked() throws Exception { public void commenceWhenSecondMatchesThenDefaultNotInvoked() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class); RequestMatcher firstRM = mock(RequestMatcher.class);
@@ -220,6 +232,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
void builderWhenDefaultNullThenFirstIsDefault() throws ServletException, IOException { void builderWhenDefaultNullThenFirstIsDefault() throws ServletException, IOException {
AuthenticationEntryPoint firstEntryPoint = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint firstEntryPoint = mock(AuthenticationEntryPoint.class);
AuthenticationEntryPoint secondEntryPoint = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint secondEntryPoint = mock(AuthenticationEntryPoint.class);
@@ -237,6 +250,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
void builderWhenDefaultAndEmptyEntryPointsThenReturnsDefault() { void builderWhenDefaultAndEmptyEntryPointsThenReturnsDefault() {
AuthenticationEntryPoint defaultEntryPoint = mock(AuthenticationEntryPoint.class); AuthenticationEntryPoint defaultEntryPoint = mock(AuthenticationEntryPoint.class);
@@ -248,6 +262,7 @@ public class DelegatingAuthenticationEntryPointTests {
} }
@Test @Test
@SuppressWarnings("removal")
void builderWhenNoEntryPointsThenIllegalStateException() { void builderWhenNoEntryPointsThenIllegalStateException() {
DelegatingAuthenticationEntryPoint.Builder builder = DelegatingAuthenticationEntryPoint.builder(); DelegatingAuthenticationEntryPoint.Builder builder = DelegatingAuthenticationEntryPoint.builder();
assertThatIllegalStateException().isThrownBy(builder::build); assertThatIllegalStateException().isThrownBy(builder::build);
@@ -70,11 +70,13 @@ class OneTimeTokenAuthenticationFilterTests {
} }
@Test @Test
@SuppressWarnings("removal")
void setAuthenticationConverterWhenNullThenIllegalArgumentException() { void setAuthenticationConverterWhenNullThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setAuthenticationConverter(null)); assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setAuthenticationConverter(null));
} }
@Test @Test
@SuppressWarnings("removal")
void doFilterWhenUrlDoesNotMatchThenContinues() throws ServletException, IOException { void doFilterWhenUrlDoesNotMatchThenContinues() throws ServletException, IOException {
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class); OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
HttpServletResponse response = mock(HttpServletResponse.class); HttpServletResponse response = mock(HttpServletResponse.class);
@@ -85,6 +87,7 @@ class OneTimeTokenAuthenticationFilterTests {
} }
@Test @Test
@SuppressWarnings("removal")
void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOException { void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOException {
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class); OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
HttpServletResponse response = mock(HttpServletResponse.class); HttpServletResponse response = mock(HttpServletResponse.class);
@@ -95,6 +98,7 @@ class OneTimeTokenAuthenticationFilterTests {
} }
@Test @Test
@SuppressWarnings("removal")
void doFilterWhenMissingTokenThenPropagatesRequest() throws ServletException, IOException { void doFilterWhenMissingTokenThenPropagatesRequest() throws ServletException, IOException {
FilterChain chain = mock(FilterChain.class); FilterChain chain = mock(FilterChain.class);
this.filter.doFilter(post("/login/ott").buildRequest(new MockServletContext()), this.response, chain); this.filter.doFilter(post("/login/ott").buildRequest(new MockServletContext()), this.response, chain);
@@ -102,6 +106,7 @@ class OneTimeTokenAuthenticationFilterTests {
} }
@Test @Test
@SuppressWarnings("removal")
void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOException { void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOException {
given(this.authenticationManager.authenticate(any())).willThrow(new BadCredentialsException("invalid token")); given(this.authenticationManager.authenticate(any())).willThrow(new BadCredentialsException("invalid token"));
this.filter.doFilter( this.filter.doFilter(
@@ -112,6 +117,7 @@ class OneTimeTokenAuthenticationFilterTests {
} }
@Test @Test
@SuppressWarnings("removal")
void doFilterWhenValidThenRedirectsToSavedRequest() throws ServletException, IOException { void doFilterWhenValidThenRedirectsToSavedRequest() throws ServletException, IOException {
given(this.authenticationManager.authenticate(any())) given(this.authenticationManager.authenticate(any()))
.willReturn(OneTimeTokenAuthenticationToken.authenticated("username", AuthorityUtils.NO_AUTHORITIES)); .willReturn(OneTimeTokenAuthenticationToken.authenticated("username", AuthorityUtils.NO_AUTHORITIES));