### Question:
OAuthTokenProvider implements TokenProvider { @Override public String getAccessToken() { if(getTokenInfo().getTimestamp() + getTokenInfo().getExpiresIn() - config.getTokenExpiryBuffer() <= new Date().getTime()) { refreshTokens(); } return this.getTokenInfo().getAccessToken(); } @Builder private  OAuthTokenProvider(TokenApi tokenApi, OAuthConfig config, TokenRepository tokenRepository, String authCode, String codeVerifier); @Override String getAccessToken(); @Override String refreshTokens();  }### Answer:
@Test public void testGetAccessToken_whenTokensAreExpired_shouldRefreshTokensAndReturnNewAccessToken() throws Exception { mockAuthCodeCall(0); provider = OAuthTokenProvider.builder() .tokenApi(tokenApi) .config(createDefaultConfig()) .authCode("auth-code").build(); TimeUnit.SECONDS.sleep(1); Mockito.when(tokenApi.refresh( eq("refresh_token"), eq("refresh-token-0"))).thenReturn(createTokens(2, 0)); String accessToken = provider.getAccessToken(); assertThat(accessToken).isEqualTo("access-token-2"); }
@Test public void testGetAccessToken_whenTokensAreNotExpired_shouldJustReturnTheCurrentAccessToken() { mockAuthCodeCall(5); provider = OAuthTokenProvider.builder() .tokenApi(tokenApi) .config(createDefaultConfig()) .authCode("auth-code").build(); assertThat(provider.getAccessToken()).isEqualTo("access-token-0"); Mockito.verify(tokenApi, Mockito.times(0)).refresh(anyString(), anyString()); }