### Question:
GatewayDispatchFilter extends AbstractGatewayFilter { @Override protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String method = request.getMethod().toUpperCase(Locale.ROOT); Adapter adapter = METHOD_ADAPTERS.get(method); if (adapter != null) { if (isDispatchAllowed(request)) { try { adapter.doMethod(getDispatch(), request, response); } catch (URISyntaxException e) { throw new ServletException(e); } } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } else { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } }  @Override void init(FilterConfig filterConfig); @Override void destroy(); Dispatch getDispatch(); void setDispatch(Dispatch dispatch);  }### Answer:
@Test public void testServiceDispatchWhitelistViolation() throws Exception { final String serviceRole = "KNOXSSO"; GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(config.getDispatchWhitelistServices()).andReturn(Collections.emptyList()).anyTimes(); EasyMock.expect(config.getDispatchWhitelist()).andReturn(null).anyTimes(); EasyMock.replay(config); ServletContext sc = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(sc.getAttribute("org.apache.knox.gateway.config")).andReturn(config).anyTimes(); EasyMock.replay(sc); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(request.getMethod()).andReturn("GET").anyTimes(); EasyMock.expect(request.getServerName()).andReturn("localhost").anyTimes(); EasyMock.expect(request.getRequestURI()).andReturn("http: EasyMock.expect(request.getAttribute("targetServiceRole")).andReturn(serviceRole).anyTimes(); EasyMock.expect(request.getServletContext()).andReturn(sc).anyTimes(); EasyMock.replay(request); HttpServletResponse response = new TestHttpServletResponse(); (new GatewayDispatchFilter()).doFilter(request, response, null); assertEquals(400, response.getStatus()); }