### Question:
IpBlockFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (ipBlocker.accept(request.getRemoteAddr())) processDoFilter(request, response, chain); else sendNotFoundResponse((HttpServletResponse) response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); static final String RELOAD_COMMAND_PARAM_NAME_CONFIG_NAME; static final String DEFAULT_RELOAD_COMMAND_PARAM_NAME_VALUE; }### Answer:
@Test public void shouldRunChainWhenIpIsNotBlocked() throws ServletException, IOException { filterInit(); when(mockRequest.getRemoteAddr()).thenReturn(FakeIpBlocker.ALLOW_IP); filter.doFilter(mockRequest, mockResponse, mockFilterChain); verify(mockFilterChain, only()).doFilter(mockRequest, mockResponse); }
@Test public void shouldResponse404WhenIpIsBlocked() throws ServletException, IOException { filterInit(); when(mockRequest.getRemoteAddr()).thenReturn(DENY_IP); filter.doFilter(mockRequest, mockResponse, mockFilterChain); verify(mockFilterChain, never()).doFilter(mockRequest, mockResponse); verify(mockResponse, only()).sendError(HttpServletResponse.SC_NOT_FOUND); }
@Test public void shouldReloadWhenRequestHasReloadParameter() throws ServletException, IOException { filterInit(); when(mockRequest.getRemoteAddr()).thenReturn(FakeIpBlocker.ALLOW_IP); filter.doFilter(mockRequest, mockResponse, mockFilterChain); assertFalse(FakeIpBlocker.reloaded); when(mockRequest.getParameter("IBFRM")).thenReturn("true"); filter.doFilter(mockRequest, mockResponse, mockFilterChain); assertTrue(FakeIpBlocker.reloaded); }