PackageState implements PackageStateMBean { public boolean isRemovalPending(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 && exportedPackage.isRemovalPending()) { return true; } } } return false; } 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 testIsRemovalPending() throws IOException { ExportedPackage exported = Mockito.mock(ExportedPackage.class); Bundle expBundle = Mockito.mock(Bundle.class); Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0")); Mockito.when(exported.isRemovalPending()).thenReturn(true); Mockito.when(exported.getExportingBundle()).thenReturn(expBundle); Mockito.when(expBundle.getBundleId()).thenReturn(Long.valueOf(2)); Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[]{exported}); boolean isRemoval = mbean.isRemovalPending("test", "1.0.0", Long.valueOf(2)); Assert.assertTrue(isRemoval); }