### Question:
PackageNameWhiteListServiceImpl implements PackageNameWhiteListService { @Override public WhiteList filterPackageNames(final Module module, final Collection<String> packageNames) { if (packageNames == null) { return new WhiteList(); } else if (module instanceof KieModule) { final WhiteList whiteList = load(((KieModule) module).getPackageNamesWhiteListPath()); if (whiteList.isEmpty()) { return new WhiteList(packageNames); } else { for (Package aPackage : moduleService.resolvePackages(module)) { whiteList.add(aPackage.getPackageName()); } return new PackageNameWhiteListFilter(packageNames, whiteList).getFilteredPackageNames(); } } else { return new WhiteList(packageNames); } } PackageNameWhiteListServiceImpl(); @Inject  PackageNameWhiteListServiceImpl(final @Named("ioStrategy") IOService ioService,
                                           final KieModuleService moduleService,
                                           final PackageNameWhiteListLoader loader,
                                           final PackageNameWhiteListSaver saver); void createModuleWhiteList(final Path packageNamesWhiteListPath,
                                                            final String initialContent); @Override WhiteList filterPackageNames(final Module module,
                                        final Collection<String> packageNames); @Override WhiteList load(final Path packageNamesWhiteListPath); @Override Path save(final Path path,
                     final WhiteList content,
                     final Metadata metadata,
                     final String comment);  }### Answer:
@Test public void ifWhiteListIsEmptyWhiteListEverything() throws Exception { final PackageNameWhiteListService packageNameWhiteListService = makeService(""); WhiteList filterPackageNames = packageNameWhiteListService.filterPackageNames(mock(KieModule.class), new ArrayList<String> () {{ add("a"); add("b"); add("c"); }}); assertEquals(3, filterPackageNames.size()); assertTrue(filterPackageNames.contains("a")); assertTrue(filterPackageNames.contains("b")); assertTrue(filterPackageNames.contains("c")); }
@Test public void testWindowsEncoding() { final PackageNameWhiteListService packageNameWhiteListService = makeService("a.**\r\nb\r\n"); final Set<String> results = packageNameWhiteListService.filterPackageNames(mock(KieModule.class), new ArrayList<String>() {{ add("a"); add("b"); add("a.b"); }}); assertEquals(3, results.size()); assertContains("a", results); assertContains("b", results); assertContains("a.b", results); }
@Test public void testUnixEncoding() { final PackageNameWhiteListService packageNameWhiteListService = makeService("a.**\nb\n"); final Set<String> results = packageNameWhiteListService.filterPackageNames(mock(KieModule.class), new ArrayList<String>() {{ add("a"); add("b"); add("a.b"); }}); assertEquals(3, results.size()); assertContains("a", results); assertContains("b", results); assertContains("a.b", results); }