Program: 25719
Project: 25719
Buggy source:
@Test public void createSynapseProjectTeam() throws SynapseException {
  Study study=getTestStudy();
  AccessControlList mockAcl=new AccessControlList();
  AccessControlList mockTeamAcl=new AccessControlList();
  mockAcl.setResourceAccess(new HashSet<ResourceAccess>());
  mockTeamAcl.setResourceAccess(new HashSet<ResourceAccess>());
  when(mockSynapseClient.createTeam(any())).thenReturn(mockTeam);
  when(mockSynapseClient.createEntity(any())).thenReturn(mockProject);
  when(mockSynapseClient.getACL(any())).thenReturn(mockAcl);
  when(mockSynapseClient.getTeamACL(any())).thenReturn(mockTeamAcl);
  Study retStudy=service.createSynapseProjectTeam(TEST_USER_ID,study);
  verify(mockSynapseClient).createTeam(any());
  verify(mockSynapseClient).createEntity(any());
  verify(mockSynapseClient).getACL(eq(TEST_PROJECT_ID));
  ArgumentCaptor<AccessControlList> argumentProjectAcl=ArgumentCaptor.forClass(AccessControlList.class);
  verify(mockSynapseClient).updateACL(argumentProjectAcl.capture());
  AccessControlList capturedProjectAcl=argumentProjectAcl.getValue();
  Set<ResourceAccess> capturedProjectAclSet=capturedProjectAcl.getResourceAccess();
  assertNotNull(capturedProjectAclSet);
  assertEquals(capturedProjectAclSet.size(),2);
  List<ResourceAccess> retListForExporter=capturedProjectAclSet.stream().filter(ra -> ra.getPrincipalId().equals(Long.parseLong(EXPORTER_SYNAPSE_USER_ID))).collect(Collectors.toList());
  assertNotNull(retListForExporter);
  assertEquals(retListForExporter.size(),1);
  ResourceAccess capturedExporterRa=retListForExporter.get(0);
  assertNotNull(capturedExporterRa);
  assertEquals(capturedExporterRa.getPrincipalId().toString(),EXPORTER_SYNAPSE_USER_ID);
  assertEquals(capturedExporterRa.getAccessType(),ModelConstants.ENITY_ADMIN_ACCESS_PERMISSIONS);
  List<ResourceAccess> retListForUser=capturedProjectAclSet.stream().filter(ra -> ra.getPrincipalId().equals(TEST_USER_ID)).collect(Collectors.toList());
  assertNotNull(retListForUser);
  assertEquals(retListForUser.size(),1);
  ResourceAccess capturedUserRa=retListForUser.get(0);
  assertNotNull(capturedUserRa);
  assertEquals(capturedUserRa.getPrincipalId(),TEST_USER_ID);
  assertEquals(capturedUserRa.getAccessType(),ModelConstants.ENITY_ADMIN_ACCESS_PERMISSIONS);
  verify(mockSynapseClient).createMembershipInvitation(eq(mockTeamMemberInvitation),any(),any());
  verify(mockSynapseClient).setTeamMemberPermissions(eq(TEST_TEAM_ID),eq(TEST_USER_ID.toString()),anyBoolean());
  assertNotNull(retStudy);
  assertEquals(retStudy.getIdentifier(),study.getIdentifier());
  assertEquals(retStudy.getName(),study.getName());
  assertEquals(retStudy.getSynapseProjectId(),TEST_PROJECT_ID);
  assertEquals(retStudy.getSynapseDataAccessTeamId().toString(),TEST_TEAM_ID);
}

Fixed version (ground truth):
@Test public void createSynapseProjectTeam() throws SynapseException {
  Study study=getTestStudy();
  study.setSynapseProjectId(null);
  study.setSynapseDataAccessTeamId(null);
  AccessControlList mockAcl=new AccessControlList();
  AccessControlList mockTeamAcl=new AccessControlList();
  mockAcl.setResourceAccess(new HashSet<ResourceAccess>());
  mockTeamAcl.setResourceAccess(new HashSet<ResourceAccess>());
  when(mockSynapseClient.createTeam(any())).thenReturn(mockTeam);
  when(mockSynapseClient.createEntity(any())).thenReturn(mockProject);
  when(mockSynapseClient.getACL(any())).thenReturn(mockAcl);
  when(mockSynapseClient.getTeamACL(any())).thenReturn(mockTeamAcl);
  Study retStudy=service.createSynapseProjectTeam(TEST_USER_ID,study);
  verify(mockSynapseClient).createTeam(any());
  verify(mockSynapseClient).createEntity(any());
  verify(mockSynapseClient).getACL(eq(TEST_PROJECT_ID));
  ArgumentCaptor<AccessControlList> argumentProjectAcl=ArgumentCaptor.forClass(AccessControlList.class);
  verify(mockSynapseClient).updateACL(argumentProjectAcl.capture());
  AccessControlList capturedProjectAcl=argumentProjectAcl.getValue();
  Set<ResourceAccess> capturedProjectAclSet=capturedProjectAcl.getResourceAccess();
  assertNotNull(capturedProjectAclSet);
  assertEquals(capturedProjectAclSet.size(),2);
  List<ResourceAccess> retListForExporter=capturedProjectAclSet.stream().filter(ra -> ra.getPrincipalId().equals(Long.parseLong(EXPORTER_SYNAPSE_USER_ID))).collect(Collectors.toList());
  assertNotNull(retListForExporter);
  assertEquals(retListForExporter.size(),1);
  ResourceAccess capturedExporterRa=retListForExporter.get(0);
  assertNotNull(capturedExporterRa);
  assertEquals(capturedExporterRa.getPrincipalId().toString(),EXPORTER_SYNAPSE_USER_ID);
  assertEquals(capturedExporterRa.getAccessType(),ModelConstants.ENITY_ADMIN_ACCESS_PERMISSIONS);
  List<ResourceAccess> retListForUser=capturedProjectAclSet.stream().filter(ra -> ra.getPrincipalId().equals(TEST_USER_ID)).collect(Collectors.toList());
  assertNotNull(retListForUser);
  assertEquals(retListForUser.size(),1);
  ResourceAccess capturedUserRa=retListForUser.get(0);
  assertNotNull(capturedUserRa);
  assertEquals(capturedUserRa.getPrincipalId(),TEST_USER_ID);
  assertEquals(capturedUserRa.getAccessType(),ModelConstants.ENITY_ADMIN_ACCESS_PERMISSIONS);
  verify(mockSynapseClient).createMembershipInvitation(eq(mockTeamMemberInvitation),any(),any());
  verify(mockSynapseClient).setTeamMemberPermissions(eq(TEST_TEAM_ID),eq(TEST_USER_ID.toString()),anyBoolean());
  assertNotNull(retStudy);
  assertEquals(retStudy.getIdentifier(),study.getIdentifier());
  assertEquals(retStudy.getName(),study.getName());
  assertEquals(retStudy.getSynapseProjectId(),TEST_PROJECT_ID);
  assertEquals(retStudy.getSynapseDataAccessTeamId().toString(),TEST_TEAM_ID);
}