PackageState implements PackageStateMBean { public long[] getExportingBundles(String packageName, String version) 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); List<Bundle> exportingBundles = new ArrayList<Bundle>(); for (ExportedPackage exportedPackage : exportedPackages) { if (exportedPackage.getVersion().equals(ver)) { Bundle bundle = exportedPackage.getExportingBundle(); exportingBundles.add(bundle); } } return FrameworkUtils.getBundleIds(exportingBundles); } 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 testGetExportingBundles() throws IOException { ExportedPackage exported = Mockito.mock(ExportedPackage.class); Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0")); Mockito.when(exported.getExportingBundle()).thenReturn(bundle); Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(5)); ExportedPackage exported2 = Mockito.mock(ExportedPackage.class); Bundle bundle2 = Mockito.mock(Bundle.class); Mockito.when(exported2.getVersion()).thenReturn(Version.parseVersion("1.0.0")); Mockito.when(exported2.getExportingBundle()).thenReturn(bundle2); Mockito.when(bundle2.getBundleId()).thenReturn(Long.valueOf(6)); Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[]{exported, exported2}); long[] ids = mbean.getExportingBundles("test", "1.0.0"); Assert.assertNotNull(ids); Assert.assertArrayEquals(new long[]{5,6}, ids); }