PackageTally { public Set<String> referencedPackagesMissingFrom(Set<String> definedAndExportedPackages) { return Sets.difference(referencedPackages(), definedAndExportedPackages).stream() .filter(pkg -> !pkg.startsWith("java.")) .filter(pkg -> !pkg.equals(com.yahoo.api.annotations.PublicApi.class.getPackageName())) .collect(Collectors.toSet()); } @VisibleForTesting  PackageTally(Map<String, Optional<ExportPackageAnnotation>> definedPackagesMap, Set<String> referencedPackagesUnfiltered); Set<String> definedPackages(); Set<String> referencedPackages(); Map<String, ExportPackageAnnotation> exportedPackages(); Set<String> referencedPackagesMissingFrom(Set<String> definedAndExportedPackages); PackageTally combine(PackageTally other); static PackageTally combine(Collection<PackageTally> packageTallies); static PackageTally fromAnalyzedClassFiles(Collection<ClassFileMetaData> analyzedClassFiles);  }
@Test public void referenced_packages_missing_from_are_detected() { PackageTally tally = new PackageTally(emptyMap(), Set.of("p1", "java.util", "com.yahoo.api.annotations", "missing")); Set<String> missingPackages = tally.referencedPackagesMissingFrom(Set.of("p1")); assertThat(missingPackages, is(Set.of("missing"))); }