|
18 | 18 | import java.util.HashMap; |
19 | 19 | import java.util.Map; |
20 | 20 | import org.junit.jupiter.api.Test; |
| 21 | +import org.mockito.ArgumentCaptor; |
21 | 22 | import org.mockito.Mockito; |
22 | 23 |
|
23 | 24 | public class ExternalBrowserCredentialsProviderTest { |
@@ -264,6 +265,21 @@ void cacheWithValidTokenTest() throws IOException { |
264 | 265 |
|
265 | 266 | // Verify token was saved back to cache |
266 | 267 | Mockito.verify(mockTokenCache, Mockito.times(1)).save(any(Token.class)); |
| 268 | + |
| 269 | + // Capture the token that was saved to cache to verify it's the refreshed token |
| 270 | + ArgumentCaptor<Token> tokenCaptor = ArgumentCaptor.forClass(Token.class); |
| 271 | + Mockito.verify(mockTokenCache).save(tokenCaptor.capture()); |
| 272 | + Token savedToken = tokenCaptor.getValue(); |
| 273 | + |
| 274 | + // Verify the saved token contains the refreshed values from the HTTP response |
| 275 | + assertEquals( |
| 276 | + "refreshed_access_token", |
| 277 | + savedToken.getAccessToken(), |
| 278 | + "Should save refreshed access token to cache"); |
| 279 | + assertEquals( |
| 280 | + "new_refresh_token", |
| 281 | + savedToken.getRefreshToken(), |
| 282 | + "Should save new refresh token to cache"); |
267 | 283 | } |
268 | 284 |
|
269 | 285 | @Test |
@@ -326,6 +342,21 @@ void cacheWithInvalidAccessTokenValidRefreshTest() throws IOException { |
326 | 342 |
|
327 | 343 | // Verify token was saved back to cache |
328 | 344 | Mockito.verify(mockTokenCache, Mockito.times(1)).save(any(Token.class)); |
| 345 | + |
| 346 | + // Capture the token that was saved to cache to verify it's the refreshed token |
| 347 | + ArgumentCaptor<Token> tokenCaptor = ArgumentCaptor.forClass(Token.class); |
| 348 | + Mockito.verify(mockTokenCache).save(tokenCaptor.capture()); |
| 349 | + Token savedToken = tokenCaptor.getValue(); |
| 350 | + |
| 351 | + // Verify the saved token contains the refreshed values from the HTTP response |
| 352 | + assertEquals( |
| 353 | + "refreshed_access_token", |
| 354 | + savedToken.getAccessToken(), |
| 355 | + "Should save refreshed access token to cache"); |
| 356 | + assertEquals( |
| 357 | + "new_refresh_token", |
| 358 | + savedToken.getRefreshToken(), |
| 359 | + "Should save new refresh token to cache"); |
329 | 360 | } |
330 | 361 |
|
331 | 362 | @Test |
|
0 commit comments