4545import static org .mockito .ArgumentMatchers .any ;
4646import static org .mockito .ArgumentMatchers .anyInt ;
4747import static org .mockito .ArgumentMatchers .eq ;
48+ import static org .mockito .BDDMockito .given ;
4849import static org .mockito .Mockito .mock ;
4950import static org .mockito .Mockito .spy ;
5051import static org .mockito .Mockito .verify ;
51- import static org .mockito .Mockito .when ;
5252
5353/**
5454 * Tests for {@link JdbcOAuth2AuthorizationConsentService}.
@@ -150,7 +150,8 @@ public void saveWhenAuthorizationConsentNewThenSaved() {
150150
151151 RegisteredClient newRegisteredClient = TestRegisteredClients .registeredClient ().id ("new-client" ).build ();
152152
153- when (this .registeredClientRepository .findById (eq (newRegisteredClient .getId ()))).thenReturn (newRegisteredClient );
153+ given (this .registeredClientRepository .findById (eq (newRegisteredClient .getId ())))
154+ .willReturn (newRegisteredClient );
154155
155156 this .authorizationConsentService .save (expectedAuthorizationConsent );
156157
@@ -164,7 +165,7 @@ public void saveWhenAuthorizationConsentExistsThenUpdated() {
164165 OAuth2AuthorizationConsent expectedAuthorizationConsent = OAuth2AuthorizationConsent .from (AUTHORIZATION_CONSENT )
165166 .authority (new SimpleGrantedAuthority ("new.authority" ))
166167 .build ();
167- when (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ()))).thenReturn (REGISTERED_CLIENT );
168+ given (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ()))).willReturn (REGISTERED_CLIENT );
168169
169170 this .authorizationConsentService .save (expectedAuthorizationConsent );
170171
@@ -176,8 +177,7 @@ public void saveWhenAuthorizationConsentExistsThenUpdated() {
176177
177178 @ Test
178179 public void saveLoadAuthorizationConsentWhenCustomStrategiesSetThenCalled () throws Exception {
179- when (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ())))
180- .thenReturn (REGISTERED_CLIENT );
180+ given (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ()))).willReturn (REGISTERED_CLIENT );
181181
182182 JdbcOAuth2AuthorizationConsentService .OAuth2AuthorizationConsentRowMapper authorizationConsentRowMapper = spy (
183183 new JdbcOAuth2AuthorizationConsentService .OAuth2AuthorizationConsentRowMapper (
@@ -188,8 +188,8 @@ public void saveLoadAuthorizationConsentWhenCustomStrategiesSetThenCalled() thro
188188 this .authorizationConsentService .setAuthorizationConsentParametersMapper (authorizationConsentParametersMapper );
189189
190190 this .authorizationConsentService .save (AUTHORIZATION_CONSENT );
191- OAuth2AuthorizationConsent authorizationConsent = this .authorizationConsentService . findById (
192- AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
191+ OAuth2AuthorizationConsent authorizationConsent = this .authorizationConsentService
192+ . findById ( AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
193193 assertThat (authorizationConsent ).isEqualTo (AUTHORIZATION_CONSENT );
194194 verify (authorizationConsentRowMapper ).mapRow (any (), anyInt ());
195195 verify (authorizationConsentParametersMapper ).apply (any ());
@@ -225,12 +225,11 @@ public void findByIdWhenPrincipalNameNullThenThrowIllegalArgumentException() {
225225
226226 @ Test
227227 public void findByIdWhenAuthorizationConsentExistsThenFound () {
228- when (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ())))
229- .thenReturn (REGISTERED_CLIENT );
228+ given (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ()))).willReturn (REGISTERED_CLIENT );
230229
231230 this .authorizationConsentService .save (AUTHORIZATION_CONSENT );
232- OAuth2AuthorizationConsent authorizationConsent = this .authorizationConsentService . findById (
233- AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
231+ OAuth2AuthorizationConsent authorizationConsent = this .authorizationConsentService
232+ . findById ( AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
234233 assertThat (authorizationConsent ).isNotNull ();
235234 }
236235
@@ -243,19 +242,18 @@ public void findByIdWhenAuthorizationConsentDoesNotExistThenNull() {
243242
244243 @ Test
245244 public void tableDefinitionWhenCustomThenAbleToOverride () {
246- when (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ())))
247- .thenReturn (REGISTERED_CLIENT );
245+ given (this .registeredClientRepository .findById (eq (REGISTERED_CLIENT .getId ()))).willReturn (REGISTERED_CLIENT );
248246
249247 EmbeddedDatabase db = createDb (CUSTOM_OAUTH2_AUTHORIZATION_CONSENT_SCHEMA_SQL_RESOURCE );
250- OAuth2AuthorizationConsentService authorizationConsentService =
251- new CustomJdbcOAuth2AuthorizationConsentService ( new JdbcTemplate (db ), this .registeredClientRepository );
248+ OAuth2AuthorizationConsentService authorizationConsentService = new CustomJdbcOAuth2AuthorizationConsentService (
249+ new JdbcTemplate (db ), this .registeredClientRepository );
252250 authorizationConsentService .save (AUTHORIZATION_CONSENT );
253- OAuth2AuthorizationConsent foundAuthorizationConsent1 = authorizationConsentService . findById (
254- AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
251+ OAuth2AuthorizationConsent foundAuthorizationConsent1 = authorizationConsentService
252+ . findById ( AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
255253 assertThat (foundAuthorizationConsent1 ).isEqualTo (AUTHORIZATION_CONSENT );
256254 authorizationConsentService .remove (AUTHORIZATION_CONSENT );
257- OAuth2AuthorizationConsent foundAuthorizationConsent2 = authorizationConsentService . findById (
258- AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
255+ OAuth2AuthorizationConsent foundAuthorizationConsent2 = authorizationConsentService
256+ . findById ( AUTHORIZATION_CONSENT .getRegisteredClientId (), AUTHORIZATION_CONSENT .getPrincipalName ());
259257 assertThat (foundAuthorizationConsent2 ).isNull ();
260258 db .shutdown ();
261259 }
0 commit comments