Program: 39236
Project: 39236
Buggy source:
@Test public final void shouldCopyEntityWithoutInfinityCycleWith2Entities(){
  SampleSimpleDatabaseObject simpleDatabaseObject1=new SampleSimpleDatabaseObject();
  simpleDatabaseObject1.setId(1L);
  simpleDatabaseObject1.setName(SIMPLE_1);
  SampleSimpleDatabaseObject simpleDatabaseObject2=new SampleSimpleDatabaseObject();
  simpleDatabaseObject2.setId(2L);
  simpleDatabaseObject2.setName(SIMPLE_2);
  simpleDatabaseObject1.setBelongsToSimple(simpleDatabaseObject2);
  simpleDatabaseObject2.setBelongsToSimple(simpleDatabaseObject1);
  stubSessionGet(simpleDatabaseObject1);
  stubSessionGet(simpleDatabaseObject2);
  List<Entity> entities=null;
  try {
    entities=dataDefinition.copy(new Long[]{simpleDatabaseObject1.getId()});
  }
 catch (  StackOverflowError e) {
    Assert.fail();
  }
  final ArgumentCaptor<SampleSimpleDatabaseObject> argCaptor=ArgumentCaptor.forClass(SampleSimpleDatabaseObject.class);
  verify(session,times(1)).save(Mockito.any(SampleSimpleDatabaseObject.class));
  verify(session,times(1)).save(argCaptor.capture());
  final SampleSimpleDatabaseObject savedObject=argCaptor.getValue();
  assertEquals(SIMPLE_1,savedObject.getName());
  assertFalse(simpleDatabaseObject1.getId().equals(savedObject.getId()));
  assertEquals(SIMPLE_2,savedObject.getBelongsToSimple().getName());
  assertEquals(simpleDatabaseObject2.getId(),savedObject.getBelongsToSimple().getId());
  assertEquals(1,entities.size());
  assertTrue(entities.get(0).isValid());
  final Entity entityCopy=entities.get(0);
  Assert.assertEquals(SIMPLE_1,entityCopy.getField(NAME));
  Assert.assertEquals(SIMPLE_2,entityCopy.getBelongsToField(BELONGS_TO_SIMPLE).getField(NAME));
  Assert.assertEquals(Long.valueOf(2L),entityCopy.getBelongsToField(BELONGS_TO_SIMPLE).getId());
  assertFalse(simpleDatabaseObject1.getId().equals(entityCopy.getId()));
}

Fixed version (ground truth):
@Test public void shouldCopyEntityWithoutInfinityCycleWith2Entities(){
  SampleSimpleDatabaseObject simpleDatabaseObject1=new SampleSimpleDatabaseObject();
  simpleDatabaseObject1.setId(1L);
  simpleDatabaseObject1.setName(SIMPLE_1);
  SampleSimpleDatabaseObject simpleDatabaseObject2=new SampleSimpleDatabaseObject();
  simpleDatabaseObject2.setId(2L);
  simpleDatabaseObject2.setName(SIMPLE_2);
  simpleDatabaseObject1.setBelongsToSimple(simpleDatabaseObject2);
  simpleDatabaseObject2.setBelongsToSimple(simpleDatabaseObject1);
  stubSessionGet(simpleDatabaseObject1);
  stubSessionGet(simpleDatabaseObject2);
  List<Entity> entities=null;
  try {
    entities=dataDefinition.copy(new Long[]{simpleDatabaseObject1.getId()});
  }
 catch (  StackOverflowError e) {
    Assert.fail();
  }
  final ArgumentCaptor<SampleSimpleDatabaseObject> argCaptor=ArgumentCaptor.forClass(SampleSimpleDatabaseObject.class);
  verify(session,times(1)).save(Mockito.any(SampleSimpleDatabaseObject.class));
  verify(session,times(1)).save(argCaptor.capture());
  final SampleSimpleDatabaseObject savedObject=argCaptor.getValue();
  assertEquals(SIMPLE_1,savedObject.getName());
  assertFalse(simpleDatabaseObject1.getId().equals(savedObject.getId()));
  assertEquals(SIMPLE_2,savedObject.getBelongsToSimple().getName());
  assertEquals(simpleDatabaseObject2.getId(),savedObject.getBelongsToSimple().getId());
  assertEquals(1,entities.size());
  assertTrue(entities.get(0).isValid());
  final Entity entityCopy=entities.get(0);
  Assert.assertEquals(SIMPLE_1,entityCopy.getField(NAME));
  Assert.assertEquals(SIMPLE_2,entityCopy.getBelongsToField(BELONGS_TO_SIMPLE).getField(NAME));
  Assert.assertEquals(Long.valueOf(2L),entityCopy.getBelongsToField(BELONGS_TO_SIMPLE).getId());
  assertFalse(simpleDatabaseObject1.getId().equals(entityCopy.getId()));
}