Skip to content

Commit

Permalink
Fix checkstyle violations for test module
Browse files Browse the repository at this point in the history
Issue gh-1624
  • Loading branch information
jgrandja committed May 22, 2024
1 parent 9c45484 commit 00e7d67
Show file tree
Hide file tree
Showing 79 changed files with 1,320 additions and 1,318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* Tests for {@link JdbcOAuth2AuthorizationConsentService}.
Expand Down Expand Up @@ -150,7 +150,8 @@ public void saveWhenAuthorizationConsentNewThenSaved() {

RegisteredClient newRegisteredClient = TestRegisteredClients.registeredClient().id("new-client").build();

when(this.registeredClientRepository.findById(eq(newRegisteredClient.getId()))).thenReturn(newRegisteredClient);
given(this.registeredClientRepository.findById(eq(newRegisteredClient.getId())))
.willReturn(newRegisteredClient);

this.authorizationConsentService.save(expectedAuthorizationConsent);

Expand All @@ -164,7 +165,7 @@ public void saveWhenAuthorizationConsentExistsThenUpdated() {
OAuth2AuthorizationConsent expectedAuthorizationConsent = OAuth2AuthorizationConsent.from(AUTHORIZATION_CONSENT)
.authority(new SimpleGrantedAuthority("new.authority"))
.build();
when(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId()))).thenReturn(REGISTERED_CLIENT);
given(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId()))).willReturn(REGISTERED_CLIENT);

this.authorizationConsentService.save(expectedAuthorizationConsent);

Expand All @@ -176,8 +177,7 @@ public void saveWhenAuthorizationConsentExistsThenUpdated() {

@Test
public void saveLoadAuthorizationConsentWhenCustomStrategiesSetThenCalled() throws Exception {
when(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId())))
.thenReturn(REGISTERED_CLIENT);
given(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId()))).willReturn(REGISTERED_CLIENT);

JdbcOAuth2AuthorizationConsentService.OAuth2AuthorizationConsentRowMapper authorizationConsentRowMapper = spy(
new JdbcOAuth2AuthorizationConsentService.OAuth2AuthorizationConsentRowMapper(
Expand All @@ -188,8 +188,8 @@ public void saveLoadAuthorizationConsentWhenCustomStrategiesSetThenCalled() thro
this.authorizationConsentService.setAuthorizationConsentParametersMapper(authorizationConsentParametersMapper);

this.authorizationConsentService.save(AUTHORIZATION_CONSENT);
OAuth2AuthorizationConsent authorizationConsent = this.authorizationConsentService.findById(
AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
OAuth2AuthorizationConsent authorizationConsent = this.authorizationConsentService
.findById(AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
assertThat(authorizationConsent).isEqualTo(AUTHORIZATION_CONSENT);
verify(authorizationConsentRowMapper).mapRow(any(), anyInt());
verify(authorizationConsentParametersMapper).apply(any());
Expand Down Expand Up @@ -225,12 +225,11 @@ public void findByIdWhenPrincipalNameNullThenThrowIllegalArgumentException() {

@Test
public void findByIdWhenAuthorizationConsentExistsThenFound() {
when(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId())))
.thenReturn(REGISTERED_CLIENT);
given(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId()))).willReturn(REGISTERED_CLIENT);

this.authorizationConsentService.save(AUTHORIZATION_CONSENT);
OAuth2AuthorizationConsent authorizationConsent = this.authorizationConsentService.findById(
AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
OAuth2AuthorizationConsent authorizationConsent = this.authorizationConsentService
.findById(AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
assertThat(authorizationConsent).isNotNull();
}

Expand All @@ -243,19 +242,18 @@ public void findByIdWhenAuthorizationConsentDoesNotExistThenNull() {

@Test
public void tableDefinitionWhenCustomThenAbleToOverride() {
when(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId())))
.thenReturn(REGISTERED_CLIENT);
given(this.registeredClientRepository.findById(eq(REGISTERED_CLIENT.getId()))).willReturn(REGISTERED_CLIENT);

EmbeddedDatabase db = createDb(CUSTOM_OAUTH2_AUTHORIZATION_CONSENT_SCHEMA_SQL_RESOURCE);
OAuth2AuthorizationConsentService authorizationConsentService =
new CustomJdbcOAuth2AuthorizationConsentService(new JdbcTemplate(db), this.registeredClientRepository);
OAuth2AuthorizationConsentService authorizationConsentService = new CustomJdbcOAuth2AuthorizationConsentService(
new JdbcTemplate(db), this.registeredClientRepository);
authorizationConsentService.save(AUTHORIZATION_CONSENT);
OAuth2AuthorizationConsent foundAuthorizationConsent1 = authorizationConsentService.findById(
AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
OAuth2AuthorizationConsent foundAuthorizationConsent1 = authorizationConsentService
.findById(AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
assertThat(foundAuthorizationConsent1).isEqualTo(AUTHORIZATION_CONSENT);
authorizationConsentService.remove(AUTHORIZATION_CONSENT);
OAuth2AuthorizationConsent foundAuthorizationConsent2 = authorizationConsentService.findById(
AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
OAuth2AuthorizationConsent foundAuthorizationConsent2 = authorizationConsentService
.findById(AUTHORIZATION_CONSENT.getRegisteredClientId(), AUTHORIZATION_CONSENT.getPrincipalName());
assertThat(foundAuthorizationConsent2).isNull();
db.shutdown();
}
Expand Down
Loading

0 comments on commit 00e7d67

Please sign in to comment.