ServletRuntime { static ServletRuntime determineServletRuntime(Class<?> servletRequestClass, String asyncListenerClassname) { try { servletRequestClass.getMethod("getAsyncContext"); Class.forName(asyncListenerClassname); return new Servlet3Runtime(); } catch (Exception ex) { logger.warn( "Servlet 3 async requests are not supported on the current container. " + "RequestTracingFilter will default to blocking request behavior (Servlet 2.x). " + "Exception message indicating a Servlet 2.x environment: {}", ex.toString() ); return new Servlet2Runtime(); } }    }
@DataProvider(value = { "true | true | true", "true | false | false", "false | true | false", "false | false | false" }, splitBy = "\\|") @Test public void determineServletRuntime_returns_ServletRuntime_based_on_arguments( boolean classHasServlet3Method, boolean useAsyncListenerClassThatExists, boolean expectServlet3Runtime ) { Class<?> servletRequestClass = (classHasServlet3Method) ? GoodFakeServletRequest.class : BadFakeServletRequest.class; String asyncListenerClassname = (useAsyncListenerClassThatExists) ? AsyncListener.class.getName() : "does.not.exist.AsyncListener" + UUID.randomUUID().toString(); ServletRuntime result = ServletRuntime.determineServletRuntime(servletRequestClass, asyncListenerClassname); if (expectServlet3Runtime) { assertThat(result).isInstanceOf(Servlet3Runtime.class); } else { assertThat(result).isInstanceOf(Servlet2Runtime.class); } }