PackageState implements PackageStateMBean { public long[] getImportingBundles(String packageName, String version, long exportingBundle) throws IOException { if (packageName == null || packageName.length() < 1) { throw new IOException("Package name cannot be null or empty"); } ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(packageName); if (exportedPackages != null) { Version ver = Version.parseVersion(version); for (ExportedPackage exportedPackage : exportedPackages) { if (exportedPackage.getVersion().equals(ver) && exportedPackage.getExportingBundle().getBundleId() == exportingBundle) { Bundle[] bundles = exportedPackage.getImportingBundles(); if (bundles != null) { return FrameworkUtils.getBundleIds(bundles); } } } } return null; } PackageState(BundleContext context, PackageAdmin packageAdmin); long[] getExportingBundles(String packageName, String version); long[] getImportingBundles(String packageName, String version, long exportingBundle); boolean isRemovalPending(String packageName, String version, long exportingBundle); TabularData listPackages();  }
@Test public void testGetImportingBundles() throws IOException { ExportedPackage exported = Mockito.mock(ExportedPackage.class); Bundle bundle = Mockito.mock(Bundle.class); Bundle exportingBundle = Mockito.mock(Bundle.class); Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0")); Mockito.when(exported.getExportingBundle()).thenReturn(exportingBundle); Mockito.when(exportingBundle.getBundleId()).thenReturn(Long.valueOf(2)); Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[]{bundle}); Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(4)); Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[]{exported}); long[] ids = mbean.getImportingBundles("test", "1.0.0", 2); Assert.assertArrayEquals(new long[]{4}, ids); }