### Question:
IDPSSOFederate { @VisibleForTesting void process(final HttpServletRequest request, final HttpServletResponse response, final PrintWriter out, final String reqBinding) throws FederatedSSOException, IOException, SessionException { if (cookieRedirector.needSetLBCookieAndRedirect(request, response, true)) { return; } final IDPRequestValidator validator = saml2ActorFactory.getIDPRequestValidator(reqBinding, isFromECP); String requestID = request.getParameter("requestID"); if (idpProxyCase(requestID, request, response)) { return; } String idpMetaAlias = validator.getMetaAlias(request); String realm = validator.getRealmByMetaAlias(idpMetaAlias); String idpEntityID = validator.getIDPEntity(idpMetaAlias, realm); SAML2IdentityProviderAdapter idpAdapter = validator.getIDPAdapter(realm, idpEntityID); String reqID = request.getParameter(REQ_ID); if (null != auditor) { if (StringUtils.isNotEmpty(reqID)) { auditor.setRequestId(reqID); } auditor.setRealm(realm); } IDPSSOFederateRequest reqData = new IDPSSOFederateRequest(reqID, realm, idpAdapter, idpMetaAlias, idpEntityID); reqData.setEventAuditor(auditor); if (StringUtils.isEmpty(reqData.getRequestID())) { SAMLAuthenticator samlAuthenticator = saml2ActorFactory.getSAMLAuthenticator(reqData, request, response, out, isFromECP); samlAuthenticator.authenticate(); } else { SAMLAuthenticatorLookup samlLookup = saml2ActorFactory.getSAMLAuthenticatorLookup(reqData, request, response, out); samlLookup.retrieveAuthenticationFromCache(); } } private  IDPSSOFederate(final boolean isFromECP); @VisibleForTesting  IDPSSOFederate(final boolean isFromECP,
                   final FederateCookieRedirector redirector,
                   final SAML2ActorFactory saml2ActorFactory); static void doSSOFederate(HttpServletRequest request,
                                     HttpServletResponse response,
                                     PrintWriter out,
                                     String reqBinding,
                                     SAML2EventLogger auditor); static void doSSOFederate(HttpServletRequest request, HttpServletResponse response, PrintWriter out,
                                     boolean isFromECP, String reqBinding, SAML2EventLogger auditor);  }### Answer:
@Test public void shouldBeTestable() throws Exception { idpSsoFederateRequest.process(mockRequest, mockResponse, mockPrintWriter, null); }
@Test public void shouldNotCallAnyFurtherFunctionsAfterNeedSetLBCookieAndRedirectReturnsTrue() throws Exception { when(cookieRedirector.needSetLBCookieAndRedirect( nullable(HttpServletRequest.class), nullable(HttpServletResponse.class), anyBoolean())).thenReturn(true); idpSsoFederateRequest.process(mockRequest, mockResponse, mockPrintWriter, null); Mockito.verifyZeroInteractions(authenticator, authenticationLookup); }
@Test public void shouldCallAuthenticateIfThereIsNoRequestId() throws Exception { when(mockRequest.getParameter("ReqID")).thenReturn(""); when(cookieRedirector.needSetLBCookieAndRedirect( nullable(HttpServletRequest.class), nullable(HttpServletResponse.class), anyBoolean())).thenReturn(false); idpSsoFederateRequest.process(mockRequest, mockResponse, mockPrintWriter, null); Mockito.verify(authenticator).authenticate(); Mockito.verifyZeroInteractions(authenticationLookup); }
@Test public void shouldCallAuthenticateLookupIfThereIsARequestId() throws Exception { when(mockRequest.getParameter("ReqID")).thenReturn("12345"); when(cookieRedirector.needSetLBCookieAndRedirect( nullable(HttpServletRequest.class), nullable(HttpServletResponse.class), anyBoolean())).thenReturn(false); idpSsoFederateRequest.process(mockRequest, mockResponse, mockPrintWriter, null); Mockito.verify(authenticationLookup).retrieveAuthenticationFromCache(); Mockito.verifyZeroInteractions(authenticator); }