Program: 6849
Project: 6849
Buggy source:
@Test public void testPluginSelector() throws Exception {
  try {
    artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
    Assert.fail();
  }
 catch (  PluginNotExistsException e) {
  }
  Id.Artifact artifact1Id=Id.Artifact.from(Constants.DEFAULT_NAMESPACE_ID,"String_Node_Str","String_Node_Str");
  Manifest manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File jarFile=createJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  Set<ArtifactRange> parents=ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace(),APP_ARTIFACT_ID.getName(),new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str")));
  artifactRepository.inspectArtifact(artifact1Id,jarFile,parents);
  Map.Entry<ArtifactDescriptor,PluginClass> plugin=artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  Id.Artifact artifact2Id=Id.Artifact.from(Constants.DEFAULT_NAMESPACE_ID,"String_Node_Str","String_Node_Str");
  jarFile=createJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  artifactRepository.inspectArtifact(artifact2Id,jarFile,parents);
  plugin=artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  PluginInstantiator instantiator=new PluginInstantiator(cConf,appClassLoader);
  ClassLoader pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey());
  Class<?> pluginClass=pluginClassLoader.loadClass(TestPlugin2.class.getName());
  plugin=artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector(){
    @Override public Map.Entry<ArtifactDescriptor,PluginClass> select(    SortedMap<ArtifactDescriptor,PluginClass> plugins){
      return plugins.entrySet().iterator().next();
    }
  }
);
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey());
  Assert.assertNotSame(pluginClass,pluginClassLoader.loadClass(TestPlugin2.class.getName()));
  Class<?> cls=pluginClassLoader.loadClass(PluginTestRunnable.class.getName());
  Assert.assertSame(appClassLoader.loadClass(PluginTestRunnable.class.getName()),cls);
  cls=pluginClassLoader.loadClass(Application.class.getName());
  Assert.assertSame(Application.class,cls);
}

Fixed version (ground truth):
@Test public void testPluginSelector() throws Exception {
  try {
    artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
    Assert.fail();
  }
 catch (  PluginNotExistsException e) {
  }
  Id.Artifact artifact1Id=Id.Artifact.from(Constants.DEFAULT_NAMESPACE_ID,"String_Node_Str","String_Node_Str");
  Manifest manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File jarFile=createJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  Set<ArtifactRange> parents=ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace(),APP_ARTIFACT_ID.getName(),new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str")));
  artifactRepository.addArtifact(artifact1Id,jarFile,parents);
  Map.Entry<ArtifactDescriptor,PluginClass> plugin=artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  Id.Artifact artifact2Id=Id.Artifact.from(Constants.DEFAULT_NAMESPACE_ID,"String_Node_Str","String_Node_Str");
  jarFile=createJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  artifactRepository.addArtifact(artifact2Id,jarFile,parents);
  plugin=artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  PluginInstantiator instantiator=new PluginInstantiator(cConf,appClassLoader);
  ClassLoader pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey());
  Class<?> pluginClass=pluginClassLoader.loadClass(TestPlugin2.class.getName());
  plugin=artifactRepository.findPlugin(APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector(){
    @Override public Map.Entry<ArtifactDescriptor,PluginClass> select(    SortedMap<ArtifactDescriptor,PluginClass> plugins){
      return plugins.entrySet().iterator().next();
    }
  }
);
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey());
  Assert.assertNotSame(pluginClass,pluginClassLoader.loadClass(TestPlugin2.class.getName()));
  Class<?> cls=pluginClassLoader.loadClass(PluginTestRunnable.class.getName());
  Assert.assertSame(appClassLoader.loadClass(PluginTestRunnable.class.getName()),cls);
  cls=pluginClassLoader.loadClass(Application.class.getName());
  Assert.assertSame(Application.class,cls);
}