From 18f3d13363a3f74ef75ee3e7b80e2546ba5d8b5f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 27 Jul 2020 12:17:41 -0700 Subject: [PATCH] Fix parenthesis padding issues Fix a few parenthesis padding issues caused by the formatter. Issue gh-8945 --- ...PasswordAuthenticationTokenMixinTests.java | 56 ++++++------------- etc/checkstyle/checkstyle-suppressions.xml | 1 - ...h2AuthorizationRequestRepositoryTests.java | 12 +--- 3 files changed, 19 insertions(+), 50 deletions(-) diff --git a/core/src/test/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenMixinTests.java b/core/src/test/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenMixinTests.java index 18905cf639..0741c926be 100644 --- a/core/src/test/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenMixinTests.java +++ b/core/src/test/java/org/springframework/security/jackson2/UsernamePasswordAuthenticationTokenMixinTests.java @@ -43,44 +43,32 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixinTests { - // @formatter:off private static final String AUTHENTICATED_JSON = "{" - + "\"@class\": \"org.springframework.security.authentication.UsernamePasswordAuthenticationToken\"," - + "\"principal\": "+ UserDeserializerTests.USER_JSON + ", " - + "\"credentials\": \"1234\", " - + "\"authenticated\": true, " - + "\"details\": null, " - + "\"authorities\": "+ SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON - + "}"; - // @formatter:on + + "\"@class\": \"org.springframework.security.authentication.UsernamePasswordAuthenticationToken\"," + + "\"principal\": " + UserDeserializerTests.USER_JSON + ", " + "\"credentials\": \"1234\", " + + "\"authenticated\": true, " + "\"details\": null, " + "\"authorities\": " + + SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON + "}"; - // @formatter:off - public static final String AUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_JSON.replace( UserDeserializerTests.USER_JSON, "\"admin\""); - // @formatter:on + public static final String AUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_JSON + .replace(UserDeserializerTests.USER_JSON, "\"admin\""); - // @formatter:off private static final String NON_USER_PRINCIPAL_JSON = "{" - + "\"@class\": \"org.springframework.security.jackson2.UsernamePasswordAuthenticationTokenMixinTests$NonUserPrincipal\", " - + "\"username\": \"admin\"" - + "}"; - // @formatter:on + + "\"@class\": \"org.springframework.security.jackson2.UsernamePasswordAuthenticationTokenMixinTests$NonUserPrincipal\", " + + "\"username\": \"admin\"" + "}"; - // @formatter:off - private static final String AUTHENTICATED_STRINGDETAILS_JSON = AUTHENTICATED_JSON.replace("\"details\": null, ", "\"details\": \"details\", "); - // @formatter:on + private static final String AUTHENTICATED_STRINGDETAILS_JSON = AUTHENTICATED_JSON.replace("\"details\": null, ", + "\"details\": \"details\", "); - // @formatter:off private static final String AUTHENTICATED_NON_USER_PRINCIPAL_JSON = AUTHENTICATED_JSON - .replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON) - .replaceAll(UserDeserializerTests.USER_PASSWORD, "null") - .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON); - // @formatter:on + .replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON) + .replaceAll(UserDeserializerTests.USER_PASSWORD, "null") + .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, + SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON); - // @formatter:off private static final String UNAUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_STRINGPRINCIPAL_JSON - .replace("\"authenticated\": true, ", "\"authenticated\": false, ") - .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON); - // @formatter:on + .replace("\"authenticated\": true, ", "\"authenticated\": false, ") + .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, + SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON); @Test public void serializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() @@ -184,30 +172,20 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin @Test public void serializingThenDeserializingWithNoCredentialsOrDetailsShouldWork() throws IOException { - // given UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null); - - // when String serialized = this.mapper.writeValueAsString(original); UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized, UsernamePasswordAuthenticationToken.class); - - // then assertThat(deserialized).isEqualTo(original); } @Test public void serializingThenDeserializingWithConfiguredObjectMapperShouldWork() throws IOException { - // given this.mapper.setDefaultPropertyInclusion(construct(ALWAYS, NON_NULL)).setSerializationInclusion(NON_ABSENT); UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null); - - // when String serialized = this.mapper.writeValueAsString(original); UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized, UsernamePasswordAuthenticationToken.class); - - // then assertThat(deserialized).isEqualTo(original); } diff --git a/etc/checkstyle/checkstyle-suppressions.xml b/etc/checkstyle/checkstyle-suppressions.xml index 0f0f43aa9d..bf9e471928 100644 --- a/etc/checkstyle/checkstyle-suppressions.xml +++ b/etc/checkstyle/checkstyle-suppressions.xml @@ -3,7 +3,6 @@ "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd"> - diff --git a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/HttpSessionOAuth2AuthorizationRequestRepositoryTests.java b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/HttpSessionOAuth2AuthorizationRequestRepositoryTests.java index 2f7863e238..3a0115e192 100644 --- a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/HttpSessionOAuth2AuthorizationRequestRepositoryTests.java +++ b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/HttpSessionOAuth2AuthorizationRequestRepositoryTests.java @@ -197,20 +197,12 @@ public class HttpSessionOAuth2AuthorizationRequestRepositoryTests { public void saveAuthorizationRequestWhenNullThenRemoved() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); - OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest().build(); - - this.authorizationRequestRepository.saveAuthorizationRequest( // Save - authorizationRequest, request, response); - + this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest, request, response); request.addParameter(OAuth2ParameterNames.STATE, authorizationRequest.getState()); - this.authorizationRequestRepository.saveAuthorizationRequest( // Null value - // removes - null, request, response); - + this.authorizationRequestRepository.saveAuthorizationRequest(null, request, response); OAuth2AuthorizationRequest loadedAuthorizationRequest = this.authorizationRequestRepository .loadAuthorizationRequest(request); - assertThat(loadedAuthorizationRequest).isNull(); }