Program: 172142
Project: 172142
Buggy source:
public void testGetWorkflows() throws Exception {
  String fakeDefId=getEngine() + "String_Node_Str";
  List<WorkflowInstance> workflows=workflowService.getActiveWorkflows(fakeDefId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getCompletedWorkflows(fakeDefId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getWorkflows(fakeDefId);
  assertTrue(workflows.isEmpty());
  WorkflowDefinition definition=deployDefinition(getTestDefinitionPath());
  String defId=definition.getId();
  workflows=workflowService.getActiveWorkflows(defId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getCompletedWorkflows(defId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getWorkflows(defId);
  assertTrue(workflows.isEmpty());
  Date dueDate=new Date();
  String description="String_Node_Str";
  NodeRef assignee=personManager.get(USER2);
  Serializable wfPackage1=workflowService.createPackage(null);
  Map<QName,Serializable> params=new HashMap<QName,Serializable>();
  params.put(WorkflowModel.ASSOC_PACKAGE,wfPackage1);
  params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE,dueDate);
  params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY,1);
  params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION,description);
  params.put(WorkflowModel.ASSOC_ASSIGNEE,assignee);
  WorkflowPath path1=workflowService.startWorkflow(defId,params);
  String instance1=path1.getInstance().getId();
  checkActiveWorkflows(defId,instance1);
  checkCompletedWorkflows(defId);
  checkWorkflows(defId,instance1);
  Serializable wfPackage2=workflowService.createPackage(null);
  params=new HashMap<QName,Serializable>();
  params.put(WorkflowModel.ASSOC_PACKAGE,wfPackage2);
  params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE,dueDate);
  params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY,1);
  params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION,description);
  params.put(WorkflowModel.ASSOC_ASSIGNEE,assignee);
  WorkflowPath path2=workflowService.startWorkflow(defId,params);
  String instance2=path2.getInstance().getId();
  checkActiveWorkflows(defId,instance1,instance2);
  checkCompletedWorkflows(defId);
  checkWorkflows(defId,instance1,instance2);
  WorkflowTask startTask1=workflowService.getStartTask(instance1);
  workflowService.endTask(startTask1.getId(),null);
  List<WorkflowTask> tasks=workflowService.getTasksForWorkflowPath(path1.getId());
  assertEquals(1,tasks.size());
  WorkflowTask task1=tasks.get(0);
  workflowService.endTask(task1.getId(),null);
  checkActiveWorkflows(defId,instance2);
  checkCompletedWorkflows(defId,instance1);
  checkWorkflows(defId,instance1,instance2);
  WorkflowTask startTask2=workflowService.getStartTask(instance2);
  workflowService.endTask(startTask2.getId(),null);
  tasks=workflowService.getTasksForWorkflowPath(path2.getId());
  assertEquals(1,tasks.size());
  WorkflowTask task2=tasks.get(0);
  workflowService.endTask(task2.getId(),null);
  checkActiveWorkflows(defId);
  checkCompletedWorkflows(defId,instance1,instance2);
  checkWorkflows(defId,instance1,instance2);
}

Fixed version (ground truth):
public void testGetWorkflows() throws Exception {
  String fakeDefId=getEngine() + "String_Node_Str";
  List<WorkflowInstance> workflows=workflowService.getActiveWorkflows(fakeDefId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getCompletedWorkflows(fakeDefId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getWorkflows(fakeDefId);
  assertTrue(workflows.isEmpty());
  WorkflowDefinition definition=deployDefinition(getTestDefinitionPath());
  String defId=definition.getId();
  workflows=workflowService.getActiveWorkflows(defId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getCompletedWorkflows(defId);
  assertTrue(workflows.isEmpty());
  workflows=workflowService.getWorkflows(defId);
  assertTrue(workflows.isEmpty());
  Date dueDate=new Date();
  String description="String_Node_Str";
  NodeRef assignee=personManager.get(USER2);
  Serializable wfPackage1=workflowService.createPackage(null);
  Map<QName,Serializable> params=new HashMap<QName,Serializable>();
  params.put(WorkflowModel.ASSOC_PACKAGE,wfPackage1);
  params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE,dueDate);
  params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY,1);
  params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION,description);
  params.put(WorkflowModel.ASSOC_ASSIGNEE,assignee);
  WorkflowPath path1=workflowService.startWorkflow(defId,params);
  String instance1=path1.getInstance().getId();
  checkActiveWorkflows(defId,instance1);
  checkCompletedWorkflows(defId);
  checkWorkflows(defId,instance1);
  Serializable wfPackage2=workflowService.createPackage(null);
  params=new HashMap<QName,Serializable>();
  params.put(WorkflowModel.ASSOC_PACKAGE,wfPackage2);
  params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE,dueDate);
  params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY,1);
  params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION,description);
  params.put(WorkflowModel.ASSOC_ASSIGNEE,assignee);
  WorkflowPath path2=workflowService.startWorkflow(defId,params);
  String instance2=path2.getInstance().getId();
  checkActiveWorkflows(defId,instance1,instance2);
  checkCompletedWorkflows(defId);
  checkWorkflows(defId,instance1,instance2);
  WorkflowTask startTask1=workflowService.getStartTask(instance1);
  workflowService.endTask(startTask1.getId(),null);
  List<WorkflowTask> tasks=workflowService.getTasksForWorkflowPath(path1.getId());
  assertEquals(1,tasks.size());
  WorkflowTask task1=tasks.get(0);
  workflowService.endTask(task1.getId(),null);
  checkActiveWorkflows(defId,instance2);
  checkCompletedWorkflows(defId,instance1);
  checkWorkflows(defId,instance1,instance2);
  checkWorkflowsContains(workflowService.getActiveWorkflows(),instance2);
  checkWorkflowsDontContain(workflowService.getActiveWorkflows(),instance1);
  checkWorkflowsContains(workflowService.getCompletedWorkflows(),instance1);
  checkWorkflowsDontContain(workflowService.getCompletedWorkflows(),instance2);
  checkWorkflowsContains(workflowService.getWorkflows(),instance1,instance2);
  WorkflowTask startTask2=workflowService.getStartTask(instance2);
  workflowService.endTask(startTask2.getId(),null);
  tasks=workflowService.getTasksForWorkflowPath(path2.getId());
  assertEquals(1,tasks.size());
  WorkflowTask task2=tasks.get(0);
  workflowService.endTask(task2.getId(),null);
  checkActiveWorkflows(defId);
  checkCompletedWorkflows(defId,instance1,instance2);
  checkWorkflows(defId,instance1,instance2);
}