Program: 20689
Project: 20689
Buggy source:
@Test public void updateDeleteManagedRepoWithStagedRepo() throws Exception {
  String repoId="String_Node_Str";
  String repoLocation=APPSERVER_BASE_PATH + File.separator + "String_Node_Str";
  String stageRepoLocation=APPSERVER_BASE_PATH + File.separator + repoId;
  File repoDir=clearRepoLocation(repoLocation);
  mockAuditListener.clearEvents();
  List<ManagedRepository> repos=managedRepositoryAdmin.getManagedRepositories();
  assertNotNull(repos);
  int initialSize=repos.size();
  assertTrue(initialSize > 0);
  ManagedRepository repo=new ManagedRepository();
  repo.setId(repoId);
  repo.setName("String_Node_Str");
  repo.setLocation(repoLocation);
  managedRepositoryAdmin.addManagedRepository(repo,false,getFakeAuditInformation());
  assertTemplateRoleExists(repoId);
  assertFalse(new File(repoLocation + STAGE_REPO_ID_END).exists());
  assertTemplateRoleNotExists(repoId + STAGE_REPO_ID_END);
  repos=managedRepositoryAdmin.getManagedRepositories();
  assertNotNull(repos);
  assertEquals(initialSize + 1,repos.size());
  String newName="String_Node_Str";
  repo.setName(newName);
  repo.setLocation(repoLocation);
  managedRepositoryAdmin.updateManagedRepository(repo,true,getFakeAuditInformation(),false);
  repo=managedRepositoryAdmin.getManagedRepository(repoId);
  assertNotNull(repo);
  assertEquals(newName,repo.getName());
  assertEquals(new File(repoLocation).getCanonicalPath(),new File(repo.getLocation()).getCanonicalPath());
  assertTrue(new File(repoLocation).exists());
  assertTemplateRoleExists(repoId);
  assertTrue(new File(stageRepoLocation + STAGE_REPO_ID_END).exists());
  assertTemplateRoleExists(repoId + STAGE_REPO_ID_END);
  managedRepositoryAdmin.deleteManagedRepository(repo.getId(),getFakeAuditInformation(),false);
  assertTrue(repoDir.exists());
  assertTemplateRoleNotExists(repoId);
  assertTrue(new File(stageRepoLocation + STAGE_REPO_ID_END).exists());
  assertTemplateRoleNotExists(repoId + STAGE_REPO_ID_END);
  assertAuditListenerCallAndUpdateAddAndDelete(true);
  mockAuditListener.clearEvents();
}

Fixed version (ground truth):
@Test public void updateDeleteManagedRepoWithStagedRepo() throws Exception {
  String repoId="String_Node_Str";
  String repoLocation=APPSERVER_BASE_PATH + File.separator + "String_Node_Str";
  String stageRepoLocation=APPSERVER_BASE_PATH + File.separator + repoId;
  File repoDir=clearRepoLocation(repoLocation);
  mockAuditListener.clearEvents();
  List<ManagedRepository> repos=managedRepositoryAdmin.getManagedRepositories();
  assertNotNull(repos);
  int initialSize=repos.size();
  assertTrue(initialSize > 0);
  ManagedRepository repo=getTestManagedRepository(repoId,repoLocation);
  managedRepositoryAdmin.addManagedRepository(repo,false,getFakeAuditInformation());
  assertTemplateRoleExists(repoId);
  assertFalse(new File(repoLocation + STAGE_REPO_ID_END).exists());
  assertTemplateRoleNotExists(repoId + STAGE_REPO_ID_END);
  repos=managedRepositoryAdmin.getManagedRepositories();
  assertNotNull(repos);
  assertEquals(initialSize + 1,repos.size());
  String newName="String_Node_Str";
  repo.setName(newName);
  repo.setLocation(repoLocation);
  managedRepositoryAdmin.updateManagedRepository(repo,true,getFakeAuditInformation(),false);
  repo=managedRepositoryAdmin.getManagedRepository(repoId);
  assertNotNull(repo);
  assertEquals(newName,repo.getName());
  assertEquals(new File(repoLocation).getCanonicalPath(),new File(repo.getLocation()).getCanonicalPath());
  assertTrue(new File(repoLocation).exists());
  assertEquals(getTestManagedRepository(repoId,repoLocation).getCronExpression(),repo.getCronExpression());
  assertEquals(getTestManagedRepository(repoId,repoLocation).getLayout(),repo.getLayout());
  assertEquals(getTestManagedRepository(repoId,repoLocation).getId(),repo.getId());
  assertTemplateRoleExists(repoId);
  assertTrue(new File(stageRepoLocation + STAGE_REPO_ID_END).exists());
  assertTemplateRoleExists(repoId + STAGE_REPO_ID_END);
  managedRepositoryAdmin.deleteManagedRepository(repo.getId(),getFakeAuditInformation(),false);
  assertTrue(repoDir.exists());
  assertTemplateRoleNotExists(repoId);
  assertTrue(new File(stageRepoLocation + STAGE_REPO_ID_END).exists());
  assertTemplateRoleNotExists(repoId + STAGE_REPO_ID_END);
  assertAuditListenerCallAndUpdateAddAndDelete(true);
  mockAuditListener.clearEvents();
}