Framework implements FrameworkMBean { public void startBundle(long bundleIdentifier) throws IOException { Bundle bundle = FrameworkUtils.resolveBundle(context, bundleIdentifier); try { bundle.start(); } catch (Exception be) { IOException ioex = new IOException("Start of bundle with id " + bundleIdentifier + " failed with message: " + be.getMessage()); ioex.initCause(be); throw ioex; } } Framework(BundleContext context, StartLevel startLevel, PackageAdmin packageAdmin); long[] getDependencyClosure(long[] bundles); int getFrameworkStartLevel(); int getInitialBundleStartLevel(); String getProperty(String key); long[] getRemovalPendingBundles(); long installBundle(String location); long installBundleFromURL(String location, String url); InputStream createStream(String url); CompositeData installBundles(String[] locations); CompositeData installBundlesFromURL(String[] locations, String[] urls); void refreshBundle(long bundleIdentifier); boolean refreshBundleAndWait(long bundleIdentifier); void refreshBundles(long[] bundleIdentifiers); CompositeData refreshBundlesAndWait(long[] bundleIdentifiers); boolean resolveBundle(long bundleIdentifier); boolean resolveBundles(long[] bundleIdentifiers); CompositeData resolve(long[] bundleIdentifiers); void restartFramework(); void setBundleStartLevel(long bundleIdentifier, int newlevel); CompositeData setBundleStartLevels(long[] bundleIdentifiers, int[] newlevels); void setFrameworkStartLevel(int newlevel); void setInitialBundleStartLevel(int newlevel); void shutdownFramework(); void startBundle(long bundleIdentifier); CompositeData startBundles(long[] bundleIdentifiers); void stopBundle(long bundleIdentifier); CompositeData stopBundles(long[] bundleIdentifiers); void uninstallBundle(long bundleIdentifier); CompositeData uninstallBundles(long[] bundleIdentifiers); void updateBundle(long bundleIdentifier); void updateBundleFromURL(long bundleIdentifier, String url); CompositeData updateBundles(long[] bundleIdentifiers); CompositeData updateBundlesFromURL(long[] bundleIdentifiers, String[] urls); void updateFramework();  }
@Test public void testStartBundle() throws Exception { Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(context.getBundle(5)).thenReturn(bundle); mbean.startBundle(5); Mockito.verify(bundle).start(); Mockito.reset(context); Mockito.when(context.getBundle(6)).thenReturn(bundle); Mockito.doThrow(new BundleException("")).when(bundle).start(); try { mbean.startBundle(6); Assert.fail("Shouldn't go to this stage, BundleException was thrown"); } catch (IOException ioe) { } Mockito.when(context.getBundle(6)).thenReturn(null); try { mbean.startBundle(6); Assert.fail("IOException should be thrown"); } catch (IOException e) { } }