### Question:
PackageFilter { public boolean isAllowedPackage(String packageName) { if (packageSet.isEmpty()) { return true; } for (String validPackage : packageSet) { if (packageName.startsWith(validPackage)) { return true; } } return false; } PackageFilter(String config); boolean isAllowedPackage(String packageName); int getNumberOfBasePackages();  }### Answer:
@Test public void testEmptyFilter() { assertTrue(new PackageFilter(null).isAllowedPackage("com.ocpsoft")); assertTrue(new PackageFilter("").isAllowedPackage("com.ocpsoft")); assertTrue(new PackageFilter(" ").isAllowedPackage("com.ocpsoft")); assertTrue(new PackageFilter(" ,, ").isAllowedPackage("com.ocpsoft")); }
@Test public void testSinglePackage() { PackageFilter filter = new PackageFilter("com.ocpsoft"); assertEquals(true, filter.isAllowedPackage("com.ocpsoft.pretty.faces")); assertEquals(true, filter.isAllowedPackage("com.ocpsoft")); assertEquals(false, filter.isAllowedPackage("com")); assertEquals(false, filter.isAllowedPackage("de")); assertEquals(true, new PackageFilter(" com.ocpsoft ").isAllowedPackage("com.ocpsoft.pretty.faces")); assertEquals(true, new PackageFilter(" , com.ocpsoft, ").isAllowedPackage("com.ocpsoft.pretty.faces")); }
@Test public void testMultiplePackages() { PackageFilter filter = new PackageFilter("com.ocpsoft,de.chkal"); assertEquals(true, filter.isAllowedPackage("com.ocpsoft.pretty.faces")); assertEquals(true, filter.isAllowedPackage("com.ocpsoft")); assertEquals(true, filter.isAllowedPackage("de.chkal.bla")); assertEquals(true, filter.isAllowedPackage("de.chkal")); assertEquals(false, filter.isAllowedPackage("com")); assertEquals(false, filter.isAllowedPackage("com.google")); assertEquals(false, filter.isAllowedPackage("de")); assertEquals(true, new PackageFilter(" com.ocpsoft , de.chkal ").isAllowedPackage("com.ocpsoft.pretty.faces")); assertEquals(true, new PackageFilter(" , com.ocpsoft, de.chkal ,,").isAllowedPackage("de.chkal.bla")); }