### Question:
SAML2Proxy { protected static String getUrlWithKey(final HttpServletRequest req, final String key) { final StringBuilder value = getLocationValue(req); if (value == null) { throw new IllegalStateException(DEFAULT_ERROR_MESSAGE); } return encodeMessage(value, key); } private  SAML2Proxy(); static void processSamlResponse(HttpServletRequest request, HttpServletResponse response, PrintWriter out); static final String RESPONSE_KEY; static final String DEFAULT_ERROR_MESSAGE; static final String BAD_REQUEST; static final String MISSING_COOKIE; static final String MISSING_META_MANAGER; static final String META_DATA_ERROR; static final String SAML_GET_RESPONSE_ERROR; static final String SAML_VERIFY_RESPONSE_ERROR; static final String SAML_FAILOVER_DISABLED_ERROR; static final String ERROR_PARAM_KEY; static final String ERROR_CODE_PARAM_KEY; static final String ERROR_MESSAGE_PARAM_KEY; }### Answer:
@Test public void shouldCreateValidUrlFromDataViaPOST() { HttpServletRequest mockRequest = mock(HttpServletRequest.class); given(mockRequest.getCookies()).willReturn(validCookies); given(mockRequest.getMethod()).willReturn("POST"); String result = SAML2Proxy.getUrlWithKey(mockRequest, KEY); assertThat(result).contains(COOKIE_LOCATION); assertThat(result).contains(SAML2Proxy.RESPONSE_KEY + "=" + KEY); assertThat(result).contains(SAML2Proxy.ERROR_PARAM_KEY + "=" + "false"); }
@Test public void shouldCreateValidUrlFromDataViaGET() { HttpServletRequest mockRequest = mock(HttpServletRequest.class); given(mockRequest.getCookies()).willReturn(validCookies); given(mockRequest.getMethod()).willReturn("GET"); String result = SAML2Proxy.getUrlWithKey(mockRequest, KEY); assertThat(result).contains(COOKIE_LOCATION); assertThat(result).contains(SAML2Proxy.RESPONSE_KEY + "=" + KEY); assertThat(result).contains(SAML2Proxy.ERROR_PARAM_KEY + "=" + "false"); }
@Test(expectedExceptions = IllegalStateException.class) public void shouldErrorDueToEmptyAuthenticationStepCookiePOST() { HttpServletRequest mockRequest = mock(HttpServletRequest.class); given(mockRequest.getMethod()).willReturn("POST"); SAML2Proxy.getUrlWithKey(mockRequest, KEY); }
@Test(expectedExceptions = IllegalStateException.class) public void shouldErrorDueToEmptyAuthenticationStepCookieGET() { HttpServletRequest mockRequest = mock(HttpServletRequest.class); given(mockRequest.getMethod()).willReturn("GET"); SAML2Proxy.getUrlWithKey(mockRequest, KEY); }