Program: 96808
Project: 96808
Buggy source:
/** 
 * Verify that if relation validity is many to one, setRelation/setRelations will successfully remove one and add another
 */
@Test public void testSetRelationAndRelations_OneToMany(){
  String className=getClass().getSimpleName();
  IAtsChangeSet changes=createAtsChangeSet();
  ArtifactId ver1=changes.createArtifact(AtsArtifactTypes.Version,"String_Node_Str" + className);
  ArtifactId ver2=changes.createArtifact(AtsArtifactTypes.Version,"String_Node_Str" + className);
  ArtifactId teamWf=changes.createArtifact(AtsArtifactTypes.TeamWorkflow,"String_Node_Str" + className);
  changes.execute();
  changes=createAtsChangeSet();
  changes.setRelation(teamWf,AtsRelationTypes.TeamWorkflowTargetedForVersion_Version,ver1);
  changes.execute();
  ver1=atsServer.getArtifact(ver1.getId());
  ver2=atsServer.getArtifact(ver2.getId());
  teamWf=atsServer.getArtifact(teamWf.getId());
  Assert.assertEquals(ver1.getId(),atsServer.getVersionService().getTargetedVersion(atsServer.getWorkItemFactory().getTeamWf(teamWf)));
  changes=createAtsChangeSet();
  changes.setRelation(teamWf,AtsRelationTypes.TeamWorkflowTargetedForVersion_Version,ver2);
  changes.execute();
  ver1=atsServer.getArtifact(ver1.getId());
  ver2=atsServer.getArtifact(ver2.getId());
  teamWf=atsServer.getArtifact(teamWf.getId());
  Assert.assertEquals(ver2.getId(),atsServer.getVersionService().getTargetedVersion(atsServer.getWorkItemFactory().getTeamWf(teamWf)));
  Assert.assertEquals(0,((ArtifactReadable)ver1).getRelated(AtsRelationTypes.TeamWorkflowTargetedForVersion_Workflow).size());
}

Fixed version (ground truth):
/** 
 * Verify that if relation validity is many to one, setRelation/setRelations will successfully remove one and add another
 */
@Test public void testSetRelationAndRelations_OneToMany(){
  String className=getClass().getSimpleName();
  IAtsChangeSet changes=createAtsChangeSet();
  ArtifactId ver1=changes.createArtifact(AtsArtifactTypes.Version,"String_Node_Str" + className);
  ArtifactId ver2=changes.createArtifact(AtsArtifactTypes.Version,"String_Node_Str" + className);
  ArtifactId teamWf=changes.createArtifact(AtsArtifactTypes.TeamWorkflow,"String_Node_Str" + className);
  changes.execute();
  changes=createAtsChangeSet();
  changes.setRelation(teamWf,AtsRelationTypes.TeamWorkflowTargetedForVersion_Version,ver1);
  changes.execute();
  ver1=atsServer.getArtifact(ver1.getId());
  ver2=atsServer.getArtifact(ver2.getId());
  teamWf=atsServer.getArtifact(teamWf.getId());
  Assert.assertEquals(ver1.getId(),atsServer.getVersionService().getTargetedVersion(atsServer.getWorkItemFactory().getTeamWf(teamWf)).getId());
  changes=createAtsChangeSet();
  changes.setRelation(teamWf,AtsRelationTypes.TeamWorkflowTargetedForVersion_Version,ver2);
  changes.execute();
  ver1=atsServer.getArtifact(ver1.getId());
  ver2=atsServer.getArtifact(ver2.getId());
  teamWf=atsServer.getArtifact(teamWf.getId());
  Assert.assertEquals(ver2.getId(),atsServer.getVersionService().getTargetedVersion(atsServer.getWorkItemFactory().getTeamWf(teamWf)).getId());
  Assert.assertEquals(0,((ArtifactReadable)ver1).getRelated(AtsRelationTypes.TeamWorkflowTargetedForVersion_Workflow).size());
}