### Question:
ApiHandlerHelpers { public static boolean validateAccessToken(HttpRequest request) { LoggingService.logDebug(MODULE_NAME, "Validate access token in request : " + request); final String validAccessToken = fetchAccessToken(); String accessToken; try { accessToken = request.headers().get(HttpHeaderNames.AUTHORIZATION, ""); return !TextUtils.isEmpty(accessToken) && accessToken.equalsIgnoreCase(validAccessToken); } catch (Exception e) { LoggingService.logError(MODULE_NAME, "Error validating Access Token", new AgentUserException(e.getMessage(), e)); } return false; }  static boolean validateMethod(HttpRequest request, HttpMethod expectedMethod); static String validateContentType(HttpRequest request, String expectedContentType); static boolean validateAccessToken(HttpRequest request); static FullHttpResponse successResponse(ByteBuf outputBuffer, String content); static FullHttpResponse methodNotAllowedResponse(); static FullHttpResponse badRequestResponse(ByteBuf outputBuffer, String content); static FullHttpResponse unauthorizedResponse(ByteBuf outputBuffer, String content); static FullHttpResponse notFoundResponse(ByteBuf outputBuffer, String content); static FullHttpResponse internalServerErrorResponse(ByteBuf outputBuffer, String content);  }### Answer:
@Test public void testValidateAccessTokenFalse() { try { assertFalse(ApiHandlerHelpers.validateAccessToken(request)); PowerMockito.verifyPrivate(ApiHandlerHelpers.class).invoke("fetchAccessToken"); } catch (Exception e) { fail("This should not happen"); } }
@Test public void testValidateAccessTokenTrue() { try { PowerMockito.when(request.headers()).thenReturn(httpHeaders); PowerMockito.when(httpHeaders.get(HttpHeaderNames.AUTHORIZATION, "")).thenReturn("token"); PowerMockito.when(bufferedReader.readLine()).thenReturn("token"); assertTrue(ApiHandlerHelpers.validateAccessToken(request)); PowerMockito.verifyPrivate(ApiHandlerHelpers.class).invoke("fetchAccessToken"); } catch (Exception e) { fail("This should not happen"); } }
@Test public void testValidateAccesswhenFetchTokenThrowsException() { try { PowerMockito.when(request.headers()).thenReturn(httpHeaders); PowerMockito.when(httpHeaders.get(HttpHeaderNames.AUTHORIZATION, "")).thenReturn("token"); PowerMockito.when(bufferedReader.readLine()).thenThrow(mock(IOException.class)); assertFalse(ApiHandlerHelpers.validateAccessToken(request)); PowerMockito.verifyPrivate(ApiHandlerHelpers.class).invoke("fetchAccessToken"); LoggingService.logError(Mockito.eq("Local API"), Mockito.eq("unable to load api token"), Mockito.any()); } catch (Exception e) { fail("This should not happen"); } }