Skip to content

Commit 6a1d4ad

Browse files
NIAD-1136: Removed lenient from tests
1 parent 1d7300a commit 6a1d4ad

16 files changed

+779
-307
lines changed

service/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ dependencies {
8585
testImplementation 'com.squareup.okhttp3:okhttp:5.1.0'
8686
testImplementation 'com.squareup.okhttp3:mockwebserver3:5.1.0'
8787
testImplementation 'com.adobe.testing:s3mock-testcontainers:4.7.0'
88+
testImplementation 'org.mockito:mockito-inline:4.8.0'
8889

8990
spotbugs 'com.github.spotbugs:spotbugs:4.9.8'
9091
spotbugs 'com.github.spotbugs:spotbugs-annotations:4.9.8'

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentDirectoryMapperTest.java

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatThrownBy;
55
import static org.mockito.ArgumentMatchers.any;
6-
import static org.mockito.Mockito.lenient;
76
import static org.mockito.Mockito.when;
8-
97
import static uk.nhs.adaptors.gp2gp.utils.IdUtil.buildReference;
108

119
import org.hl7.fhir.dstu3.model.Bundle;
@@ -31,12 +29,12 @@ class AgentDirectoryMapperTest {
3129
private static final String AGENT_DIRECTORY_FOLDER = "/ehr/mapper/agent-directory/";
3230
private static final String INPUT_AGENT_DIRECTORY = AGENT_DIRECTORY_FOLDER + "input-agent-directory-bundle.json";
3331
private static final String INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_REFERENCE =
34-
AGENT_DIRECTORY_FOLDER + "without-patient-managing-organization-reference.json";
32+
AGENT_DIRECTORY_FOLDER + "without-patient-managing-organization-reference.json";
3533
private static final String INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_RESOURCE =
36-
AGENT_DIRECTORY_FOLDER + "without-patient-managing-organization-resource.json";
34+
AGENT_DIRECTORY_FOLDER + "without-patient-managing-organization-resource.json";
3735
private static final String EXPECTED_AGENT_DIRECTORY = AGENT_DIRECTORY_FOLDER + "expected-agent-directory.xml";
3836
private static final String EXPECTED_AGENT_DIRECTORY_AGENT_PERSON_AS_ORGANIZATION =
39-
AGENT_DIRECTORY_FOLDER + "expected-with-agent-person-as-organization.xml";
37+
AGENT_DIRECTORY_FOLDER + "expected-with-agent-person-as-organization.xml";
4038

4139
@Mock
4240
private RandomIdGeneratorService randomIdGeneratorService;
@@ -48,99 +46,112 @@ class AgentDirectoryMapperTest {
4846
private MessageContext messageContext;
4947

5048
@BeforeEach
51-
public void setUp() {
52-
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
49+
void setUp() {
5350
messageContext = new MessageContext(randomIdGeneratorService);
54-
lenient().when(agentPersonMapper.mapAgentPerson(any(), any())).thenAnswer(answerWithObjectId());
55-
5651
agentDirectoryMapper = new AgentDirectoryMapper(messageContext, agentPersonMapper);
5752
fhirParseService = new FhirParseService();
5853
}
5954

55+
@AfterEach
56+
void tearDown() {
57+
messageContext.resetMessageContext();
58+
}
59+
6060
private Answer<String> answerWithObjectId() {
6161
return invocation -> {
62-
AgentDirectory.AgentKey agentKey = invocation.getArgument(0);
62+
var agentKey = invocation.getArgument(0, AgentDirectory.AgentKey.class);
6363
return String.format("<!--Mocked agentPerson for: %s %s -->",
64-
agentKey.getPractitionerReference(),
65-
agentKey.getOrganizationReference());
64+
agentKey.getPractitionerReference(),
65+
agentKey.getOrganizationReference());
6666
};
6767
}
6868

69+
private Bundle parseBundle(String path) {
70+
var jsonInput = ResourceTestFileUtils.getFileContent(path);
71+
return fhirParseService.parseResource(jsonInput, Bundle.class);
72+
}
73+
74+
private String readExpectedOutput(String path) {
75+
return ResourceTestFileUtils.getFileContent(path);
76+
}
77+
78+
private void initializeMessageContextWithAgentKeys(Bundle bundle) {
79+
messageContext.initialize(bundle);
80+
messageContext.getAgentDirectory().getAgentRef(
81+
buildReference(ResourceType.Practitioner, "11112222"),
82+
buildReference(ResourceType.Organization, "33334444")
83+
);
84+
messageContext.getAgentDirectory().getAgentRef(
85+
buildReference(ResourceType.Practitioner, "55556666"),
86+
buildReference(ResourceType.Organization, "77778888")
87+
);
88+
}
89+
6990
@Test
7091
void When_MappingAgentDirectory_Expect_CorrectOutputFromMapper() {
71-
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY);
72-
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
92+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
93+
when(agentPersonMapper.mapAgentPerson(any(), any())).thenAnswer(answerWithObjectId());
94+
95+
var bundle = parseBundle(INPUT_AGENT_DIRECTORY);
7396
initializeMessageContextWithAgentKeys(bundle);
74-
var expectedOutput = ResourceTestFileUtils.getFileContent(EXPECTED_AGENT_DIRECTORY);
7597

98+
var expectedOutput = readExpectedOutput(EXPECTED_AGENT_DIRECTORY);
7699
var mapperOutput = agentDirectoryMapper.mapEHRFolderToAgentDirectory(bundle, NHS_NUMBER);
77100

78101
assertThat(mapperOutput).isEqualTo(expectedOutput);
79102
}
80103

81104
@Test
82105
void When_MappingAgentDirectoryWithoutPatientManagingOrganizationReference_Expect_Exception() {
83-
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_REFERENCE);
84-
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
106+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
107+
108+
var bundle = parseBundle(INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_REFERENCE);
85109
initializeMessageContextWithAgentKeys(bundle);
86110

87111
assertThatThrownBy(() -> agentDirectoryMapper.mapEHRFolderToAgentDirectory(bundle, NHS_NUMBER))
88-
.isExactlyInstanceOf(EhrMapperException.class)
89-
.hasMessage("The ASR bundle does not contain a Patient resource with the correct identifier and managingOrganization");
112+
.isInstanceOf(EhrMapperException.class)
113+
.hasMessage("The ASR bundle does not contain a Patient resource with the correct identifier and managingOrganization");
90114
}
91115

92116
@Test
93117
void When_MappingAgentDirectoryWithoutPatientManagingOrganizationResource_Expect_Exception() {
94-
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_RESOURCE);
95-
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
118+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
119+
120+
var bundle = parseBundle(INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_RESOURCE);
96121
initializeMessageContextWithAgentKeys(bundle);
97122

98123
assertThatThrownBy(() -> agentDirectoryMapper.mapEHRFolderToAgentDirectory(bundle, NHS_NUMBER))
99-
.isExactlyInstanceOf(EhrMapperException.class)
100-
.hasMessage("The ASR bundle does not contain a Patient resource with the correct identifier and managingOrganization");
124+
.isInstanceOf(EhrMapperException.class)
125+
.hasMessage("The ASR bundle does not contain a Patient resource with the correct identifier and managingOrganization");
101126
}
102127

103128
@Test
104129
void When_MappingAgentDirectoryWithPatientManagingOrganizationInAgentKeys_Expect_AgentPersonNotDuplicated() {
105-
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY);
106-
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
107-
initializeMessageContextWithAgentKeys(bundle);
108-
messageContext.getAgentDirectory().getAgentId(buildReference(ResourceType.Organization, "5E496953-065B-41F2-9577-BE8F2FBD0757"));
130+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
131+
when(agentPersonMapper.mapAgentPerson(any(), any())).thenAnswer(answerWithObjectId());
109132

110-
var expectedOutput = ResourceTestFileUtils.getFileContent(EXPECTED_AGENT_DIRECTORY);
133+
var bundle = parseBundle(INPUT_AGENT_DIRECTORY);
134+
initializeMessageContextWithAgentKeys(bundle);
135+
messageContext.getAgentDirectory().getAgentId(
136+
buildReference(ResourceType.Organization, TEST_ID)
137+
);
111138

139+
var expectedOutput = readExpectedOutput(EXPECTED_AGENT_DIRECTORY);
112140
var mapperOutput = agentDirectoryMapper.mapEHRFolderToAgentDirectory(bundle, NHS_NUMBER);
113141

114142
assertThat(mapperOutput).isEqualTo(expectedOutput);
115143
}
116144

117145
@Test
118146
void When_MappingAgentKeysWithoutAgentKeys_Expect_CorrectOutputFromMapper() {
119-
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY);
120-
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
121-
messageContext.initialize(bundle);
147+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
122148

123-
var expectedOutput = ResourceTestFileUtils.getFileContent(EXPECTED_AGENT_DIRECTORY_AGENT_PERSON_AS_ORGANIZATION);
149+
var bundle = parseBundle(INPUT_AGENT_DIRECTORY);
150+
messageContext.initialize(bundle);
124151

152+
var expectedOutput = readExpectedOutput(EXPECTED_AGENT_DIRECTORY_AGENT_PERSON_AS_ORGANIZATION);
125153
var mapperOutput = agentDirectoryMapper.mapEHRFolderToAgentDirectory(bundle, NHS_NUMBER);
126154

127155
assertThat(mapperOutput).isEqualTo(expectedOutput);
128156
}
129-
130-
private void initializeMessageContextWithAgentKeys(Bundle bundle) {
131-
messageContext.initialize(bundle);
132-
messageContext.getAgentDirectory().getAgentRef(
133-
buildReference(ResourceType.Practitioner, "11112222"),
134-
buildReference(ResourceType.Organization, "33334444")
135-
);
136-
messageContext.getAgentDirectory().getAgentRef(
137-
buildReference(ResourceType.Practitioner, "55556666"),
138-
buildReference(ResourceType.Organization, "77778888")
139-
);
140-
}
141-
142-
@AfterEach
143-
public void tearDown() {
144-
messageContext.resetMessageContext();
145-
}
146157
}

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/AgentPersonMapperTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package uk.nhs.adaptors.gp2gp.ehr.mapper;
22

3-
import static org.mockito.Mockito.when;
43
import static org.assertj.core.api.Assertions.assertThat;
54
import java.util.stream.Stream;
65

@@ -18,16 +17,14 @@
1817
import org.junit.jupiter.params.provider.MethodSource;
1918
import org.mockito.Mock;
2019
import org.mockito.junit.jupiter.MockitoExtension;
21-
import org.mockito.junit.jupiter.MockitoSettings;
22-
import org.mockito.quality.Strictness;
20+
2321

2422
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
2523
import uk.nhs.adaptors.gp2gp.common.service.RandomIdGeneratorService;
2624
import uk.nhs.adaptors.gp2gp.utils.ResourceTestFileUtils;
2725
import uk.nhs.adaptors.gp2gp.utils.TestArgumentsLoaderUtil;
2826

2927
@ExtendWith(MockitoExtension.class)
30-
@MockitoSettings(strictness = Strictness.LENIENT)
3128
class AgentPersonMapperTest {
3229

3330
private static final String TEST_ID = "6D340A1B-BC15-4D4E-93CF-BBCB5B74DF73";
@@ -47,7 +44,6 @@ class AgentPersonMapperTest {
4744

4845
@BeforeEach
4946
public void setUp() {
50-
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
5147
messageContext = new MessageContext(randomIdGeneratorService);
5248
agentPersonMapper = new AgentPersonMapper(messageContext);
5349
fhirParseService = new FhirParseService();

0 commit comments

Comments
 (0)