Program: 96876
Project: 96876
Buggy source:
@Test public void testRelateWithSortingUserDefined() throws OseeCoreException {
  when(container1.getRelation(node1,TYPE_1,node2,INCLUDE_DELETED)).thenReturn(null);
  when(container2.getRelation(node1,TYPE_1,node2,INCLUDE_DELETED)).thenReturn(null);
  when(relationFactory.createRelation(node1,TYPE_1,node2)).thenReturn(relation1);
  when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1);
  List<Relation> toOrder=Arrays.asList(relation3,relation4);
  when(container1.getList(TYPE_1,EXCLUDE_DELETED,node1,SIDE_A)).thenReturn(toOrder);
  List<RelationNode> nodesToOrder=Arrays.asList(node3,node4,node5,node6);
  when(resolver.resolve(session,graph,toOrder,SIDE_B)).thenReturn(nodesToOrder);
  when(node1.getArtifactType()).thenReturn(artifactType1);
  when(node2.getArtifactType()).thenReturn(artifactType2);
  when(validity.getMaximumRelationsAllowed(TYPE_1,artifactType1,SIDE_A)).thenReturn(10);
  when(validity.getMaximumRelationsAllowed(TYPE_1,artifactType2,SIDE_B)).thenReturn(10);
  manager.relate(session,node1,TYPE_1,node2,USER_DEFINED);
  verify(container1).getRelation(node1,TYPE_1,node2,INCLUDE_DELETED);
  verify(container2).getRelation(node1,TYPE_1,node2,INCLUDE_DELETED);
  verify(container1).add(TYPE_1.getGuid(),relation1);
  verify(container2).add(TYPE_1.getGuid(),relation1);
  verify(resolver).resolve(session,graph,toOrder,SIDE_B);
  IRelationTypeSide typeSide=RelationUtil.asTypeSide(TYPE_1,SIDE_B);
  verify(orderManager1).sort(typeSide,nodesToOrder);
  verify(orderManager1).setOrder(eq(typeSide),eq(USER_DEFINED),sortedListCaptor.capture());
  Iterator<? extends Identifiable<String>> iterator=sortedListCaptor.getValue().iterator();
  assertEquals(node3,iterator.next());
  assertEquals(node4,iterator.next());
  assertEquals(node5,iterator.next());
  assertEquals(node6,iterator.next());
  assertEquals(node2,iterator.next());
}

Fixed version (ground truth):
@Test public void testRelateWithSortingUserDefined() throws OseeCoreException {
  when(container1.getRelation(node1,TYPE_1,node2,INCLUDE_DELETED)).thenReturn(null);
  when(container2.getRelation(node1,TYPE_1,node2,INCLUDE_DELETED)).thenReturn(null);
  when(relationFactory.createRelation(eq(node1),eq(TYPE_1),eq(node2),Matchers.anyString())).thenReturn(relation1);
  when(orderFactory.createOrderManager(node1)).thenReturn(orderManager1);
  List<Relation> toOrder=Arrays.asList(relation3,relation4);
  when(container1.getList(TYPE_1,EXCLUDE_DELETED,node1,SIDE_A)).thenReturn(toOrder);
  List<RelationNode> nodesToOrder=Arrays.asList(node3,node4,node5,node6);
  when(resolver.resolve(session,graph,toOrder,SIDE_B)).thenReturn(nodesToOrder);
  when(node1.getArtifactType()).thenReturn(artifactType1);
  when(node2.getArtifactType()).thenReturn(artifactType2);
  when(validity.getMaximumRelationsAllowed(TYPE_1,artifactType1,SIDE_A)).thenReturn(10);
  when(validity.getMaximumRelationsAllowed(TYPE_1,artifactType2,SIDE_B)).thenReturn(10);
  manager.relate(session,node1,TYPE_1,node2,USER_DEFINED);
  verify(container1).getRelation(node1,TYPE_1,node2,INCLUDE_DELETED);
  verify(container2).getRelation(node1,TYPE_1,node2,INCLUDE_DELETED);
  verify(container1).add(TYPE_1.getGuid(),relation1);
  verify(container2).add(TYPE_1.getGuid(),relation1);
  verify(resolver).resolve(session,graph,toOrder,SIDE_B);
  IRelationTypeSide typeSide=RelationUtil.asTypeSide(TYPE_1,SIDE_B);
  verify(orderManager1).sort(typeSide,nodesToOrder);
  verify(orderManager1).setOrder(eq(typeSide),eq(USER_DEFINED),sortedListCaptor.capture());
  Iterator<? extends Identifiable<String>> iterator=sortedListCaptor.getValue().iterator();
  assertEquals(node3,iterator.next());
  assertEquals(node4,iterator.next());
  assertEquals(node5,iterator.next());
  assertEquals(node6,iterator.next());
  assertEquals(node2,iterator.next());
}