### Question:
UnloadableStaticPluginFactory implements PluginFactory { public String canCreate(PluginArtifact pluginArtifact) throws PluginParseException { Validate.notNull(pluginArtifact, "The plugin artifact is required"); InputStream descriptorStream = null; try { descriptorStream = pluginArtifact.getResourceAsStream(pluginDescriptorFileName); if (descriptorStream != null) { final DescriptorParser descriptorParser = descriptorParserFactory.getInstance(descriptorStream); if (descriptorParser.getPluginsVersion() == 1) { return descriptorParser.getKey(); } } } finally { IOUtils.closeQuietly(descriptorStream); } return null; } UnloadableStaticPluginFactory(String pluginDescriptorFileName); String canCreate(PluginArtifact pluginArtifact); Plugin create(DeploymentUnit deploymentUnit, ModuleDescriptorFactory moduleDescriptorFactory); Plugin create(PluginArtifact pluginArtifact, ModuleDescriptorFactory moduleDescriptorFactory);  }### Answer:
@Test public void testCanCreate() { UnloadableStaticPluginFactory factory = new UnloadableStaticPluginFactory("foo.xml"); PluginArtifact artifact = mock(PluginArtifact.class); when(artifact.getResourceAsStream("foo.xml")).thenReturn(new ByteArrayInputStream( "<maera-plugin key=\"foo\" />".getBytes() )); assertEquals("foo", factory.canCreate(artifact)); }
@Test public void testCanCreateWithNoDescriptor() { UnloadableStaticPluginFactory factory = new UnloadableStaticPluginFactory("foo.xml"); PluginArtifact artifact = mock(PluginArtifact.class); when(artifact.getResourceAsStream("foo.xml")).thenReturn(null); assertEquals(null, factory.canCreate(artifact)); }
@Test public void testCanCreateWithOsgi() { UnloadableStaticPluginFactory factory = new UnloadableStaticPluginFactory("foo.xml"); PluginArtifact artifact = mock(PluginArtifact.class); when(artifact.getResourceAsStream("foo.xml")).thenReturn(new ByteArrayInputStream( "<maera-plugin key=\"foo\" plugins-version=\"2\"/>".getBytes() )); assertEquals(null, factory.canCreate(artifact)); }