Source:
<code>public void testRefreshTokenPositive() throws IOException, InterruptedException, AuthenticationException { FileMockContext mockContext = new FileMockContext(getContext()); ITokenCacheStore mockCache = getCacheForRefreshToken(TEST_IDTOKEN_USERID, TEST_IDTOKEN_UPN); final AuthenticationContext context = getAuthenticationContext(mockContext, VALID_AUTHORITY, false, mockCache); final MockActivity testActivity = new MockActivity(); final CountDownLatch signal = new CountDownLatch(1); testActivity.mSignal = signal; MockAuthenticationCallback callback = new MockAuthenticationCallback(signal); final String response = "{\"id_token\":\"" + TEST_IDTOKEN + "\",\"access_token\":\"TokenFortestRefreshTokenPositive\",\"token_type\":\"Bearer\",\"expires_in\":\"-10\",\"expires_on\":\"1368768616\",\"refresh_token\":\"refresh112\",\"scope\":\"*\"}"; final String response2 = "{\"id_token\":\"" + TEST_IDTOKEN + "\",\"access_token\":\"TokenReturnsWithIdToken\",\"token_type\":\"Bearer\",\"expires_in\":\"3600\",\"expires_on\":\"1368768616\",\"refresh_token\":\"refreshABC\",\"scope\":\"*\"}"; final HttpURLConnection mockedConnection = Mockito.mock(HttpURLConnection.class); HttpUrlConnectionFactory.mockedConnection = mockedConnection; Util.prepareMockedUrlConnection(mockedConnection); Mockito.when(mockedConnection.getOutputStream()).thenReturn(Mockito.mock(OutputStream.class)); Mockito.when(mockedConnection.getInputStream()).thenReturn(Util.createInputStream(response), Util.createInputStream(response2)); Mockito.when(mockedConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); context.acquireToken(testActivity, "resource", "clientid", "redirectUri", TEST_IDTOKEN_UPN, callback); <START> signal.await(CONTEXT_REQUEST_TIME_OUT*1000, TimeUnit.MILLISECONDS); <END> verifyRefreshTokenResponse(mockCache, callback.mException, callback.mResult); AuthenticationResult result = context.acquireTokenSilentSync("resource", "clientid", TEST_IDTOKEN_USERID); assertEquals("Access Token", "TokenReturnsWithIdToken", result.getAccessToken()); assertEquals("Refresh Token", "refreshABC", result.getRefreshToken()); assertEquals("IdToken", TEST_IDTOKEN, result.getIdToken()); clearCache(context); }</code><technical_language>why</technical_language>

Target:
public void testRefreshTokenPositive() throws IOException, InterruptedException, AuthenticationException { FileMockContext mockContext = new FileMockContext(getContext()); ITokenCacheStore mockCache = getCacheForRefreshToken(TEST_IDTOKEN_USERID, TEST_IDTOKEN_UPN); final AuthenticationContext context = getAuthenticationContext(mockContext, VALID_AUTHORITY, false, mockCache); final MockActivity testActivity = new MockActivity(); final CountDownLatch signal = new CountDownLatch(1); testActivity.mSignal = signal; MockAuthenticationCallback callback = new MockAuthenticationCallback(signal); final String response = "{\"id_token\":\"" + TEST_IDTOKEN + "\",\"access_token\":\"TokenFortestRefreshTokenPositive\",\"token_type\":\"Bearer\",\"expires_in\":\"-10\",\"expires_on\":\"1368768616\",\"refresh_token\":\"refresh112\",\"scope\":\"*\"}"; final String response2 = "{\"id_token\":\"" + TEST_IDTOKEN + "\",\"access_token\":\"TokenReturnsWithIdToken\",\"token_type\":\"Bearer\",\"expires_in\":\"3600\",\"expires_on\":\"1368768616\",\"refresh_token\":\"refreshABC\",\"scope\":\"*\"}"; final HttpURLConnection mockedConnection = Mockito.mock(HttpURLConnection.class); HttpUrlConnectionFactory.mockedConnection = mockedConnection; Util.prepareMockedUrlConnection(mockedConnection); Mockito.when(mockedConnection.getOutputStream()).thenReturn(Mockito.mock(OutputStream.class)); Mockito.when(mockedConnection.getInputStream()).thenReturn(Util.createInputStream(response), Util.createInputStream(response2)); Mockito.when(mockedConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); context.acquireToken(testActivity, "resource", "clientid", "redirectUri", TEST_IDTOKEN_UPN, callback); signal.await(CONTEXT_REQUEST_TIME_OUT, TimeUnit.MILLISECONDS); verifyRefreshTokenResponse(mockCache, callback.getException(), callback.getAuthenticationResult()); AuthenticationResult result = context.acquireTokenSilentSync("resource", "clientid", TEST_IDTOKEN_USERID); assertEquals("Access Token", "TokenReturnsWithIdToken", result.getAccessToken()); assertEquals("Refresh Token", "refreshABC", result.getRefreshToken()); assertEquals("IdToken", TEST_IDTOKEN, result.getIdToken()); clearCache(context); }