From 48f958cbbf2582a6ae612bbfd51438f4780cb660 Mon Sep 17 00:00:00 2001 From: Robert Winch <362503+rwinch@users.noreply.github.com> Date: Wed, 14 Jan 2026 09:32:54 -0600 Subject: [PATCH] Fix OAuth2AuthorizationRequestRedirectFilter constructor tests OAuth2AuthorizationRequestRedirectFilterTests attempt to validate the constructors throw IllegalArgumentException if an invalid argument is provided, but they are flawed because it is the relective code that is throwing the IllegalArgumentException due to imprecise type information. This changes the tests to no longer use unnecessary reflection and casts the types so that the type information is used to target the correct constructor. Closes gh-18507 --- ...Auth2AuthorizationRequestRedirectFilterTests.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationRequestRedirectFilterTests.java b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationRequestRedirectFilterTests.java index 51974ec1ee..1033d76ffe 100644 --- a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationRequestRedirectFilterTests.java +++ b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationRequestRedirectFilterTests.java @@ -16,7 +16,6 @@ package org.springframework.security.oauth2.client.web; -import java.lang.reflect.Constructor; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; @@ -43,7 +42,6 @@ import org.springframework.security.oauth2.client.registration.TestClientRegistr import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; import org.springframework.security.web.RedirectStrategy; import org.springframework.security.web.savedrequest.RequestCache; -import org.springframework.util.ClassUtils; import org.springframework.web.util.UriComponentsBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -87,9 +85,8 @@ public class OAuth2AuthorizationRequestRedirectFilterTests { @Test public void constructorWhenClientRegistrationRepositoryIsNullThenThrowIllegalArgumentException() { - Constructor constructor = ClassUtils.getConstructorIfAvailable( - OAuth2AuthorizationRequestRedirectFilter.class, ClientRegistrationRepository.class); - assertThatIllegalArgumentException().isThrownBy(() -> constructor.newInstance(null)); + assertThatIllegalArgumentException() + .isThrownBy(() -> new OAuth2AuthorizationRequestRedirectFilter((ClientRegistrationRepository) null)); } @Test @@ -100,9 +97,8 @@ public class OAuth2AuthorizationRequestRedirectFilterTests { @Test public void constructorWhenAuthorizationRequestResolverIsNullThenThrowIllegalArgumentException() { - Constructor constructor = ClassUtils.getConstructorIfAvailable( - OAuth2AuthorizationRequestRedirectFilter.class, OAuth2AuthorizationRequestResolver.class); - assertThatIllegalArgumentException().isThrownBy(() -> constructor.newInstance(null)); + assertThatIllegalArgumentException() + .isThrownBy(() -> new OAuth2AuthorizationRequestRedirectFilter((OAuth2AuthorizationRequestResolver) null)); } @Test