21
21
import java .util .HashSet ;
22
22
import java .util .Set ;
23
23
24
+ import org .junit .Assert ;
24
25
import org .junit .Before ;
25
26
import org .junit .Test ;
26
27
import org .junit .runner .RunWith ;
52
53
53
54
import com .google .common .collect .Sets ;
54
55
56
+ import static com .google .common .collect .Sets .newHashSet ;
55
57
import static org .hamcrest .CoreMatchers .equalTo ;
56
58
import static org .hamcrest .CoreMatchers .is ;
57
59
import static org .hamcrest .CoreMatchers .not ;
60
62
61
63
import static org .mockito .Mockito .never ;
62
64
import static org .mockito .Mockito .when ;
63
-
65
+ import static org .junit .Assert .assertEquals ;
66
+ import static org .junit .Assert .assertFalse ;
64
67
import static org .junit .Assert .assertThat ;
65
68
import static org .junit .Assert .assertTrue ;
66
69
import static org .junit .Assert .fail ;
@@ -83,7 +86,9 @@ public class TestDefaultOAuth2ProviderTokenService {
83
86
private String badClientId = "bad_client" ;
84
87
private Set <String > scope = Sets .newHashSet ("openid" , "profile" , "email" , "offline_access" );
85
88
private OAuth2RefreshTokenEntity refreshToken ;
89
+ private OAuth2AccessTokenEntity accessToken ;
86
90
private String refreshTokenValue = "refresh_token_value" ;
91
+ private String userSub = "6a50ac11786d402a9591d3e592ac770f" ;
87
92
private TokenRequest tokenRequest ;
88
93
89
94
// for use when refreshing access tokens
@@ -142,6 +147,8 @@ public void prepare() {
142
147
Mockito .when (tokenRepository .getRefreshTokenByValue (refreshTokenValue )).thenReturn (refreshToken );
143
148
Mockito .when (refreshToken .getClient ()).thenReturn (client );
144
149
Mockito .when (refreshToken .isExpired ()).thenReturn (false );
150
+
151
+ accessToken = Mockito .mock (OAuth2AccessTokenEntity .class );
145
152
146
153
tokenRequest = new TokenRequest (null , clientId , null , null );
147
154
@@ -542,5 +549,22 @@ public void refreshAccessToken_expiration() {
542
549
543
550
assertTrue (token .getExpiration ().after (lowerBoundAccessTokens ) && token .getExpiration ().before (upperBoundAccessTokens ));
544
551
}
545
-
552
+
553
+ @ Test
554
+ public void getAllAccessTokensForUser (){
555
+ Mockito .when (tokenRepository .getAccessTokensBySub (userSub )).thenReturn (newHashSet (accessToken ));
556
+
557
+ Set <OAuth2AccessTokenEntity > tokens = service .getAllAccessTokensForUser (userSub );
558
+ assertEquals (1 , tokens .size ());
559
+ assertTrue (tokens .contains (accessToken ));
560
+ }
561
+
562
+ @ Test
563
+ public void getAllRefreshTokensForUser (){
564
+ Mockito .when (tokenRepository .getRefreshTokensBySub (userSub )).thenReturn (newHashSet (refreshToken ));
565
+
566
+ Set <OAuth2RefreshTokenEntity > tokens = service .getAllRefreshTokensForUser (userSub );
567
+ assertEquals (1 , tokens .size ());
568
+ assertTrue (tokens .contains (refreshToken ));
569
+ }
546
570
}
0 commit comments