public static MockRequestContext create(final ApplicationContext applicationContext) throws Exception {
        val requestContext = new MockRequestContext();
        val request = new MockHttpServletRequest();
        val response = new MockHttpServletResponse();
        val externalContext = new MockExternalContext();
        externalContext.setNativeContext(new MockServletContext());
        externalContext.setNativeRequest(request);
        externalContext.setNativeResponse(response);
        externalContext.setLocale(Locale.ENGLISH);
        requestContext.setExternalContext(externalContext);
        RequestContextHolder.setRequestContext(requestContext);
        ExternalContextHolder.setExternalContext(externalContext);
        if (applicationContext != null) {
            val flow = (Flow) requestContext.getActiveFlow();
            flow.setApplicationContext(applicationContext);
        }
        return requestContext;
    }
This is {@link MockRequestContext}.

@author Misagh Moayyed
@since 6.6.0
core/cas-server-core-util-api/src/test/java/org/apereo/cas/util/MockRequestContext.java