### Question:
RestAuthenticationHandler { public JsonValue initiateAuthentication(HttpServletRequest request, HttpServletResponse response, String authIndexType, String indexValue, String sessionUpgradeSSOTokenId) throws RestAuthException { return authenticate(request, response, null, authIndexType, indexValue, sessionUpgradeSSOTokenId); } @Inject  RestAuthenticationHandler(LoginAuthenticator loginAuthenticator,
            RestAuthCallbackHandlerManager restAuthCallbackHandlerManager,
            AMAuthErrorCodeResponseStatusMapping amAuthErrorCodeResponseStatusMapping, AuthIdHelper authIdHelper); JsonValue initiateAuthentication(HttpServletRequest request, HttpServletResponse response,
            String authIndexType, String indexValue, String sessionUpgradeSSOTokenId); JsonValue continueAuthentication(HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, String sessionUpgradeSSOTokenId);  }### Answer:
@Test public void shouldInitiateAuthenticationViaGET5() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, RestAuthException, RestAuthResponseException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse httpResponse = mock(HttpServletResponse.class); String authIndexType = "UNKNOWN"; String indexValue = null; String sessionUpgradeSSOTokenId = null; try { restAuthenticationHandler.initiateAuthentication(request, httpResponse, authIndexType, indexValue, sessionUpgradeSSOTokenId); } catch (RestAuthException e) { assertEquals(e.getStatusCode(), 400); assertEquals(e.getMessage(), "Unknown Authentication Index Type"); return; } fail(); }
@Test public void shouldInitiateAuthenticationViaGET5() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, RestAuthException, RestAuthResponseException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse httpResponse = mock(HttpServletResponse.class); String authIndexType = "UNKNOWN"; String indexValue = null; String sessionUpgradeSSOTokenId = null; try { restAuthenticationHandler.initiateAuthentication(request, httpResponse, authIndexType, indexValue, sessionUpgradeSSOTokenId); } catch (RestAuthException e) { assertEquals(e.getStatusCode(), 400); return; } fail(); }
@Test public void shouldCleanupAfterAuthenticationComplete() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); String module = "LDAP"; String existingSesssionId = "session1"; AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class); LoginProcess loginProcess = mock(LoginProcess.class); given(loginProcess.getLoginStage()).willReturn(LoginStage.COMPLETE); given(loginProcess.isSuccessful()).willReturn(true); given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper); given(loginAuthenticator.getLoginProcess(Matchers.<LoginConfiguration>anyObject())).willReturn(loginProcess); restAuthenticationHandler.initiateAuthentication(request, response, "module", module, existingSesssionId); verify(loginProcess).cleanup(); }