Skip to content

Commit 478ec40

Browse files
authored
code cleanup (#1055)
1 parent 300135b commit 478ec40

File tree

9 files changed

+21
-71
lines changed

9 files changed

+21
-71
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import static uk.nhs.adaptors.gp2gp.utils.IdUtil.buildReference;
1010

11-
import java.io.IOException;
12-
1311
import org.hl7.fhir.dstu3.model.Bundle;
1412
import org.hl7.fhir.dstu3.model.ResourceType;
1513
import org.junit.jupiter.api.AfterEach;
@@ -69,7 +67,7 @@ private Answer<String> answerWithObjectId() {
6967
}
7068

7169
@Test
72-
public void When_MappingAgentDirectory_Expect_CorrectOutputFromMapper() throws IOException {
70+
public void When_MappingAgentDirectory_Expect_CorrectOutputFromMapper() {
7371
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY);
7472
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
7573
initializeMessageContextWithAgentKeys(bundle);
@@ -81,7 +79,7 @@ public void When_MappingAgentDirectory_Expect_CorrectOutputFromMapper() throws I
8179
}
8280

8381
@Test
84-
public void When_MappingAgentDirectoryWithoutPatientManagingOrganizationReference_Expect_Exception() throws IOException {
82+
public void When_MappingAgentDirectoryWithoutPatientManagingOrganizationReference_Expect_Exception() {
8583
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_REFERENCE);
8684
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
8785
initializeMessageContextWithAgentKeys(bundle);
@@ -92,7 +90,7 @@ public void When_MappingAgentDirectoryWithoutPatientManagingOrganizationReferenc
9290
}
9391

9492
@Test
95-
public void When_MappingAgentDirectoryWithoutPatientManagingOrganizationResource_Expect_Exception() throws IOException {
93+
public void When_MappingAgentDirectoryWithoutPatientManagingOrganizationResource_Expect_Exception() {
9694
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY_WITHOUT_MANAGING_ORGANIZATION_RESOURCE);
9795
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
9896
initializeMessageContextWithAgentKeys(bundle);
@@ -103,7 +101,7 @@ public void When_MappingAgentDirectoryWithoutPatientManagingOrganizationResource
103101
}
104102

105103
@Test
106-
public void When_MappingAgentDirectoryWithPatientManagingOrganizationInAgentKeys_Expect_AgentPersonNotDuplicated() throws IOException {
104+
public void When_MappingAgentDirectoryWithPatientManagingOrganizationInAgentKeys_Expect_AgentPersonNotDuplicated() {
107105
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY);
108106
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
109107
initializeMessageContextWithAgentKeys(bundle);
@@ -117,7 +115,7 @@ public void When_MappingAgentDirectoryWithPatientManagingOrganizationInAgentKeys
117115
}
118116

119117
@Test
120-
public void When_MappingAgentKeysWithoutAgentKeys_Expect_CorrectOutputFromMapper() throws IOException {
118+
public void When_MappingAgentKeysWithoutAgentKeys_Expect_CorrectOutputFromMapper() {
121119
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_AGENT_DIRECTORY);
122120
Bundle bundle = fhirParseService.parseResource(jsonInput, Bundle.class);
123121
messageContext.initialize(bundle);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import static uk.nhs.adaptors.gp2gp.utils.IdUtil.buildReference;
77

8-
import java.io.IOException;
98
import java.util.Map;
109
import java.util.Optional;
1110

@@ -40,7 +39,7 @@ public class AgentDirectoryTest {
4039
private Bundle inputBundle;
4140

4241
@BeforeEach
43-
public void setUp() throws IOException {
42+
public void setUp() {
4443
lenient().when(randomIdGeneratorService.createNewId()).thenReturn(GENERATED_ID_1, GENERATED_ID_2);
4544

4645
String jsonInput = ResourceTestFileUtils.getFileContent(INPUT_BUNDLE);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import static uk.nhs.adaptors.gp2gp.utils.IdUtil.buildIdType;
1111
import static uk.nhs.adaptors.gp2gp.utils.IdUtil.buildReference;
1212

13-
import java.io.IOException;
1413
import java.util.List;
1514
import java.util.Optional;
1615
import java.util.stream.Stream;
@@ -180,7 +179,7 @@ private static Stream<Arguments> resourceFileParams() {
180179
}
181180

182181
@BeforeEach
183-
public void setUp() throws IOException {
182+
public void setUp() {
184183
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
185184
when(randomIdGeneratorService.createNewOrUseExistingUUID(anyString())).thenReturn(TEST_ID);
186185

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import static org.mockito.Mockito.verify;
88
import static org.mockito.Mockito.when;
99

10-
import java.io.IOException;
1110
import java.time.Instant;
1211
import java.util.Date;
1312
import java.util.List;
@@ -125,8 +124,6 @@ public class EncounterMapperTest {
125124
+ "expected-output-encounter-13.xml";
126125
private static final String INPUT_JSON_ENCOUNTER_NO_ASSOCIATED_CONSULTATION = TEST_FILES_DIRECTORY
127126
+ "example-encounter-resource-18.json";
128-
private static final String OUTPUT_XML_WITH_NO_EHR_COMPOSITION_COMPONENTS = TEST_FILES_DIRECTORY
129-
+ "expected-output-encounter-14.xml";
130127
public static final String OUTPUT_XML_WITH_NUL_AUTHOR_PARTICIPANT2 = TEST_FILES_DIRECTORY + "expected-output-encounter-15.xml";
131128

132129
@Mock
@@ -159,7 +156,7 @@ public void tearDown() {
159156

160157
@ParameterizedTest
161158
@MethodSource("testFilePaths")
162-
public void When_MappingParsedEncounterJson_Expect_EhrCompositionXmlOutput(String input, String output) throws IOException {
159+
public void When_MappingParsedEncounterJson_Expect_EhrCompositionXmlOutput(String input, String output) {
163160
lenient().when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
164161
var sampleComponent = ResourceTestFileUtils.getFileContent(SAMPLE_EHR_COMPOSITION_COMPONENT);
165162

@@ -196,7 +193,7 @@ private static Stream<Arguments> testFilePaths() {
196193
}
197194

198195
@Test
199-
public void When_MappingEncounterWithNoType_Expect_Exception() throws IOException {
196+
public void When_MappingEncounterWithNoType_Expect_Exception() {
200197
var sampleComponent = ResourceTestFileUtils.getFileContent(SAMPLE_EHR_COMPOSITION_COMPONENT);
201198

202199
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_NO_TYPE);
@@ -211,7 +208,7 @@ public void When_MappingEncounterWithNoType_Expect_Exception() throws IOExceptio
211208
}
212209

213210
@Test
214-
public void When_MappingEncounterWithInvalidParticipantReferenceResourceType_Expect_Exception() throws IOException {
211+
public void When_MappingEncounterWithInvalidParticipantReferenceResourceType_Expect_Exception() {
215212
var sampleComponent = ResourceTestFileUtils.getFileContent(SAMPLE_EHR_COMPOSITION_COMPONENT);
216213

217214
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_PERFORMER_INVALID_REFERENCE_RESOURCE_TYPE);
@@ -226,7 +223,7 @@ public void When_MappingEncounterWithInvalidParticipantReferenceResourceType_Exp
226223
}
227224

228225
@Test
229-
public void When_MappingEmptyConsultation_Expect_NoEhrCompositionGenerated() throws IOException {
226+
public void When_MappingEmptyConsultation_Expect_NoEhrCompositionGenerated() {
230227
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_ENCOUNTER_NO_ASSOCIATED_CONSULTATION);
231228
Encounter parsedEncounter = new FhirParseService().parseResource(jsonInput, Encounter.class);
232229

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/scheduling/EhrExtractTimeoutSchedulerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void updateEhrExtractStatusListWithEhrReceivedAcknowledgementError() {
286286
doReturn(List.of(ehrExtractStatus)).when(ehrExtractTimeoutSchedulerSpy).findInProgressTransfers();
287287
when(ehrExtractTimeoutSchedulerSpy.logger()).thenReturn(logger);
288288

289-
var exception = assertThrows(EhrExtractException.class, () -> ehrExtractTimeoutSchedulerSpy.processEhrExtractAckTimeouts());
289+
var exception = assertThrows(EhrExtractException.class, ehrExtractTimeoutSchedulerSpy::processEhrExtractAckTimeouts);
290290

291291
assertAll(
292292
() -> verify(logger, times(1)).info("Scheduler has started processing EhrExtract list with Ack timeouts"),
@@ -318,7 +318,7 @@ void shouldCatchExceptionIfUnexpectedConditionAriseWhileUpdatingEhrExtractStatus
318318
doThrow(exception).when(logger).info("Scheduler has started processing EhrExtract list with Ack timeouts");
319319
when(ehrExtractTimeoutSchedulerSpy.logger()).thenReturn(logger);
320320

321-
assertThrows(Exception.class, () -> ehrExtractTimeoutSchedulerSpy.processEhrExtractAckTimeouts());
321+
assertThrows(Exception.class, ehrExtractTimeoutSchedulerSpy::processEhrExtractAckTimeouts);
322322

323323
verify(logger, times(1)).info("Scheduler has started processing EhrExtract list with Ack timeouts");
324324
verify(logger, times(1)).error("An unexpected error occurred for conversation_id: {}",
@@ -339,7 +339,7 @@ void whenEhrExtractStatusIsNullInterceptExceptionAndLogErrorMsg() {
339339
any(FindAndModifyOptions.class), any());
340340
when(ehrExtractTimeoutSchedulerSpy.logger()).thenReturn(logger);
341341

342-
var exception = assertThrows(EhrExtractException.class, () -> ehrExtractTimeoutSchedulerSpy.processEhrExtractAckTimeouts());
342+
var exception = assertThrows(EhrExtractException.class, ehrExtractTimeoutSchedulerSpy::processEhrExtractAckTimeouts);
343343

344344
assertEquals("Couldn't update EHR received acknowledgement with error information because EHR status doesn't exist, "
345345
+ "conversation_id: " + inProgressConversationId, exception.getMessage());

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/status/service/EhrStatusBaseServiceTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private String generateRandomUppercaseUUID() {
175175
}
176176

177177
private EhrExtractStatus inProgressTransfers(String conversationId) {
178-
EhrExtractStatus extractStatus = EhrExtractStatus.builder()
178+
return EhrExtractStatus.builder()
179179
.ackPending(buildPositiveAckPending())
180180
.ackToRequester(buildPositiveAckToRequester())
181181
.conversationId(conversationId)
@@ -207,12 +207,10 @@ private EhrExtractStatus inProgressTransfers(String conversationId) {
207207
.display(DISPLAY_ERROR_MESSAGE)
208208
.build())).build())
209209
.build();
210-
211-
return extractStatus;
212210
}
213211

214212
private EhrExtractStatus completeTransfers(String conversationId) {
215-
EhrExtractStatus extractStatus = EhrExtractStatus.builder()
213+
return EhrExtractStatus.builder()
216214
.ackPending(buildPositiveAckPending())
217215
.ackToRequester(buildPositiveAckToRequester())
218216
.conversationId(conversationId)
@@ -241,8 +239,6 @@ private EhrExtractStatus completeTransfers(String conversationId) {
241239
.conversationClosed(FIVE_DAYS_AGO)
242240
.build())
243241
.build();
244-
245-
return extractStatus;
246242
}
247243

248244
private EhrExtractStatus.AckPending buildPositiveAckPending() {

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/status/service/EhrStatusServiceTest.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,39 +72,6 @@ public class EhrStatusServiceTest {
7272
.ehrRequest(EhrExtractStatus.EhrRequest.builder().toAsid(TO_ASID_CODE).fromAsid(FROM_ASID_CODE).build())
7373
.build();
7474

75-
private static final EhrExtractStatus.GpcDocument SKELETON_DOCUMENT = EhrExtractStatus.GpcDocument.builder()
76-
.isSkeleton(true)
77-
.build();
78-
79-
private static final EhrExtractStatus.GpcDocument PLACEHOLDER_DOCUMENT_1 = EhrExtractStatus.GpcDocument.builder()
80-
.fileName("AbsentAttachmentTest.txt")
81-
.isSkeleton(false)
82-
.build();
83-
84-
private static final EhrExtractStatus.GpcDocument PLACEHOLDER_DOCUMENT_2 = EhrExtractStatus.GpcDocument.builder()
85-
.objectName("AbsentAttachmentTest.txt")
86-
.isSkeleton(false)
87-
.build();
88-
89-
private static final EhrExtractStatus.GpcDocument ORIGINAL_FILE_DOCUMENT = EhrExtractStatus.GpcDocument.builder()
90-
.fileName("test.txt")
91-
.objectName("test.txt")
92-
.isSkeleton(false)
93-
.sentToMhs(EhrExtractStatus.GpcAccessDocument.SentToMhs.builder()
94-
.messageId(List.of("123456"))
95-
.build())
96-
.build();
97-
98-
private static final List<EhrExtractStatus.EhrReceivedAcknowledgement> ONE_FAILED_ACK_LIST = List.of(
99-
EhrExtractStatus.EhrReceivedAcknowledgement.builder()
100-
.messageRef("123456")
101-
.errors(List.of(EhrExtractStatus.EhrReceivedAcknowledgement.ErrorDetails.builder()
102-
.code("99")
103-
.display("Test Error")
104-
.build()))
105-
.build()
106-
);
107-
10875
@Mock
10976
private EhrExtractStatusRepository extractStatusRepository;
11077
@InjectMocks

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/EncounterExtractorTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package uk.nhs.adaptors.gp2gp.ehr.utils;
22

3-
import com.google.common.collect.ImmutableList;
43
import org.hl7.fhir.dstu3.model.Bundle;
54
import org.hl7.fhir.dstu3.model.Encounter;
65
import org.junit.jupiter.api.BeforeAll;
76
import org.junit.jupiter.api.Test;
87
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
98
import uk.nhs.adaptors.gp2gp.utils.ResourceTestFileUtils;
10-
119
import java.io.IOException;
1210
import java.util.List;
13-
1411
import static org.assertj.core.api.Assertions.assertThat;
1512

1613
public class EncounterExtractorTest {
@@ -22,7 +19,7 @@ public class EncounterExtractorTest {
2219
private static final String INPUT_PATH = TEST_FILE_DIRECTORY + INPUT_DIRECTORY;
2320
private static final String ENCOUNTER_ID_PREFIX = "Encounter/";
2421
private static final int EXPECTED_ENCOUNTER_NUMBER = 6;
25-
private static final List<String> EXPECTED_ENCOUNTER_IDS = ImmutableList.of("DBF5776F-8A86-477C-AB98-57182A9B40FD",
22+
private static final List<String> EXPECTED_ENCOUNTER_IDS = List.of("DBF5776F-8A86-477C-AB98-57182A9B40FD",
2623
"F550CC56-EF65-4934-A7B1-3DC2E02243C3",
2724
"9B69F6AE-F991-49EE-9FFD-028E39B38BFE",
2825
"D81C5E8F-CB3A-4A78-92EA-51EC3665648E",

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/utils/ResourceExtractorTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
1515
import uk.nhs.adaptors.gp2gp.ehr.mapper.MessageContext;
1616
import uk.nhs.adaptors.gp2gp.utils.ResourceTestFileUtils;
17-
18-
import java.io.IOException;
1917
import java.util.Optional;
2018

2119
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -31,7 +29,7 @@ class ResourceExtractorTest {
3129
private MessageContext messageContext;
3230

3331
@Test
34-
void extractListWithContainedAllergiesResourceByReference() throws IOException {
32+
void extractListWithContainedAllergiesResourceByReference() {
3533

3634
String bundleJsonInput = ResourceTestFileUtils.getFileContent(LIST_RESOURCE_TEST_FILE_DIRECTORY + "fhir_bundle.json");
3735
Bundle allBundle = new FhirParseService().parseResource(bundleJsonInput, Bundle.class);
@@ -45,7 +43,7 @@ void extractListWithContainedAllergiesResourceByReference() throws IOException {
4543
}
4644

4745
@Test
48-
void extractEmptyResourceWithValidContainedIdButNotValidResourceTypeReference() throws IOException {
46+
void extractEmptyResourceWithValidContainedIdButNotValidResourceTypeReference() {
4947

5048
final String LIST_REFERENCE_ID_WITH_WRONG_RESOURCE_TYPE = "Organization/ended-allergies#eb306f14-31e9-11ee-b912-0a58a9feac02";
5149
String bundleJsonInput = ResourceTestFileUtils.getFileContent(LIST_RESOURCE_TEST_FILE_DIRECTORY + "fhir_bundle.json");
@@ -58,7 +56,7 @@ void extractEmptyResourceWithValidContainedIdButNotValidResourceTypeReference()
5856
}
5957

6058
@Test
61-
void extractEmptyResourceByNonExistedReference() throws IOException {
59+
void extractEmptyResourceByNonExistedReference() {
6260

6361
final String NON_EXISTED_LIST_REFERENCE_ID = "List/ended-allergies#eb306f14-31e9-11ee-b912-0a58a9feac04";
6462
String bundleJsonInput = ResourceTestFileUtils.getFileContent(LIST_RESOURCE_TEST_FILE_DIRECTORY + "fhir_bundle.json");
@@ -74,8 +72,7 @@ private IIdType createAllergyIntoleranceReference(String refId) {
7472
AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
7573
allergyIntolerance.getAsserter().setReference(refId);
7674

77-
IIdType reference = allergyIntolerance.getAsserter().getReferenceElement();
78-
return reference;
75+
return allergyIntolerance.getAsserter().getReferenceElement();
7976
}
8077

8178

0 commit comments

Comments
 (0)