### Question:
KeycloakServiceImpl implements KeycloakService { @Override public AccessTokenResponse generateAccessToken(String refreshToken) { AccessTokenResponse tokenResponse = refreshToken(refreshToken); final String username = KeycloakUtil.parseToken(tokenResponse.getToken()).getPreferredUsername(); securityDAO.updateUser(username, tokenResponse); return tokenResponse; } @Inject  KeycloakServiceImpl(Client httpClient, SelfServiceApplicationConfiguration conf, SecurityDAO securityDAO); @Override AccessTokenResponse getToken(String code); @Override AccessTokenResponse refreshToken(String refreshToken); @Override AccessTokenResponse generateAccessToken(String refreshToken); @Override AccessTokenResponse generateServiceAccountToken();  }### Answer:
@Test public void generateAccessToken() { WebTarget webTarget = mock(WebTarget.class); Invocation.Builder builder = mock(Invocation.Builder.class); Response response = mock(Response.class); Response.StatusType statusType = mock(Response.StatusType.class); AccessTokenResponse tokenResponse = mock(AccessTokenResponse.class); when(httpClient.target(anyString())).thenReturn(webTarget); when(webTarget.request()).thenReturn(builder); when(builder.header(any(), anyString())).thenReturn(builder); when(builder.post(any())).thenReturn(response); when(response.getStatusInfo()).thenReturn(statusType); when(response.readEntity(AccessTokenResponse.class)).thenReturn(tokenResponse); when(statusType.getFamily()).thenReturn(Response.Status.Family.SUCCESSFUL); when(tokenResponse.getToken()).thenReturn(ACCESS_TOKEN); doNothing().when(securityDAO).updateUser(anyString(), any(AccessTokenResponse.class)); keycloakService.generateAccessToken(REFRESH_TOKEN); verify(httpClient).target(anyString()); verify(securityDAO).updateUser("test", tokenResponse); verifyNoMoreInteractions(securityDAO, httpClient); }