Program: 188644
Project: 188644
Buggy source:
@Test public void testVirusCheck() throws RODAException, FileAlreadyExistsException, InterruptedException, IOException, SolrServerException {
  AIP aip=ingestCorpora();
  Plugin<AIP> plugin=RodaCoreFactory.getPluginManager().getPlugin(AntivirusPlugin.class.getCanonicalName(),AIP.class.getName());
  Map<String,String> parameters=new HashMap<>();
  parameters.put(RodaConstants.PLUGIN_PARAMS_JOB_ID,FAKE_JOB_ID);
  plugin.setParameterValues(parameters);
  List<String> aipIdList=Arrays.asList(aip.getId());
  RodaCoreFactory.getPluginOrchestrator().runPluginOnAIPs(null,plugin,aipIdList,false);
  Thread.sleep(1000);
  aip=model.retrieveAIP(aip.getId());
  String agentID=plugin.getClass().getName() + "String_Node_Str" + plugin.getVersion();
  boolean found=false;
  CloseableIterable<OptionalWithCause<PreservationMetadata>> preservationMetadataList=model.listPreservationMetadata(aip.getId(),true);
  for (  OptionalWithCause<PreservationMetadata> opm : preservationMetadataList) {
    if (opm.isPresent()) {
      PreservationMetadata pm=opm.get();
      if (pm.getType().equals(PreservationMetadataType.EVENT)) {
        try {
          EventComplexType event=PremisV3Utils.binaryToEvent(model.retrievePreservationEvent(pm.getAipId(),pm.getRepresentationId(),pm.getId()).getContent().createInputStream());
          if (event.getLinkingAgentIdentifierArray() != null && event.getLinkingAgentIdentifierArray().length > 0) {
            for (            LinkingAgentIdentifierComplexType laict : event.getLinkingAgentIdentifierArray()) {
              if (laict.getLinkingAgentIdentifierValue() != null && laict.getLinkingAgentIdentifierValue().equalsIgnoreCase(agentID)) {
                found=true;
                break;
              }
            }
            if (found) {
              break;
            }
          }
        }
 catch (        XmlException|IOException e) {
        }
      }
    }
  }
  IOUtils.closeQuietly(preservationMetadataList);
  Assert.assertTrue(found);
  index.commitAIPs();
  Filter filter=new Filter();
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_TYPE,PreservationEventType.VIRUS_CHECK.toString()));
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_AIP_ID,aip.getId()));
  IndexResult<IndexedPreservationEvent> events=index.find(IndexedPreservationEvent.class,filter,null,new Sublist(0,10));
  Assert.assertEquals(1,events.getTotalCount());
}

Fixed version (ground truth):
@Test public void testVirusCheck() throws RODAException, FileAlreadyExistsException, InterruptedException, IOException, SolrServerException {
  AIP aip=ingestCorpora();
  Plugin<AIP> plugin=RodaCoreFactory.getPluginManager().getPlugin(AntivirusPlugin.class.getCanonicalName(),AIP.class);
  Map<String,String> parameters=new HashMap<>();
  parameters.put(RodaConstants.PLUGIN_PARAMS_JOB_ID,FAKE_JOB_ID);
  plugin.setParameterValues(parameters);
  List<String> aipIdList=Arrays.asList(aip.getId());
  RodaCoreFactory.getPluginOrchestrator().runPluginOnAIPs(null,plugin,aipIdList,false);
  Thread.sleep(1000);
  aip=model.retrieveAIP(aip.getId());
  String agentID=plugin.getClass().getName() + "String_Node_Str" + plugin.getVersion();
  boolean found=false;
  CloseableIterable<OptionalWithCause<PreservationMetadata>> preservationMetadataList=model.listPreservationMetadata(aip.getId(),true);
  for (  OptionalWithCause<PreservationMetadata> opm : preservationMetadataList) {
    if (opm.isPresent()) {
      PreservationMetadata pm=opm.get();
      if (pm.getType().equals(PreservationMetadataType.EVENT)) {
        try {
          EventComplexType event=PremisV3Utils.binaryToEvent(model.retrievePreservationEvent(pm.getAipId(),pm.getRepresentationId(),pm.getId()).getContent().createInputStream());
          if (event.getLinkingAgentIdentifierArray() != null && event.getLinkingAgentIdentifierArray().length > 0) {
            for (            LinkingAgentIdentifierComplexType laict : event.getLinkingAgentIdentifierArray()) {
              if (laict.getLinkingAgentIdentifierValue() != null && laict.getLinkingAgentIdentifierValue().equalsIgnoreCase(agentID)) {
                found=true;
                break;
              }
            }
            if (found) {
              break;
            }
          }
        }
 catch (        XmlException|IOException e) {
        }
      }
    }
  }
  IOUtils.closeQuietly(preservationMetadataList);
  Assert.assertTrue(found);
  index.commitAIPs();
  Filter filter=new Filter();
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_TYPE,PreservationEventType.VIRUS_CHECK.toString()));
  filter.add(new SimpleFilterParameter(RodaConstants.PRESERVATION_EVENT_AIP_ID,aip.getId()));
  IndexResult<IndexedPreservationEvent> events=index.find(IndexedPreservationEvent.class,filter,null,new Sublist(0,10));
  Assert.assertEquals(1,events.getTotalCount());
}