### Question:
IPFilter implements Filter { public boolean accept(String ip) { if (whites.isEmpty() && blacks.isEmpty()) return true; if (!whites.isEmpty()) { for (String w : whites) { if (simpleMatch(ip, w)) return true; } return false; } if (blacks.isEmpty()) throw new IllegalStateException("cannot happen"); for (String b : blacks) { if (simpleMatch(ip, b)) return false; } return true; } IPFilter(String whiteList, String blackList); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); boolean accept(String ip); @Override void init(FilterConfig filterConfig); @Override void destroy(); boolean simpleMatch(String ip, String pattern);  }### Answer:
@Test public void testAcceptWhite() { IPFilter instance = new IPFilter("1.2.3.4, 4.5.67.1", ""); assertTrue(instance.accept("1.2.3.4")); assertTrue(instance.accept("4.5.67.1")); assertFalse(instance.accept("1.2.3.5")); instance = new IPFilter("1.2.3*, 4.5.67.1, 7.8.*.3", ""); assertTrue(instance.accept("1.2.3.4")); assertTrue(instance.accept("4.5.67.1")); assertTrue(instance.accept("1.2.3.5")); assertFalse(instance.accept("1.3.5.7")); assertTrue(instance.accept("7.8.5.3")); assertFalse(instance.accept("7.88.5.3")); }
@Test public void testAcceptBlack() { IPFilter instance = new IPFilter("", "1.2.3.4, 4.5.67.1"); assertFalse(instance.accept("1.2.3.4")); assertFalse(instance.accept("4.5.67.1")); assertTrue(instance.accept("1.2.3.5")); }
@Test public void testFilterSpecialCases() { IPFilter instance = new IPFilter("", ""); assertTrue(instance.accept("1.2.3.4")); try { new IPFilter("1.2.3.4, 4.5.67.1", "8.9.7.3"); assertFalse("black and white", true); } catch (Exception ex) { } }