Skip to content

Commit abea362

Browse files
Fixed the import for MOCK
1 parent c3fca3b commit abea362

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

service/src/test/java/uk/nhs/adaptors/gp2gp/gpc/StructuredRecordMappingServiceTest.java

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import static org.mockito.ArgumentMatchers.any;
55
import static org.mockito.ArgumentMatchers.anyString;
66

7-
import static org.mockito.Mockito.*;
7+
import static org.mockito.Mockito.lenient;
8+
import static org.mockito.Mockito.when;
9+
import static org.mockito.Mockito.mock;
10+
import static org.mockito.Mockito.doThrow;
11+
import static org.mockito.Mockito.verify;
812
import static uk.nhs.adaptors.gp2gp.utils.IdUtil.buildIdType;
913

1014
import java.util.Arrays;
@@ -78,34 +82,34 @@ void setup() {
7882
@Test
7983
void When_GettingExternalAttachments_Expect_AllDocumentReferenceResourcesAreMapped() {
8084
when(randomIdGeneratorService.createNewId()).thenReturn(
81-
NEW_DOC_MANIFEST_ID_1,
82-
NEW_DOC_MANIFEST_ID_2
85+
NEW_DOC_MANIFEST_ID_1,
86+
NEW_DOC_MANIFEST_ID_2
8387
);
8488
when(randomIdGeneratorService.createNewOrUseExistingUUID(anyString())).thenReturn(
85-
NEW_DOC_MANIFEST_ID_1,
86-
NEW_DOC_MANIFEST_ID_2
89+
NEW_DOC_MANIFEST_ID_1,
90+
NEW_DOC_MANIFEST_ID_2
8791
);
8892
when(gp2gpConfiguration.getLargeAttachmentThreshold()).thenReturn(LARGE_MESSAGE_THRESHOLD);
8993
when(supportedContentTypes.isContentTypeSupported(any())).thenReturn(true);
9094

9195
var mappedExternalAttachments = getMappedExternalAttachments(
92-
buildDocumentReference(ID_1, "/" + NEW_DOC_REF_ID_1, null, ATTACHMENT_1_SIZE, "text/plain"),
93-
buildDocumentReference(ID_2, "/" + NEW_DOC_REF_ID_2, null, ATTACHMENT_2_SIZE, "text/html")
96+
buildDocumentReference(ID_1, "/" + NEW_DOC_REF_ID_1, null, ATTACHMENT_1_SIZE, "text/plain"),
97+
buildDocumentReference(ID_2, "/" + NEW_DOC_REF_ID_2, null, ATTACHMENT_2_SIZE, "text/html")
9498
);
9599

96100
assertThat(mappedExternalAttachments).usingRecursiveComparison().isEqualTo(
97-
List.of(
98-
buildExternalAttachment(
99-
NEW_DOC_MANIFEST_ID_1, NEW_DOC_MANIFEST_ID_1, "/" + NEW_DOC_REF_ID_1, null,
100-
"111_new_doc_manifest_id.txt", "text/plain",
101-
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_1)
102-
),
103-
buildExternalAttachment(
104-
NEW_DOC_MANIFEST_ID_2, NEW_DOC_MANIFEST_ID_2, "/" + NEW_DOC_REF_ID_2, null,
105-
"222_new_doc_manifest_id.html", "text/html",
106-
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_2)
101+
List.of(
102+
buildExternalAttachment(
103+
NEW_DOC_MANIFEST_ID_1, NEW_DOC_MANIFEST_ID_1, "/" + NEW_DOC_REF_ID_1, null,
104+
"111_new_doc_manifest_id.txt", "text/plain",
105+
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_1)
106+
),
107+
buildExternalAttachment(
108+
NEW_DOC_MANIFEST_ID_2, NEW_DOC_MANIFEST_ID_2, "/" + NEW_DOC_REF_ID_2, null,
109+
"222_new_doc_manifest_id.html", "text/html",
110+
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_2)
111+
)
107112
)
108-
)
109113
);
110114
}
111115

@@ -116,13 +120,13 @@ void When_GettingExternalAttachment_WithWrongContentType_Expect_AbsentAttachment
116120
when(gp2gpConfiguration.getLargeAttachmentThreshold()).thenReturn(LARGE_MESSAGE_THRESHOLD);
117121

118122
var mappedExternalAttachments = getMappedAbsentAttachments(
119-
buildDocumentReference(ID_1, "/" + NEW_DOC_REF_ID_1, null, ATTACHMENT_1_SIZE, UNSUPPORTED_CONTENT_TYPE)
123+
buildDocumentReference(ID_1, "/" + NEW_DOC_REF_ID_1, null, ATTACHMENT_1_SIZE, UNSUPPORTED_CONTENT_TYPE)
120124
);
121125

122126
assertThat(mappedExternalAttachments).usingRecursiveComparison().isEqualTo(List.of(buildExternalAttachment(
123-
NEW_DOC_MANIFEST_ID_1, NEW_DOC_MANIFEST_ID_1, "/" + NEW_DOC_REF_ID_1, null,
124-
"AbsentAttachment111_new_doc_manifest_id.txt", "text/plain",
125-
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_1)
127+
NEW_DOC_MANIFEST_ID_1, NEW_DOC_MANIFEST_ID_1, "/" + NEW_DOC_REF_ID_1, null,
128+
"AbsentAttachment111_new_doc_manifest_id.txt", "text/plain",
129+
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_1)
126130
)));
127131
}
128132

@@ -133,13 +137,13 @@ void When_GettingExternalAttachment_WithTitleAndNoUrl_Expect_AbsentAttachmentMap
133137
when(gp2gpConfiguration.getLargeAttachmentThreshold()).thenReturn(LARGE_MESSAGE_THRESHOLD);
134138

135139
var mappedExternalAttachments = getMappedAbsentAttachments(
136-
buildDocumentReference(ID_1, null, "some title", ATTACHMENT_1_SIZE, "text/plain")
140+
buildDocumentReference(ID_1, null, "some title", ATTACHMENT_1_SIZE, "text/plain")
137141
);
138142

139143
assertThat(mappedExternalAttachments).usingRecursiveComparison().isEqualTo(List.of(buildExternalAttachment(
140-
NEW_DOC_MANIFEST_ID_1, NEW_DOC_MANIFEST_ID_1, null, "some title",
141-
"AbsentAttachment111_new_doc_manifest_id.txt", "text/plain",
142-
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_1)
144+
NEW_DOC_MANIFEST_ID_1, NEW_DOC_MANIFEST_ID_1, null, "some title",
145+
"AbsentAttachment111_new_doc_manifest_id.txt", "text/plain",
146+
buildAttachmentDescription(NEW_DOC_MANIFEST_ID_1)
143147
)));
144148
}
145149

@@ -152,15 +156,16 @@ void When_GettingHL7_Expect_BundleAndStructuredRecordAreMapped() {
152156
var ehrExtractTemplateParameters = mock(EhrExtractTemplateParameters.class);
153157

154158
when(ehrExtractMapper.mapBundleToEhrFhirExtractParams(structuredTaskDefinition, bundle))
155-
.thenReturn(ehrExtractTemplateParameters);
159+
.thenReturn(ehrExtractTemplateParameters);
156160
when(ehrExtractMapper.mapEhrExtractToXml(ehrExtractTemplateParameters)).thenReturn(ehrExtractContent);
157161
when(outputMessageWrapperMapper.map(structuredTaskDefinition, ehrExtractContent))
158-
.thenReturn(expectedHL7);
162+
.thenReturn(expectedHL7);
159163

160164
var actualHL7 = structuredRecordMappingService.mapStructuredRecordToEhrExtractXml(structuredTaskDefinition, bundle);
161165

162166
verify(ehrExtractMapper).mapBundleToEhrFhirExtractParams(structuredTaskDefinition, bundle);
163167
verify(ehrExtractMapper).mapEhrExtractToXml(ehrExtractTemplateParameters);
168+
verify(ehrExtractMapper).mapEhrExtractToXml(ehrExtractTemplateParameters);
164169
verify(outputMessageWrapperMapper).map(structuredTaskDefinition, ehrExtractContent);
165170

166171
assertThat(actualHL7).isEqualTo(expectedHL7);
@@ -194,7 +199,7 @@ private Bundle getBundleWith(DocumentReference... documentReferences) {
194199
var bundle = new Bundle().addEntry(new Bundle.BundleEntryComponent().setResource(new Patient()));
195200

196201
Arrays.stream(documentReferences).forEach(
197-
documentReference -> bundle.addEntry(new Bundle.BundleEntryComponent().setResource(documentReference))
202+
documentReference -> bundle.addEntry(new Bundle.BundleEntryComponent().setResource(documentReference))
198203
);
199204
return bundle;
200205
}
@@ -325,37 +330,37 @@ private static OutboundMessage.ExternalAttachment buildExternalAttachment(String
325330
String filename, String contentType,
326331
OutboundMessage.AttachmentDescription description) {
327332
return OutboundMessage.ExternalAttachment.builder()
328-
.title(title)
329-
.documentId(documentID)
330-
.messageId(messageID)
331-
.description(description.toString())
332-
.url(url)
333-
.filename(filename)
334-
.identifier(List.of())
335-
.contentType(contentType)
336-
.build();
333+
.title(title)
334+
.documentId(documentID)
335+
.messageId(messageID)
336+
.description(description.toString())
337+
.url(url)
338+
.filename(filename)
339+
.identifier(List.of())
340+
.contentType(contentType)
341+
.build();
337342
}
338343

339344
private static OutboundMessage.AttachmentDescription buildAttachmentDescription(String documentId) {
340345
return OutboundMessage.AttachmentDescription.builder()
341-
.fileName(null)
342-
.contentType(null)
343-
.compressed(false)
344-
.largeAttachment(false)
345-
.originalBase64(false)
346-
.documentId(documentId)
347-
.build();
346+
.fileName(null)
347+
.contentType(null)
348+
.compressed(false)
349+
.largeAttachment(false)
350+
.originalBase64(false)
351+
.documentId(documentId)
352+
.build();
348353
}
349354

350355
private static DocumentReference buildDocumentReference(String id, String attachmentURL, String attachmentTitle,
351-
int size, String contentType) {
356+
int size, String contentType) {
352357
var documentReference = new DocumentReference();
353358
documentReference.setId(buildIdType(ResourceType.DocumentReference, id));
354359
documentReference.getContentFirstRep().setAttachment(new Attachment()
355-
.setUrl(attachmentURL)
356-
.setTitle(attachmentTitle)
357-
.setSize(size)
358-
.setContentType(contentType));
360+
.setUrl(attachmentURL)
361+
.setTitle(attachmentTitle)
362+
.setSize(size)
363+
.setContentType(contentType));
359364
return documentReference;
360365
}
361366
}

0 commit comments

Comments
 (0)