### Question:
SLIAuthenticationEntryPoint implements AuthenticationEntryPoint { @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { HttpSession session = request.getSession(); try { SliApi.setBaseUrl(apiUrl); OAuthService service = new ServiceBuilder().provider(SliApi.class) .apiKey(propDecryptor.getDecryptedClientId()).apiSecret(propDecryptor.getDecryptedClientSecret()) .callback(callbackUrl).build(); boolean cookieFound = checkCookiesForToken(request, session); Object token = session.getAttribute(OAUTH_TOKEN); if (token == null && request.getParameter(OAUTH_CODE) == null) { initiatingAuthentication(request, response, session, service); } else if (token == null && request.getParameter(OAUTH_CODE) != null) { verifyingAuthentication(request, response, session, service); } else { completeAuthentication(request, response, session, token, cookieFound); } } catch (OAuthException ex) { session.invalidate(); LOG.error(LOG_MESSAGE_AUTH_EXCEPTION, new Object[] { ex.getMessage() }); response.sendError(HttpServletResponse.SC_FORBIDDEN, ex.getMessage()); return; } }  void setCallbackUrl(String callbackUrl); String getCallbackUrl(); void setApiUrl(String apiUrl); String getApiUrl(); RESTClient getRestClient(); void setRestClient(RESTClient restClient); APIClient getApiClient(); void setApiClient(APIClient apiClient); PropertiesDecryptor getPropDecryptor(); void setPropDecryptor(PropertiesDecryptor propDecryptor); @Override void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException); static final String OAUTH_TOKEN; static final String DASHBOARD_COOKIE; }### Answer:
@Test public void testCommence() throws Exception { HttpSession mockSession = mock(HttpSession.class); AuthenticationException mockAuthenticationException = mock(AuthenticationException.class); PropertiesDecryptor mockPropertiesDecryptor = mock(PropertiesDecryptor.class); APIClient mockAPIClient = mock(APIClient.class); RESTClient mockRESTClient = mock(RESTClient.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = (JsonObject)parser.parse("{\"authenticated\":true,\"edOrg\":null,\"edOrgId\":null,\"email\":\"dummy@fake.com\",\"external_id\":\"cgray\",\"full_name\":\"Mr Charles Gray\",\"granted_authorities\":[\"Destroyme\"],\"isAdminUser\":false,\"realm\":\"2013uz-d5ae70c9-55ef-11e2-b6be-68a86d3c2fde\",\"rights\":[\"READ_PUBLIC\",\"READ_GENERAL\",\"AGGREGATE_READ\"],\"sliRoles\":[\"Destroyme\"],\"tenantId\":\"wolverineil.wgen@gmail.com\",\"userType\":\"teacher\",\"user_id\":\"cgray@wolverineil.wgen@gmail.com\"}"); when(request.getSession()).thenReturn(mockSession); when(request.getRemoteAddr()).thenReturn("http: when(request.getServerName()).thenReturn("mock.slidev.org"); when(request.isSecure()).thenReturn(true); when(mockPropertiesDecryptor.getDecryptedClientId()).thenReturn("mock-client-id"); when(mockPropertiesDecryptor.getDecryptedClientSecret()).thenReturn("mock-client-secret"); when(mockPropertiesDecryptor.encrypt(anyString())).thenReturn("MOCK-ENCRYPTED-TOKEN"); when(mockSession.getAttribute(anyString())).thenReturn("Mock-OAUTH-TOKEN"); when(mockRESTClient.sessionCheck(anyString())).thenReturn(jsonObject); SLIAuthenticationEntryPoint sliAuthenticationEntryPoint = new SLIAuthenticationEntryPoint(); sliAuthenticationEntryPoint.setPropDecryptor(mockPropertiesDecryptor); sliAuthenticationEntryPoint.setApiClient(mockAPIClient); sliAuthenticationEntryPoint.setRestClient(mockRESTClient); sliAuthenticationEntryPoint.setApiUrl("/api/mock/uri"); sliAuthenticationEntryPoint.setCallbackUrl("http: sliAuthenticationEntryPoint.commence(request,response,mockAuthenticationException); }