Fix parenthesis padding issues

Fix a few parenthesis padding issues caused by the formatter.

Issue gh-8945
This commit is contained in:
Phillip Webb 2020-07-27 12:17:41 -07:00 committed by Rob Winch
parent f1cee9500f
commit 18f3d13363
3 changed files with 19 additions and 50 deletions

View File

@ -43,44 +43,32 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixinTests { public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixinTests {
// @formatter:off
private static final String AUTHENTICATED_JSON = "{" private static final String AUTHENTICATED_JSON = "{"
+ "\"@class\": \"org.springframework.security.authentication.UsernamePasswordAuthenticationToken\"," + "\"@class\": \"org.springframework.security.authentication.UsernamePasswordAuthenticationToken\","
+ "\"principal\": "+ UserDeserializerTests.USER_JSON + ", " + "\"principal\": " + UserDeserializerTests.USER_JSON + ", " + "\"credentials\": \"1234\", "
+ "\"credentials\": \"1234\", " + "\"authenticated\": true, " + "\"details\": null, " + "\"authorities\": "
+ "\"authenticated\": true, " + SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON + "}";
+ "\"details\": null, "
+ "\"authorities\": "+ SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON
+ "}";
// @formatter:on
// @formatter:off public static final String AUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_JSON
public static final String AUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_JSON.replace( UserDeserializerTests.USER_JSON, "\"admin\""); .replace(UserDeserializerTests.USER_JSON, "\"admin\"");
// @formatter:on
// @formatter:off
private static final String NON_USER_PRINCIPAL_JSON = "{" private static final String NON_USER_PRINCIPAL_JSON = "{"
+ "\"@class\": \"org.springframework.security.jackson2.UsernamePasswordAuthenticationTokenMixinTests$NonUserPrincipal\", " + "\"@class\": \"org.springframework.security.jackson2.UsernamePasswordAuthenticationTokenMixinTests$NonUserPrincipal\", "
+ "\"username\": \"admin\"" + "\"username\": \"admin\"" + "}";
+ "}";
// @formatter:on
// @formatter:off private static final String AUTHENTICATED_STRINGDETAILS_JSON = AUTHENTICATED_JSON.replace("\"details\": null, ",
private static final String AUTHENTICATED_STRINGDETAILS_JSON = AUTHENTICATED_JSON.replace("\"details\": null, ", "\"details\": \"details\", "); "\"details\": \"details\", ");
// @formatter:on
// @formatter:off
private static final String AUTHENTICATED_NON_USER_PRINCIPAL_JSON = AUTHENTICATED_JSON private static final String AUTHENTICATED_NON_USER_PRINCIPAL_JSON = AUTHENTICATED_JSON
.replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON) .replace(UserDeserializerTests.USER_JSON, NON_USER_PRINCIPAL_JSON)
.replaceAll(UserDeserializerTests.USER_PASSWORD, "null") .replaceAll(UserDeserializerTests.USER_PASSWORD, "null")
.replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON); .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON,
// @formatter:on SimpleGrantedAuthorityMixinTests.NO_AUTHORITIES_ARRAYLIST_JSON);
// @formatter:off
private static final String UNAUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_STRINGPRINCIPAL_JSON private static final String UNAUTHENTICATED_STRINGPRINCIPAL_JSON = AUTHENTICATED_STRINGPRINCIPAL_JSON
.replace("\"authenticated\": true, ", "\"authenticated\": false, ") .replace("\"authenticated\": true, ", "\"authenticated\": false, ")
.replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON, SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON); .replace(SimpleGrantedAuthorityMixinTests.AUTHORITIES_ARRAYLIST_JSON,
// @formatter:on SimpleGrantedAuthorityMixinTests.EMPTY_AUTHORITIES_ARRAYLIST_JSON);
@Test @Test
public void serializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() public void serializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest()
@ -184,30 +172,20 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
@Test @Test
public void serializingThenDeserializingWithNoCredentialsOrDetailsShouldWork() throws IOException { public void serializingThenDeserializingWithNoCredentialsOrDetailsShouldWork() throws IOException {
// given
UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null); UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null);
// when
String serialized = this.mapper.writeValueAsString(original); String serialized = this.mapper.writeValueAsString(original);
UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized, UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized,
UsernamePasswordAuthenticationToken.class); UsernamePasswordAuthenticationToken.class);
// then
assertThat(deserialized).isEqualTo(original); assertThat(deserialized).isEqualTo(original);
} }
@Test @Test
public void serializingThenDeserializingWithConfiguredObjectMapperShouldWork() throws IOException { public void serializingThenDeserializingWithConfiguredObjectMapperShouldWork() throws IOException {
// given
this.mapper.setDefaultPropertyInclusion(construct(ALWAYS, NON_NULL)).setSerializationInclusion(NON_ABSENT); this.mapper.setDefaultPropertyInclusion(construct(ALWAYS, NON_NULL)).setSerializationInclusion(NON_ABSENT);
UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null); UsernamePasswordAuthenticationToken original = new UsernamePasswordAuthenticationToken("Frodo", null);
// when
String serialized = this.mapper.writeValueAsString(original); String serialized = this.mapper.writeValueAsString(original);
UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized, UsernamePasswordAuthenticationToken deserialized = this.mapper.readValue(serialized,
UsernamePasswordAuthenticationToken.class); UsernamePasswordAuthenticationToken.class);
// then
assertThat(deserialized).isEqualTo(original); assertThat(deserialized).isEqualTo(original);
} }

View File

@ -3,7 +3,6 @@
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd"> "https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions> <suppressions>
<suppress files=".*" checks="ParenPad" />
<suppress files=".*" checks="RedundantImport" /> <suppress files=".*" checks="RedundantImport" />
<suppress files=".*" checks="RegexpSinglelineJava" /> <suppress files=".*" checks="RegexpSinglelineJava" />
<suppress files=".*" checks="SimplifyBooleanExpression" /> <suppress files=".*" checks="SimplifyBooleanExpression" />

View File

@ -197,20 +197,12 @@ public class HttpSessionOAuth2AuthorizationRequestRepositoryTests {
public void saveAuthorizationRequestWhenNullThenRemoved() { public void saveAuthorizationRequestWhenNullThenRemoved() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest().build(); OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest().build();
this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest, request, response);
this.authorizationRequestRepository.saveAuthorizationRequest( // Save
authorizationRequest, request, response);
request.addParameter(OAuth2ParameterNames.STATE, authorizationRequest.getState()); request.addParameter(OAuth2ParameterNames.STATE, authorizationRequest.getState());
this.authorizationRequestRepository.saveAuthorizationRequest( // Null value this.authorizationRequestRepository.saveAuthorizationRequest(null, request, response);
// removes
null, request, response);
OAuth2AuthorizationRequest loadedAuthorizationRequest = this.authorizationRequestRepository OAuth2AuthorizationRequest loadedAuthorizationRequest = this.authorizationRequestRepository
.loadAuthorizationRequest(request); .loadAuthorizationRequest(request);
assertThat(loadedAuthorizationRequest).isNull(); assertThat(loadedAuthorizationRequest).isNull();
} }