Skip to content

Commit e5dc462

Browse files
committed
Fix checkstyle
Issue gh-17880
1 parent 6484d1a commit e5dc462

File tree

61 files changed

+1085
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1085
-1122
lines changed

oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/InMemoryOAuth2AuthorizationServiceTests.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.springframework.security.oauth2.server.authorization.client.TestRegisteredClients;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
36-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
36+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3737

3838
/**
3939
* Tests for {@link InMemoryOAuth2AuthorizationService}.
@@ -69,16 +69,16 @@ public void setup() {
6969

7070
@Test
7171
public void constructorVarargsWhenAuthorizationNullThenThrowIllegalArgumentException() {
72-
assertThatThrownBy(() -> new InMemoryOAuth2AuthorizationService((OAuth2Authorization) null))
73-
.isInstanceOf(IllegalArgumentException.class)
74-
.hasMessage("authorization cannot be null");
72+
assertThatExceptionOfType(IllegalArgumentException.class)
73+
.isThrownBy(() -> new InMemoryOAuth2AuthorizationService((OAuth2Authorization) null))
74+
.withMessage("authorization cannot be null");
7575
}
7676

7777
@Test
7878
public void constructorListWhenAuthorizationsNullThenThrowIllegalArgumentException() {
79-
assertThatThrownBy(() -> new InMemoryOAuth2AuthorizationService((List<OAuth2Authorization>) null))
80-
.isInstanceOf(IllegalArgumentException.class)
81-
.hasMessage("authorizations cannot be null");
79+
assertThatExceptionOfType(IllegalArgumentException.class)
80+
.isThrownBy(() -> new InMemoryOAuth2AuthorizationService((List<OAuth2Authorization>) null))
81+
.withMessage("authorizations cannot be null");
8282
}
8383

8484
@Test
@@ -90,15 +90,15 @@ public void constructorWhenDuplicateAuthorizationsThenThrowIllegalArgumentExcept
9090
.token(AUTHORIZATION_CODE)
9191
.build();
9292

93-
assertThatThrownBy(() -> new InMemoryOAuth2AuthorizationService(authorization, authorization))
94-
.isInstanceOf(IllegalArgumentException.class)
95-
.hasMessage("The authorization must be unique. Found duplicate identifier: id");
93+
assertThatExceptionOfType(IllegalArgumentException.class)
94+
.isThrownBy(() -> new InMemoryOAuth2AuthorizationService(authorization, authorization))
95+
.withMessage("The authorization must be unique. Found duplicate identifier: id");
9696
}
9797

9898
@Test
9999
public void saveWhenAuthorizationNullThenThrowIllegalArgumentException() {
100-
assertThatThrownBy(() -> this.authorizationService.save(null)).isInstanceOf(IllegalArgumentException.class)
101-
.hasMessage("authorization cannot be null");
100+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.save(null))
101+
.withMessage("authorization cannot be null");
102102
}
103103

104104
@Test
@@ -179,8 +179,9 @@ public void saveWhenInitializedAuthorizationsReachMaxThenOldestRemoved() {
179179

180180
@Test
181181
public void removeWhenAuthorizationNullThenThrowIllegalArgumentException() {
182-
assertThatThrownBy(() -> this.authorizationService.remove(null)).isInstanceOf(IllegalArgumentException.class)
183-
.hasMessage("authorization cannot be null");
182+
assertThatExceptionOfType(IllegalArgumentException.class)
183+
.isThrownBy(() -> this.authorizationService.remove(null))
184+
.withMessage("authorization cannot be null");
184185
}
185186

186187
@Test
@@ -205,15 +206,16 @@ public void removeWhenAuthorizationProvidedThenRemoved() {
205206

206207
@Test
207208
public void findByIdWhenIdNullThenThrowIllegalArgumentException() {
208-
assertThatThrownBy(() -> this.authorizationService.findById(null)).isInstanceOf(IllegalArgumentException.class)
209-
.hasMessage("id cannot be empty");
209+
assertThatExceptionOfType(IllegalArgumentException.class)
210+
.isThrownBy(() -> this.authorizationService.findById(null))
211+
.withMessage("id cannot be empty");
210212
}
211213

212214
@Test
213215
public void findByTokenWhenTokenNullThenThrowIllegalArgumentException() {
214-
assertThatThrownBy(() -> this.authorizationService.findByToken(null, AUTHORIZATION_CODE_TOKEN_TYPE))
215-
.isInstanceOf(IllegalArgumentException.class)
216-
.hasMessage("token cannot be empty");
216+
assertThatExceptionOfType(IllegalArgumentException.class)
217+
.isThrownBy(() -> this.authorizationService.findByToken(null, AUTHORIZATION_CODE_TOKEN_TYPE))
218+
.withMessage("token cannot be empty");
217219
}
218220

219221
@Test

oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/JdbcOAuth2AuthorizationConsentServiceTests.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
import org.springframework.util.StringUtils;
4242

4343
import static org.assertj.core.api.Assertions.assertThat;
44+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4445
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
45-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4646
import static org.mockito.ArgumentMatchers.any;
4747
import static org.mockito.ArgumentMatchers.anyInt;
4848
import static org.mockito.ArgumentMatchers.eq;
@@ -100,36 +100,32 @@ public void tearDown() {
100100
@Test
101101
public void constructorWhenJdbcOperationsIsNullThenThrowIllegalArgumentException() {
102102
// @formatter:off
103-
assertThatThrownBy(() -> new JdbcOAuth2AuthorizationConsentService(null, this.registeredClientRepository))
104-
.isInstanceOf(IllegalArgumentException.class)
105-
.hasMessage("jdbcOperations cannot be null");
103+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new JdbcOAuth2AuthorizationConsentService(null, this.registeredClientRepository))
104+
.withMessage("jdbcOperations cannot be null");
106105
// @formatter:on
107106
}
108107

109108
@Test
110109
public void constructorWhenRegisteredClientRepositoryIsNullThenThrowIllegalArgumentException() {
111110
// @formatter:off
112-
assertThatThrownBy(() -> new JdbcOAuth2AuthorizationConsentService(this.jdbcOperations, null))
113-
.isInstanceOf(IllegalArgumentException.class)
114-
.hasMessage("registeredClientRepository cannot be null");
111+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new JdbcOAuth2AuthorizationConsentService(this.jdbcOperations, null))
112+
.withMessage("registeredClientRepository cannot be null");
115113
// @formatter:on
116114
}
117115

118116
@Test
119117
public void setAuthorizationConsentRowMapperWhenNullThenThrowIllegalArgumentException() {
120118
// @formatter:off
121-
assertThatThrownBy(() -> this.authorizationConsentService.setAuthorizationConsentRowMapper(null))
122-
.isInstanceOf(IllegalArgumentException.class)
123-
.hasMessage("authorizationConsentRowMapper cannot be null");
119+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationConsentService.setAuthorizationConsentRowMapper(null))
120+
.withMessage("authorizationConsentRowMapper cannot be null");
124121
// @formatter:on
125122
}
126123

127124
@Test
128125
public void setAuthorizationConsentParametersMapperWhenNullThenThrowIllegalArgumentException() {
129126
// @formatter:off
130-
assertThatThrownBy(() -> this.authorizationConsentService.setAuthorizationConsentParametersMapper(null))
131-
.isInstanceOf(IllegalArgumentException.class)
132-
.hasMessage("authorizationConsentParametersMapper cannot be null");
127+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationConsentService.setAuthorizationConsentParametersMapper(null))
128+
.withMessage("authorizationConsentParametersMapper cannot be null");
133129
// @formatter:on
134130
}
135131

oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/JdbcOAuth2AuthorizationServiceTests.java

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
import org.springframework.util.StringUtils;
6161

6262
import static org.assertj.core.api.Assertions.assertThat;
63-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
63+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6464
import static org.mockito.ArgumentMatchers.any;
6565
import static org.mockito.ArgumentMatchers.anyInt;
6666
import static org.mockito.ArgumentMatchers.eq;
@@ -130,54 +130,48 @@ public void tearDown() {
130130
@Test
131131
public void constructorWhenJdbcOperationsIsNullThenThrowIllegalArgumentException() {
132132
// @formatter:off
133-
assertThatThrownBy(() -> new JdbcOAuth2AuthorizationService(null, this.registeredClientRepository))
134-
.isInstanceOf(IllegalArgumentException.class)
135-
.hasMessage("jdbcOperations cannot be null");
133+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new JdbcOAuth2AuthorizationService(null, this.registeredClientRepository))
134+
.withMessage("jdbcOperations cannot be null");
136135
// @formatter:on
137136
}
138137

139138
@Test
140139
public void constructorWhenRegisteredClientRepositoryIsNullThenThrowIllegalArgumentException() {
141140
// @formatter:off
142-
assertThatThrownBy(() -> new JdbcOAuth2AuthorizationService(this.jdbcOperations, null))
143-
.isInstanceOf(IllegalArgumentException.class)
144-
.hasMessage("registeredClientRepository cannot be null");
141+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new JdbcOAuth2AuthorizationService(this.jdbcOperations, null))
142+
.withMessage("registeredClientRepository cannot be null");
145143
// @formatter:on
146144
}
147145

148146
@Test
149147
public void constructorWhenLobHandlerIsNullThenThrowIllegalArgumentException() {
150148
// @formatter:off
151-
assertThatThrownBy(() -> new JdbcOAuth2AuthorizationService(this.jdbcOperations, this.registeredClientRepository, null))
152-
.isInstanceOf(IllegalArgumentException.class)
153-
.hasMessage("lobHandler cannot be null");
149+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new JdbcOAuth2AuthorizationService(this.jdbcOperations, this.registeredClientRepository, null))
150+
.withMessage("lobHandler cannot be null");
154151
// @formatter:on
155152
}
156153

157154
@Test
158155
public void setAuthorizationRowMapperWhenNullThenThrowIllegalArgumentException() {
159156
// @formatter:off
160-
assertThatThrownBy(() -> this.authorizationService.setAuthorizationRowMapper(null))
161-
.isInstanceOf(IllegalArgumentException.class)
162-
.hasMessage("authorizationRowMapper cannot be null");
157+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.setAuthorizationRowMapper(null))
158+
.withMessage("authorizationRowMapper cannot be null");
163159
// @formatter:on
164160
}
165161

166162
@Test
167163
public void setAuthorizationParametersMapperWhenNullThenThrowIllegalArgumentException() {
168164
// @formatter:off
169-
assertThatThrownBy(() -> this.authorizationService.setAuthorizationParametersMapper(null))
170-
.isInstanceOf(IllegalArgumentException.class)
171-
.hasMessage("authorizationParametersMapper cannot be null");
165+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.setAuthorizationParametersMapper(null))
166+
.withMessage("authorizationParametersMapper cannot be null");
172167
// @formatter:on
173168
}
174169

175170
@Test
176171
public void saveWhenAuthorizationNullThenThrowIllegalArgumentException() {
177172
// @formatter:off
178-
assertThatThrownBy(() -> this.authorizationService.save(null))
179-
.isInstanceOf(IllegalArgumentException.class)
180-
.hasMessage("authorization cannot be null");
173+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.save(null))
174+
.withMessage("authorization cannot be null");
181175
// @formatter:on
182176
}
183177

@@ -247,9 +241,8 @@ public void saveLoadAuthorizationWhenCustomStrategiesSetThenCalled() throws Exce
247241
@Test
248242
public void removeWhenAuthorizationNullThenThrowIllegalArgumentException() {
249243
// @formatter:off
250-
assertThatThrownBy(() -> this.authorizationService.remove(null))
251-
.isInstanceOf(IllegalArgumentException.class)
252-
.hasMessage("authorization cannot be null");
244+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.remove(null))
245+
.withMessage("authorization cannot be null");
253246
// @formatter:on
254247
}
255248

@@ -277,27 +270,24 @@ public void removeWhenAuthorizationProvidedThenRemoved() {
277270
@Test
278271
public void findByIdWhenIdNullThenThrowIllegalArgumentException() {
279272
// @formatter:off
280-
assertThatThrownBy(() -> this.authorizationService.findById(null))
281-
.isInstanceOf(IllegalArgumentException.class)
282-
.hasMessage("id cannot be empty");
273+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.findById(null))
274+
.withMessage("id cannot be empty");
283275
// @formatter:on
284276
}
285277

286278
@Test
287279
public void findByIdWhenIdEmptyThenThrowIllegalArgumentException() {
288280
// @formatter:off
289-
assertThatThrownBy(() -> this.authorizationService.findById(" "))
290-
.isInstanceOf(IllegalArgumentException.class)
291-
.hasMessage("id cannot be empty");
281+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.findById(" "))
282+
.withMessage("id cannot be empty");
292283
// @formatter:on
293284
}
294285

295286
@Test
296287
public void findByTokenWhenTokenNullThenThrowIllegalArgumentException() {
297288
// @formatter:off
298-
assertThatThrownBy(() -> this.authorizationService.findByToken(null, AUTHORIZATION_CODE_TOKEN_TYPE))
299-
.isInstanceOf(IllegalArgumentException.class)
300-
.hasMessage("token cannot be empty");
289+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.authorizationService.findByToken(null, AUTHORIZATION_CODE_TOKEN_TYPE))
290+
.withMessage("token cannot be empty");
301291
// @formatter:on
302292
}
303293

oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/OAuth2AuthorizationTests.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.springframework.security.oauth2.server.authorization.client.TestRegisteredClients;
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
31-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
31+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3232

3333
/**
3434
* Tests for {@link OAuth2Authorization}.
@@ -56,15 +56,15 @@ public class OAuth2AuthorizationTests {
5656

5757
@Test
5858
public void withRegisteredClientWhenRegisteredClientNullThenThrowIllegalArgumentException() {
59-
assertThatThrownBy(() -> OAuth2Authorization.withRegisteredClient(null))
60-
.isInstanceOf(IllegalArgumentException.class)
61-
.hasMessage("registeredClient cannot be null");
59+
assertThatExceptionOfType(IllegalArgumentException.class)
60+
.isThrownBy(() -> OAuth2Authorization.withRegisteredClient(null))
61+
.withMessage("registeredClient cannot be null");
6262
}
6363

6464
@Test
6565
public void fromWhenAuthorizationNullThenThrowIllegalArgumentException() {
66-
assertThatThrownBy(() -> OAuth2Authorization.from(null)).isInstanceOf(IllegalArgumentException.class)
67-
.hasMessage("authorization cannot be null");
66+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> OAuth2Authorization.from(null))
67+
.withMessage("authorization cannot be null");
6868
}
6969

7070
@Test
@@ -91,32 +91,31 @@ public void fromWhenAuthorizationProvidedThenCopied() {
9191

9292
@Test
9393
public void buildWhenPrincipalNameNotProvidedThenThrowIllegalArgumentException() {
94-
assertThatThrownBy(() -> OAuth2Authorization.withRegisteredClient(REGISTERED_CLIENT).build())
94+
assertThatExceptionOfType(IllegalArgumentException.class)
95+
.isThrownBy(() -> OAuth2Authorization.withRegisteredClient(REGISTERED_CLIENT).build())
9596
.isInstanceOf(IllegalArgumentException.class)
96-
.hasMessage("principalName cannot be empty");
97+
.withMessage("principalName cannot be empty");
9798
}
9899

99100
@Test
100101
public void buildWhenAuthorizationGrantTypeNotProvidedThenThrowIllegalArgumentException() {
101-
assertThatThrownBy(
102+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
102103
() -> OAuth2Authorization.withRegisteredClient(REGISTERED_CLIENT).principalName(PRINCIPAL_NAME).build())
103-
.isInstanceOf(IllegalArgumentException.class)
104-
.hasMessage("authorizationGrantType cannot be null");
104+
.withMessage("authorizationGrantType cannot be null");
105105
}
106106

107107
@Test
108108
public void attributeWhenNameNullThenThrowIllegalArgumentException() {
109-
assertThatThrownBy(
109+
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
110110
() -> OAuth2Authorization.withRegisteredClient(REGISTERED_CLIENT).attribute(null, AUTHORIZATION_CODE))
111-
.isInstanceOf(IllegalArgumentException.class)
112-
.hasMessage("name cannot be empty");
111+
.withMessage("name cannot be empty");
113112
}
114113

115114
@Test
116115
public void attributeWhenValueNullThenThrowIllegalArgumentException() {
117-
assertThatThrownBy(() -> OAuth2Authorization.withRegisteredClient(REGISTERED_CLIENT).attribute("name", null))
118-
.isInstanceOf(IllegalArgumentException.class)
119-
.hasMessage("value cannot be null");
116+
assertThatExceptionOfType(IllegalArgumentException.class)
117+
.isThrownBy(() -> OAuth2Authorization.withRegisteredClient(REGISTERED_CLIENT).attribute("name", null))
118+
.withMessage("value cannot be null");
120119
}
121120

122121
@Test

0 commit comments

Comments
 (0)