### Question:
AuthenticationService { public void authenticateByRefreshToken(String refreshToken) throws ObtainRefreshTokenException { logger.debug("authenticateByRefreshToken: {}", refreshToken); TokenDetails tokenDetails = tokenService.getTokenByRefreshToken(refreshToken); authenticateByTokenDetails(tokenDetails); } @Autowired  AuthenticationService(TokenService tokenService,
                                 OidcAuthenticationHelper oidcAuthenticationHelper); void authenticateByTokenDetails(TokenDetails tokenDetails); void authenticateByRefreshToken(String refreshToken);  }### Answer:
@Test void authenticateByRefreshToken() throws Exception { JwtTokenGenerator tokenGenerator = new JwtTokenGenerator("http: CLIENT_ID, Arrays.asList("USER_READ", "USER_WRITE")); String accessToken = tokenGenerator.generateJwtAccessToken(); TokenDetails tokenDetails = new TokenDetails(); tokenDetails.setAccessToken(accessToken); String refreshToken = "refresh-token"; when(tokenService.getTokenByRefreshToken(refreshToken)).thenReturn(tokenDetails); String publicKey = KeyUtils.importPublicKeyToPem(tokenGenerator.getIdpPair().getPublic()); when(publicKeyCacheService.getPublicKeyByRealm("test-realm")).thenReturn(publicKey); service.authenticateByRefreshToken(refreshToken); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); TokenDetails credentials = (TokenDetails) authentication.getCredentials(); Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities(); assertThat(credentials.getAccessToken(), is(accessToken)) ; assertThat(authorities.size(), is(2)); assertThat(authorities.contains(new SimpleGrantedAuthority("USER_READ")), is(true)); assertThat(authorities.contains(new SimpleGrantedAuthority("USER_WRITE")), is(true)); }