Program: 174774
Project: 174774
Buggy source:
public void testWorkflowInstancesGet() throws Exception {
  personManager.setUser(USER1);
  WorkflowDefinition adhocDef=workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
  Map<QName,Serializable> params=new HashMap<QName,Serializable>();
  params.put(WorkflowModel.ASSOC_ASSIGNEE,personManager.get(USER2));
  Date dueDate=new Date();
  params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE,dueDate);
  params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY,1);
  params.put(WorkflowModel.ASSOC_PACKAGE,packageRef);
  params.put(WorkflowModel.PROP_CONTEXT,packageRef);
  WorkflowPath adhocPath=workflowService.startWorkflow(adhocDef.getId(),params);
  String WorkflowId=adhocPath.getInstance().getId();
  workflows.add(WorkflowId);
  WorkflowTask startTask=workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
  WorkflowInstance adhocInstance=startTask.getPath().getInstance();
  workflowService.endTask(startTask.getId(),null);
  Response response=sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES),200);
  assertEquals(Status.STATUS_OK,response.getStatus());
  String jsonStr=response.getContentAsString();
  JSONObject json=new JSONObject(jsonStr);
  JSONArray result=json.getJSONArray("String_Node_Str");
  assertNotNull(result);
  int totalItems=result.length();
  for (int i=0; i < result.length(); i++) {
    checkSimpleWorkflowInstanceResponse(result.getJSONObject(i));
  }
  Response forDefinitionResponse=sendRequest(new GetRequest(MessageFormat.format(URL_WORKFLOW_INSTANCES_FOR_DEFINITION,adhocDef.getId())),200);
  assertEquals(Status.STATUS_OK,forDefinitionResponse.getStatus());
  String forDefinitionJsonStr=forDefinitionResponse.getContentAsString();
  JSONObject forDefinitionJson=new JSONObject(forDefinitionJsonStr);
  JSONArray forDefinitionResult=forDefinitionJson.getJSONArray("String_Node_Str");
  assertNotNull(forDefinitionResult);
  for (int i=0; i < forDefinitionResult.length(); i++) {
    checkSimpleWorkflowInstanceResponse(forDefinitionResult.getJSONObject(i));
  }
  Calendar hourAgoCal=Calendar.getInstance();
  hourAgoCal.setTime(dueDate);
  hourAgoCal.add(Calendar.HOUR_OF_DAY,-1);
  Date anHourAgo=hourAgoCal.getTime();
  Calendar hourLater=Calendar.getInstance();
  hourLater.setTime(dueDate);
  hourLater.add(Calendar.HOUR_OF_DAY,1);
  Date anHourLater=hourLater.getTime();
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + USER1);
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourAgo));
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourLater));
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourAgo));
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourLater));
  if (adhocInstance.getEndDate() != null) {
    checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(adhocInstance.getEndDate()));
    checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(adhocInstance.getEndDate()));
  }
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str");
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str");
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + getAdhocWorkflowDefinitionName());
  int maxItems=3;
  for (int skipCount=0; skipCount < totalItems; skipCount+=maxItems) {
    checkPaging(URL_WORKFLOW_INSTANCES + "String_Node_Str" + maxItems+ "String_Node_Str"+ skipCount,totalItems,maxItems,skipCount);
  }
  String exclude=getAdhocWorkflowDefinitionName();
  response=sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES + "String_Node_Str" + exclude),200);
  assertEquals(Status.STATUS_OK,response.getStatus());
  jsonStr=response.getContentAsString();
  json=new JSONObject(jsonStr);
  JSONArray results=json.getJSONArray("String_Node_Str");
  assertNotNull(results);
  boolean adhocWorkflowPresent=false;
  for (int i=0; i < results.length(); i++) {
    JSONObject workflowInstanceJSON=results.getJSONObject(i);
    String type=workflowInstanceJSON.getString("String_Node_Str");
    if (exclude.equals(type)) {
      adhocWorkflowPresent=true;
      break;
    }
  }
  assertFalse("String_Node_Str",adhocWorkflowPresent);
}

Fixed version (ground truth):
public void testWorkflowInstancesGet() throws Exception {
  wfTestHelper.setVisible(false);
  personManager.setUser(USER1);
  WorkflowDefinition adhocDef=workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
  Map<QName,Serializable> params=new HashMap<QName,Serializable>();
  params.put(WorkflowModel.ASSOC_ASSIGNEE,personManager.get(USER2));
  Date dueDate=new Date();
  params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE,dueDate);
  params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY,1);
  params.put(WorkflowModel.ASSOC_PACKAGE,packageRef);
  params.put(WorkflowModel.PROP_CONTEXT,packageRef);
  WorkflowPath adhocPath=workflowService.startWorkflow(adhocDef.getId(),params);
  String WorkflowId=adhocPath.getInstance().getId();
  workflows.add(WorkflowId);
  WorkflowTask startTask=workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
  WorkflowInstance adhocInstance=startTask.getPath().getInstance();
  workflowService.endTask(startTask.getId(),null);
  Response response=sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES),200);
  assertEquals(Status.STATUS_OK,response.getStatus());
  String jsonStr=response.getContentAsString();
  JSONObject json=new JSONObject(jsonStr);
  JSONArray result=json.getJSONArray("String_Node_Str");
  assertNotNull(result);
  int totalItems=result.length();
  for (int i=0; i < result.length(); i++) {
    checkSimpleWorkflowInstanceResponse(result.getJSONObject(i));
  }
  Response forDefinitionResponse=sendRequest(new GetRequest(MessageFormat.format(URL_WORKFLOW_INSTANCES_FOR_DEFINITION,adhocDef.getId())),200);
  assertEquals(Status.STATUS_OK,forDefinitionResponse.getStatus());
  String forDefinitionJsonStr=forDefinitionResponse.getContentAsString();
  JSONObject forDefinitionJson=new JSONObject(forDefinitionJsonStr);
  JSONArray forDefinitionResult=forDefinitionJson.getJSONArray("String_Node_Str");
  assertNotNull(forDefinitionResult);
  for (int i=0; i < forDefinitionResult.length(); i++) {
    checkSimpleWorkflowInstanceResponse(forDefinitionResult.getJSONObject(i));
  }
  Calendar hourAgoCal=Calendar.getInstance();
  hourAgoCal.setTime(dueDate);
  hourAgoCal.add(Calendar.HOUR_OF_DAY,-1);
  Date anHourAgo=hourAgoCal.getTime();
  Calendar hourLater=Calendar.getInstance();
  hourLater.setTime(dueDate);
  hourLater.add(Calendar.HOUR_OF_DAY,1);
  Date anHourLater=hourLater.getTime();
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + USER1);
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourAgo));
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourLater));
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourAgo));
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(anHourLater));
  if (adhocInstance.getEndDate() != null) {
    checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(adhocInstance.getEndDate()));
    checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + ISO8601DateFormat.format(adhocInstance.getEndDate()));
  }
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str");
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str");
  checkFiltering(URL_WORKFLOW_INSTANCES + "String_Node_Str" + getAdhocWorkflowDefinitionName());
  int maxItems=3;
  for (int skipCount=0; skipCount < totalItems; skipCount+=maxItems) {
    checkPaging(URL_WORKFLOW_INSTANCES + "String_Node_Str" + maxItems+ "String_Node_Str"+ skipCount,totalItems,maxItems,skipCount);
  }
  String exclude=getAdhocWorkflowDefinitionName();
  response=sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES + "String_Node_Str" + exclude),200);
  assertEquals(Status.STATUS_OK,response.getStatus());
  jsonStr=response.getContentAsString();
  json=new JSONObject(jsonStr);
  JSONArray results=json.getJSONArray("String_Node_Str");
  assertNotNull(results);
  boolean adhocWorkflowPresent=false;
  for (int i=0; i < results.length(); i++) {
    JSONObject workflowInstanceJSON=results.getJSONObject(i);
    String type=workflowInstanceJSON.getString("String_Node_Str");
    if (exclude.equals(type)) {
      adhocWorkflowPresent=true;
      break;
    }
  }
  assertFalse("String_Node_Str",adhocWorkflowPresent);
}