### Question:
OsgiBundleFactory implements PluginFactory { public Plugin create(DeploymentUnit deploymentUnit, ModuleDescriptorFactory moduleDescriptorFactory) throws PluginParseException { Validate.notNull(deploymentUnit, "The deployment unit is required"); return create(new JarPluginArtifact(deploymentUnit.getPath()), moduleDescriptorFactory); } OsgiBundleFactory(OsgiContainerManager osgi, PluginEventManager pluginEventManager);  OsgiBundleFactory(String pluginDescriptorFileName, OsgiContainerManager osgi, PluginEventManager pluginEventManager); String canCreate(PluginArtifact pluginArtifact); Plugin create(DeploymentUnit deploymentUnit, ModuleDescriptorFactory moduleDescriptorFactory); Plugin create(PluginArtifact pluginArtifact, ModuleDescriptorFactory moduleDescriptorFactory);  }### Answer:
@Test public void testDeploy() throws PluginParseException, IOException { File bundle = new PluginJarBuilder("someplugin") .addResource("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n" + "Import-Package: javax.swing\n" + "Bundle-SymbolicName: my.foo.symbolicName\n") .build(); Mock mockBundle = new Mock(Bundle.class); Dictionary<String, String> dict = new Hashtable<String, String>(); dict.put(Constants.BUNDLE_DESCRIPTION, "desc"); dict.put(Constants.BUNDLE_VERSION, "1.0"); dict.put(Constants.BUNDLE_VENDOR, "acme"); dict.put(Constants.BUNDLE_NAME, "myplugin"); mockBundle.matchAndReturn("getHeaders", dict); mockBundle.expectAndReturn("getSymbolicName", "my.foo.symbolicName"); mockOsgi.expectAndReturn("installBundle", C.ANY_ARGS, mockBundle.proxy()); Plugin plugin = deployer.create(new JarPluginArtifact(bundle), (ModuleDescriptorFactory) new Mock(ModuleDescriptorFactory.class).proxy()); assertNotNull(plugin); assertTrue(plugin instanceof OsgiBundlePlugin); assertEquals("acme", plugin.getPluginInformation().getVendorName()); assertEquals("myplugin", plugin.getName()); assertEquals("desc", plugin.getPluginInformation().getDescription()); assertNull(plugin.getI18nNameKey()); mockOsgi.verify(); }
@Test public void testDeployFail() throws PluginParseException, IOException { File bundle = new PluginJarBuilder("someplugin") .addResource("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n" + "Import-Package: javax.swing\n" + "Bundle-SymbolicName: my.foo.symbolicName\n") .build(); mockOsgi.expectAndThrow("installBundle", C.ANY_ARGS, new OsgiContainerException("Bad install")); Plugin plugin = deployer.create(new JarPluginArtifact(bundle), (ModuleDescriptorFactory) new Mock(ModuleDescriptorFactory.class).proxy()); assertNotNull(plugin); assertTrue(plugin instanceof UnloadablePlugin); mockOsgi.verify(); }