### Question:
OsgiPluginFactory 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); } OsgiPluginFactory(String pluginDescriptorFileName, String applicationKey, OsgiPersistentCache persistentCache, OsgiContainerManager osgi, PluginEventManager pluginEventManager);  OsgiPluginFactory(String pluginDescriptorFileName, Set<String> applicationKeys, OsgiPersistentCache persistentCache, OsgiContainerManager osgi, PluginEventManager pluginEventManager); String canCreate(PluginArtifact pluginArtifact); Plugin create(DeploymentUnit deploymentUnit, ModuleDescriptorFactory moduleDescriptorFactory); Plugin create(PluginArtifact pluginArtifact, ModuleDescriptorFactory moduleDescriptorFactory);  }### Answer:
@Test public void testCreateOsgiPlugin() throws PluginParseException { mockBundle.expectAndReturn("getSymbolicName", "plugin.key"); when(osgiContainerManager.getHostComponentRegistrations()).thenReturn(new ArrayList<HostComponentRegistration>()); when(osgiContainerManager.getBundles()).thenReturn(new Bundle[]{(Bundle) mockSystemBundle.proxy()}); final Plugin plugin = factory.create(new JarPluginArtifact(jar), (ModuleDescriptorFactory) new Mock(ModuleDescriptorFactory.class).proxy()); assertNotNull(plugin); assertTrue(plugin instanceof OsgiPlugin); }
@Test public void testCreateOsgiPluginWithBadVersion() throws PluginParseException, IOException { jar = new PluginJarBuilder("someplugin").addPluginInformation("plugin.key", "My Plugin", "beta.1.0").build(); mockBundle.expectAndReturn("getSymbolicName", "plugin.key"); when(osgiContainerManager.getHostComponentRegistrations()).thenReturn(new ArrayList<HostComponentRegistration>()); when(osgiContainerManager.getBundles()).thenReturn(new Bundle[]{(Bundle) mockSystemBundle.proxy()}); try { factory.create(new JarPluginArtifact(jar), (ModuleDescriptorFactory) new Mock(ModuleDescriptorFactory.class).proxy()); fail("Should have complained about osgi version"); } catch (PluginParseException ignored) { } }
@Test public void testCreateOsgiPluginWithBadVersion2() throws PluginParseException, IOException { jar = new PluginJarBuilder("someplugin").addPluginInformation("plugin.key", "My Plugin", "3.2-rc1").build(); mockBundle.expectAndReturn("getSymbolicName", "plugin.key"); when(osgiContainerManager.getHostComponentRegistrations()).thenReturn(new ArrayList<HostComponentRegistration>()); when(osgiContainerManager.getBundles()).thenReturn(new Bundle[]{(Bundle) mockSystemBundle.proxy()}); Plugin plugin = factory.create(new JarPluginArtifact(jar), (ModuleDescriptorFactory) new Mock(ModuleDescriptorFactory.class).proxy()); assertTrue(plugin instanceof OsgiPlugin); }