24
24
import java .util .Collections ;
25
25
import java .util .List ;
26
26
27
- import static org .junit .Assert .*;
27
+ import static org .assertj .core .api .Assertions .assertThat ;
28
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
28
29
29
30
/**
30
31
* Unit tests for {@link InMemoryOAuth2AuthorizationService}.
@@ -43,31 +44,32 @@ public class InMemoryOAuth2AuthorizationServiceTest {
43
44
private InMemoryOAuth2AuthorizationService authorizationService ;
44
45
45
46
@ Before
46
- public void setUp () throws Exception {
47
+ public void setUp () {
47
48
store = new ArrayList <>();
48
49
authorizationService = new InMemoryOAuth2AuthorizationService (store );
49
50
}
50
51
51
52
@ Test
52
- public void testSave () {
53
+ public void saveWhenAuthorizationProvidedThenSavedInList () {
53
54
OAuth2Authorization authorization = OAuth2Authorization .builder ()
54
55
.registeredClientId ("clientId" )
55
56
.principalName ("principalName" )
56
57
.attributes (Collections .singletonMap (AUTHORIZATION_CODE .getValue (), TOKEN ))
57
58
.build ();
58
59
authorizationService .save (authorization );
59
60
60
- assertEquals ( 1 , store .size ());
61
- assertEquals (authorization , store .get (0 ));
61
+ assertThat ( store .size ()). isEqualTo ( 1 );
62
+ assertThat (authorization ). isEqualTo ( store .get (0 ));
62
63
}
63
64
64
65
@ 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 );
67
69
}
68
70
69
71
@ Test
70
- public void testFindByTokenAndTokenTypeWhenTokenTypeIsAuthorizationCode () {
72
+ public void findByTokenAndTokenTypeWhenTokenTypeIsAuthorizationCodeThenFound () {
71
73
OAuth2Authorization authorization = OAuth2Authorization .builder ()
72
74
.registeredClientId ("clientId" )
73
75
.principalName ("principalName" )
@@ -76,11 +78,11 @@ public void testFindByTokenAndTokenTypeWhenTokenTypeIsAuthorizationCode() {
76
78
store .add (authorization );
77
79
78
80
OAuth2Authorization result = authorizationService .findByTokenAndTokenType (TOKEN , TokenType .AUTHORIZATION_CODE );
79
- assertEquals (authorization , result );
81
+ assertThat (authorization ). isEqualTo ( result );
80
82
}
81
83
82
84
@ Test
83
- public void testFindByTokenAndTokenTypeWhenTokenTypeIsAccessToken () {
85
+ public void findByTokenAndTokenTypeWhenTokenTypeIsAccessTokenThenFound () {
84
86
OAuth2AccessToken accessToken = new OAuth2AccessToken (OAuth2AccessToken .TokenType .BEARER , TOKEN , ISSUED_AT ,
85
87
EXPIRES_AT );
86
88
OAuth2Authorization authorization = OAuth2Authorization .builder ()
@@ -91,11 +93,11 @@ public void testFindByTokenAndTokenTypeWhenTokenTypeIsAccessToken() {
91
93
store .add (authorization );
92
94
93
95
OAuth2Authorization result = authorizationService .findByTokenAndTokenType (TOKEN , ACCESS_TOKEN );
94
- assertEquals (authorization , result );
96
+ assertThat (authorization ). isEqualTo ( result );
95
97
}
96
98
97
99
@ Test
98
- public void testFindByTokenAndTokenTypeWhenTokenNotFound () {
100
+ public void findByTokenAndTokenTypeWhenTokenWithTokenTypeDoesNotExistThenNull () {
99
101
OAuth2Authorization authorization = OAuth2Authorization .builder ()
100
102
.registeredClientId ("clientId" )
101
103
.principalName ("principalName" )
@@ -104,18 +106,18 @@ public void testFindByTokenAndTokenTypeWhenTokenNotFound() {
104
106
store .add (authorization );
105
107
106
108
OAuth2Authorization result = authorizationService .findByTokenAndTokenType (TOKEN , ACCESS_TOKEN );
107
- assertNull (result );
109
+ assertThat (result ). isNull ( );
108
110
}
109
111
110
112
@ 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 );
114
116
}
115
117
116
118
@ 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 );
120
122
}
121
123
}
0 commit comments