Source:
<code>public void testRefreshTokenWebRequestHasError() throws InterruptedException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InstantiationException, InvocationTargetException, NoSuchAlgorithmException, NoSuchPaddingException { FileMockContext mockContext = new FileMockContext(getContext()); ITokenCacheStore mockCache = getCacheForRefreshToken(TEST_IDTOKEN_USERID, TEST_IDTOKEN_UPN); final AuthenticationContext context = getAuthenticationContext(mockContext, VALID_AUTHORITY, false, mockCache); setConnectionAvailable(context, true); final CountDownLatch signal = new CountDownLatch(1); MockAuthenticationCallback callback = new MockAuthenticationCallback(signal); MockWebRequestHandler webrequest = new MockWebRequestHandler(); webrequest.setReturnResponse(new HttpWebResponse(500, null, null)); ReflectionUtils.setFieldValue(context, "mWebRequest", webrequest); final TestLogResponse response = new TestLogResponse(); <START> response.listenLogForMessageSegments(signal, "Server error message"); <END> context.acquireTokenSilentAsync("resource", "clientid", TEST_IDTOKEN_USERID, callback); signal.await(CONTEXT_REQUEST_TIME_OUT, TimeUnit.MILLISECONDS); assertTrue("Log message has same webstatus code", response.errorCode.equals(ADALError.SERVER_ERROR)); assertNotNull("Cache item is not removed for this item", mockCache.getItem(CacheKey.createCacheKey( VALID_AUTHORITY, "resource", "clientId", false, TEST_IDTOKEN_USERID))); clearCache(context); }</code><technical_language>this function unlocks signal acquireTokenSilentAsync exits... wait acquireTokenSilentAsync invokes callback, check get exception in result</technical_language>

Target:
public void testRefreshTokenWebRequestHasError() throws InterruptedException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InstantiationException, InvocationTargetException, NoSuchAlgorithmException, NoSuchPaddingException { FileMockContext mockContext = new FileMockContext(getContext()); ITokenCacheStore mockCache = getCacheForRefreshToken(TEST_IDTOKEN_USERID, TEST_IDTOKEN_UPN); final AuthenticationContext context = getAuthenticationContext(mockContext, VALID_AUTHORITY, false, mockCache); setConnectionAvailable(context, true); final CountDownLatch signal = new CountDownLatch(1); MockAuthenticationCallback callback = new MockAuthenticationCallback(signal); MockWebRequestHandler webrequest = new MockWebRequestHandler(); webrequest.setReturnResponse(new HttpWebResponse(500, null, null)); ReflectionUtils.setFieldValue(context, "mWebRequest", webrequest); context.acquireTokenSilentAsync("resource", "clientid", TEST_IDTOKEN_USERID, callback); signal.await(CONTEXT_REQUEST_TIME_OUT, TimeUnit.MILLISECONDS); assertNotNull(callback.mException); assertTrue(callback.mException instanceof AuthenticationException); AuthenticationException authenticationException = (AuthenticationException)callback.mException; assertEquals(authenticationException.getCode(), ADALError.AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED); assertNotNull("Cache item is not removed for this item", mockCache.getItem(CacheKey.createCacheKey( VALID_AUTHORITY, "resource", "clientId", false, TEST_IDTOKEN_USERID))); clearCache(context); }