Source:
<code>public void validDataGroupsCanBeAdded() throws Exception { BridgeUtils.setRequestContext(new RequestContext.Builder().withCallerSubstudies( ImmutableSet.of("substudyA")).build()); StudyParticipant existing = new StudyParticipant.Builder() .withHealthCode(HEALTH_CODE) .withId(ID) .withSubstudyIds(TestConstants.USER_SUBSTUDY_IDS) .withFirstName("First").build(); doReturn(existing).when(participantService).getParticipant(study, ID, false); session.setParticipant(existing); Set<String> dataGroupSet = Sets.newHashSet("group1"); TestUtils.mockPlay().withMockResponse() .withJsonBody("{\"dataGroups\":[\"group1\"]}").mock(); Result result = controller.updateDataGroups(); TestUtils.assertResult(result, 200); JsonNode node = TestUtils.getJson(result); assertEquals("First", node.get("firstName").asText()); assertEquals("group1", node.get("dataGroups").get(0).asText()); verify(participantService).updateParticipant(eq(study), participantCaptor.capture()); verify(consentService).getConsentStatuses(contextCaptor.capture()); StudyParticipant participant = participantCaptor.getValue(); assertEquals(ID, participant.getId()); assertEquals(dataGroupSet, participant.getDataGroups()); assertEquals("First", participant.getFirstName()); assertEquals(TestConstants.USER_SUBSTUDY_IDS, participant.getSubstudyIds()); <START> assertEquals(dataGroupSet, contextCaptor.getValue().getUserDataGroups()); <END> assertEquals(dataGroupSet, session.getParticipant().getDataGroups()); assertEquals(TestConstants.USER_SUBSTUDY_IDS, session.getParticipant().getSubstudyIds()); assertEquals("healthCode", session.getParticipant().getHealthCode()); assertEquals("First", session.getParticipant().getFirstName()); }</code><technical_language>test captured context contains substudies</technical_language>

Target:
public void validDataGroupsCanBeAdded() throws Exception { BridgeUtils.setRequestContext(new RequestContext.Builder().withCallerSubstudies( ImmutableSet.of("substudyA")).build()); StudyParticipant existing = new StudyParticipant.Builder() .withHealthCode(HEALTH_CODE) .withId(ID) .withSubstudyIds(TestConstants.USER_SUBSTUDY_IDS) .withFirstName("First").build(); doReturn(existing).when(participantService).getParticipant(study, ID, false); session.setParticipant(existing); Set<String> dataGroupSet = Sets.newHashSet("group1"); TestUtils.mockPlay().withMockResponse() .withJsonBody("{\"dataGroups\":[\"group1\"]}").mock(); Result result = controller.updateDataGroups(); TestUtils.assertResult(result, 200); JsonNode node = TestUtils.getJson(result); assertEquals("First", node.get("firstName").asText()); assertEquals("group1", node.get("dataGroups").get(0).asText()); verify(participantService).updateParticipant(eq(study), participantCaptor.capture()); verify(consentService).getConsentStatuses(contextCaptor.capture()); StudyParticipant participant = participantCaptor.getValue(); assertEquals(ID, participant.getId()); assertEquals(dataGroupSet, participant.getDataGroups()); assertEquals("First", participant.getFirstName()); assertEquals(TestConstants.USER_SUBSTUDY_IDS, participant.getSubstudyIds()); assertEquals(dataGroupSet, contextCaptor.getValue().getUserDataGroups()); assertEquals(TestConstants.USER_SUBSTUDY_IDS, contextCaptor.getValue().getUserSubstudyIds()); assertEquals(dataGroupSet, session.getParticipant().getDataGroups()); assertEquals(TestConstants.USER_SUBSTUDY_IDS, session.getParticipant().getSubstudyIds()); assertEquals("healthCode", session.getParticipant().getHealthCode()); assertEquals("First", session.getParticipant().getFirstName()); }