Program: 395
Project: 395
Buggy source:
/** 
 * This test verifies that: <ul> <li>No visual character gets created (via event) for the own character (as it is first person)</li> <li>That the system can deal with LocalPlayer and characters not being properly linked when the character entities get loaded/created</li> <li>A visual character gets created (via event) for charcters that were already present when the player joined</li> <li>A visual character gets created (via event) for characters that joins afterwards </li> </ul>
 */
@Test public void testSendingOfCreateVisualCharacterEvent(){
  EntityRef clientEntity=mockEntityWithUniqueId();
  EntityRef otherClientEntity=mockEntityWithUniqueId();
  EntityRef ownCharacterEntity=mockEntityWithUniqueId();
  List<Event> ownCharacterEntityEvents=new ArrayList<>();
  recordEntityEventsToList(ownCharacterEntity,ownCharacterEntityEvents);
  EntityRef otherCharacterEntity=mockEntityWithUniqueId();
  List<Event> otherCharacterEntityEvents=new ArrayList<>();
  recordEntityEventsToList(otherCharacterEntity,otherCharacterEntityEvents);
  clientEntityReturnedByLocalPlayer=EntityRef.NULL;
  system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(),otherCharacterEntity);
  system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(),ownCharacterEntity);
  simulateProperLinkingOfLocalPlayerAndCharacterEntities(clientEntity,otherClientEntity,ownCharacterEntity,otherCharacterEntity);
  system.onAwaitedLocalCharacterSpawnEvent(new AwaitedLocalCharacterSpawnEvent(),ownCharacterEntity);
  assertTypesInListEqual(ownCharacterEntityEvents,Collections.emptyList());
  assertTypesInListEqual(otherCharacterEntityEvents,Arrays.asList(CreateVisualCharacterEvent.class));
  EntityRef laterJoiningCharacterEntity=mockEntityWithUniqueId();
  List<Event> laterJoiningCharacterEntityEvents=new ArrayList<>();
  recordEntityEventsToList(laterJoiningCharacterEntity,laterJoiningCharacterEntityEvents);
  Mockito.when(laterJoiningCharacterEntity.getOwner()).thenReturn(EntityRef.NULL);
  system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(),laterJoiningCharacterEntity);
  assertTypesInListEqual(laterJoiningCharacterEntityEvents,Arrays.asList(CreateVisualCharacterEvent.class));
}

Fixed version (ground truth):
/** 
 * This test verifies that: <ul> <li>No visual character gets created (via event) for the own character (as it is first person)</li> <li>That the system can deal with LocalPlayer and characters not being properly linked when the character entities get loaded/created</li> <li>A visual character gets created (via event) for charcters that were already present when the player joined</li> <li>A visual character gets created (via event) for characters that joins afterwards </li> </ul>
 */
@Test public void testSendingOfCreateVisualCharacterEvent(){
  EntityRef clientEntity=mockEntityWithUniqueId();
  EntityRef otherClientEntity=mockEntityWithUniqueId();
  EntityRef ownCharacterEntity=mockEntityWithUniqueId();
  List<Event> ownCharacterEntityEvents=new ArrayList<>();
  recordEntityEventsToList(ownCharacterEntity,ownCharacterEntityEvents);
  VisualCharacterComponent visualComponentOfOwnCharacter=new VisualCharacterComponent();
  Mockito.when(ownCharacterEntity.getComponent(VisualCharacterComponent.class)).thenReturn(visualComponentOfOwnCharacter);
  EntityRef otherCharacterEntity=mockEntityWithUniqueId();
  List<Event> otherCharacterEntityEvents=new ArrayList<>();
  recordEntityEventsToList(otherCharacterEntity,otherCharacterEntityEvents);
  clientEntityReturnedByLocalPlayer=EntityRef.NULL;
  system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(),otherCharacterEntity,new VisualCharacterComponent());
  system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(),ownCharacterEntity,visualComponentOfOwnCharacter);
  simulateProperLinkingOfLocalPlayerAndCharacterEntities(clientEntity,otherClientEntity,ownCharacterEntity,otherCharacterEntity);
  system.onAwaitedLocalCharacterSpawnEvent(new AwaitedLocalCharacterSpawnEvent(),ownCharacterEntity);
  assertTypesInListEqual(ownCharacterEntityEvents,Collections.emptyList());
  assertTypesInListEqual(otherCharacterEntityEvents,Arrays.asList(CreateVisualCharacterEvent.class));
  EntityRef laterJoiningCharacterEntity=mockEntityWithUniqueId();
  List<Event> laterJoiningCharacterEntityEvents=new ArrayList<>();
  recordEntityEventsToList(laterJoiningCharacterEntity,laterJoiningCharacterEntityEvents);
  Mockito.when(laterJoiningCharacterEntity.getOwner()).thenReturn(EntityRef.NULL);
  system.onActivatedVisualCharacter(OnActivatedComponent.newInstance(),laterJoiningCharacterEntity,new VisualCharacterComponent());
  assertTypesInListEqual(laterJoiningCharacterEntityEvents,Arrays.asList(CreateVisualCharacterEvent.class));
}