Skip to content

Commit 48cc835

Browse files
Update tests in InMemoryOAuth2AuthorizationServiceTest to conform to standards
Fixes spring-projectsgh-43
1 parent 9b748c4 commit 48cc835

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

core/src/test/java/org/springframework/security/oauth2/server/authorization/InMemoryOAuth2AuthorizationServiceTest.java

+21-19
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import java.util.Collections;
2525
import java.util.List;
2626

27-
import static org.junit.Assert.*;
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2829

2930
/**
3031
* Unit tests for {@link InMemoryOAuth2AuthorizationService}.
@@ -43,31 +44,32 @@ public class InMemoryOAuth2AuthorizationServiceTest {
4344
private InMemoryOAuth2AuthorizationService authorizationService;
4445

4546
@Before
46-
public void setUp() throws Exception {
47+
public void setUp() {
4748
store = new ArrayList<>();
4849
authorizationService = new InMemoryOAuth2AuthorizationService(store);
4950
}
5051

5152
@Test
52-
public void testSave() {
53+
public void saveWhenAuthorizationProvidedThenSavedInList() {
5354
OAuth2Authorization authorization = OAuth2Authorization.builder()
5455
.registeredClientId("clientId")
5556
.principalName("principalName")
5657
.attributes(Collections.singletonMap(AUTHORIZATION_CODE.getValue(), TOKEN))
5758
.build();
5859
authorizationService.save(authorization);
5960

60-
assertEquals(1, store.size());
61-
assertEquals(authorization, store.get(0));
61+
assertThat(store.size()).isEqualTo(1);
62+
assertThat(authorization).isEqualTo(store.get(0));
6263
}
6364

6465
@Test
65-
public void testSaveWithNullParam() {
66-
assertThrows(IllegalArgumentException.class, () -> authorizationService.save(null));
66+
public void saveWhenAuthorizationNotProvidedThenThrowIllegalArgumentException() {
67+
assertThatThrownBy(() -> authorizationService.save(null))
68+
.isInstanceOf(IllegalArgumentException.class);
6769
}
6870

6971
@Test
70-
public void testFindByTokenAndTokenTypeWhenTokenTypeIsAuthorizationCode() {
72+
public void findByTokenAndTokenTypeWhenTokenTypeIsAuthorizationCodeThenFound() {
7173
OAuth2Authorization authorization = OAuth2Authorization.builder()
7274
.registeredClientId("clientId")
7375
.principalName("principalName")
@@ -76,11 +78,11 @@ public void testFindByTokenAndTokenTypeWhenTokenTypeIsAuthorizationCode() {
7678
store.add(authorization);
7779

7880
OAuth2Authorization result = authorizationService.findByTokenAndTokenType(TOKEN, TokenType.AUTHORIZATION_CODE);
79-
assertEquals(authorization, result);
81+
assertThat(authorization).isEqualTo(result);
8082
}
8183

8284
@Test
83-
public void testFindByTokenAndTokenTypeWhenTokenTypeIsAccessToken() {
85+
public void findByTokenAndTokenTypeWhenTokenTypeIsAccessTokenThenFound() {
8486
OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, TOKEN, ISSUED_AT,
8587
EXPIRES_AT);
8688
OAuth2Authorization authorization = OAuth2Authorization.builder()
@@ -91,11 +93,11 @@ public void testFindByTokenAndTokenTypeWhenTokenTypeIsAccessToken() {
9193
store.add(authorization);
9294

9395
OAuth2Authorization result = authorizationService.findByTokenAndTokenType(TOKEN, ACCESS_TOKEN);
94-
assertEquals(authorization, result);
96+
assertThat(authorization).isEqualTo(result);
9597
}
9698

9799
@Test
98-
public void testFindByTokenAndTokenTypeWhenTokenNotFound() {
100+
public void findByTokenAndTokenTypeWhenTokenWithTokenTypeDoesNotExistThenNull() {
99101
OAuth2Authorization authorization = OAuth2Authorization.builder()
100102
.registeredClientId("clientId")
101103
.principalName("principalName")
@@ -104,18 +106,18 @@ public void testFindByTokenAndTokenTypeWhenTokenNotFound() {
104106
store.add(authorization);
105107

106108
OAuth2Authorization result = authorizationService.findByTokenAndTokenType(TOKEN, ACCESS_TOKEN);
107-
assertNull(result);
109+
assertThat(result).isNull();
108110
}
109111

110112
@Test
111-
public void testFindByTokenAndTokenTypeWithNullToken() {
112-
assertThrows(IllegalArgumentException.class,
113-
() -> authorizationService.findByTokenAndTokenType(null, TokenType.AUTHORIZATION_CODE));
113+
public void findByTokenAndTokenTypeWhenTokenNullThenThrowIllegalArgumentException() {
114+
assertThatThrownBy(() -> authorizationService.findByTokenAndTokenType(null, TokenType.AUTHORIZATION_CODE))
115+
.isInstanceOf(IllegalArgumentException.class);
114116
}
115117

116118
@Test
117-
public void testFindByTokenAndTokenTypeWithNullTokenType() {
118-
assertThrows(IllegalArgumentException.class,
119-
() -> authorizationService.findByTokenAndTokenType(TOKEN, null));
119+
public void findByTokenAndTokenTypeWhenTokenTypeNullThenThrowIllegalArgumentException() {
120+
assertThatThrownBy(() -> authorizationService.findByTokenAndTokenType(TOKEN, null))
121+
.isInstanceOf(IllegalArgumentException.class);
120122
}
121123
}

0 commit comments

Comments
 (0)