ImportExportResolver { public void resolveBundleWiring(ExtendedBundleInformation bundleInfo) { List<PackageInfo> imports = new ArrayList<>(); List<PackageInfo> exports = new ArrayList<>(); Bundle bundle = bundleContext.getBundle(bundleInfo.getBundleId()); ExportedPackage[] allExportedPackages = packageAdmin.getExportedPackages((Bundle) null); for (ExportedPackage exportedPackage : allExportedPackages) { if (isImportedByBundle(exportedPackage, bundle)) { PackageInfo importInfo = new PackageInfo(exportedPackage); imports.add(importInfo); } if (exportedPackage.getExportingBundle().equals(bundle)) { PackageInfo exportInfo = new PackageInfo(exportedPackage); exports.add(exportInfo); } } bundleInfo.setBundleExports(exports); bundleInfo.setBundleImports(imports); }  void resolveBundleWiring(ExtendedBundleInformation bundleInfo); void refreshPackage(Bundle bundle);  }
@Test public void testResolveImportExport() { ExportedPackage[] allExportedPackages = new ExportedPackage[] { exportedPackage, importedPackage, unrelatedPackage, secondImportedPackage }; long bundleId = 1; when(bundle.getBundleId()).thenReturn(bundleId); when(bundle.getSymbolicName()).thenReturn("my.bundle"); when(bundle.getHeaders()).thenReturn(headers); when(otherBundle.getSymbolicName()).thenReturn("other.bundle"); when(bundleContext.getBundle(bundleId)).thenReturn(bundle); when(packageAdmin.getExportedPackages((Bundle) null)).thenReturn(allExportedPackages); setUpExport(exportedPackage, bundle, new Bundle[]{ otherBundle }, "my.export", exportedVersion); setUpExport(unrelatedPackage, otherBundle, new Bundle[]{ }, "unrelated", exportedVersion); setUpExport(importedPackage, otherBundle, new Bundle[]{ bundle }, "my.import", importedVersion); setUpExport(secondImportedPackage, otherBundle, new Bundle[]{ bundle }, "my.import.number.two", secondImportedVersion); ExtendedBundleInformation bundleInfo = new ExtendedBundleInformation(bundle); importExportResolver.resolveBundleWiring(bundleInfo); assertEquals(expectedExports(), bundleInfo.getBundleExports()); assertEquals(expectedImports(), bundleInfo.getBundleImports()); }