From 8e64ae591a7bf4db8a784039ad3c825b1599deff Mon Sep 17 00:00:00 2001 From: MartinWheelerMT Date: Fri, 22 Nov 2024 10:59:44 +0000 Subject: [PATCH] Remove superfluous size assert of list. Refactor tests to use extracting() better and make it more readable. --- .../mapper/ReferralRequestMapperTest.java | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/ReferralRequestMapperTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/ReferralRequestMapperTest.java index edf43be69..262571eaa 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/ReferralRequestMapperTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/ReferralRequestMapperTest.java @@ -22,6 +22,7 @@ import java.util.function.Function; import java.util.stream.Stream; +import org.assertj.core.groups.Tuple; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.Encounter; @@ -568,46 +569,34 @@ void When_MappingReferralRequestReferencedByReferralRequestToExternalDocumentLin ); final var referralRequest = referralRequests.getFirst(); - assertAll( - () -> assertThat(referralRequest.getSupportingInfo()) - .hasSize(2), - () -> assertThat(referralRequest.getSupportingInfo().getFirst().getReferenceElement().getResourceType()) - .isEqualTo(ResourceType.DocumentReference.name()), - () -> assertThat(referralRequest.getSupportingInfo().getFirst().getReferenceElement().getIdPart()) - .isEqualTo("narrative-statement-1"), - () -> assertThat(referralRequest.getSupportingInfo().getLast().getReferenceElement().getResourceType()) - .isEqualTo(ResourceType.DocumentReference.name()), - () -> assertThat(referralRequest.getSupportingInfo().getLast().getReferenceElement().getIdPart()) - .isEqualTo("narrative-statement-2") - ); + assertThat(referralRequest.getSupportingInfo()) + .extracting("referenceElement.resourceType", "referenceElement.idPart") + .containsExactly( + Tuple.tuple(ResourceType.DocumentReference.name(), "narrative-statement-1"), + Tuple.tuple(ResourceType.DocumentReference.name(), "narrative-statement-2") + ); } @Test void When_ReferralRequestReferencedByMultipleLinkSets_Expect_AllRelatedDocumentReferencesAddedAsSupportingInfo() { - final var expectedSize = 3; final RCMRMT030101UKEhrExtract ehrExtract = unmarshallEhrExtractElement( "ehr_extract_with_multiple_request_statement_to_external_document_linksets.xml" ); - final var referralRequests = referralRequestMapper.mapResources( ehrExtract, (Patient) new Patient().setId(PATIENT_ID), List.of(), PRACTISE_CODE ); - final var referralRequest = referralRequests.getFirst(); - assertAll( - () -> assertThat(referralRequest.getSupportingInfo()).hasSize(expectedSize), - () -> assertThat(referralRequest.getSupportingInfo()) - .extracting(reference -> reference.getReferenceElement().getIdPart()) - .containsExactly( - "narrative-statement-1", - "narrative-statement-2", - "narrative-statement-3" - ) - ); + assertThat(referralRequests.getFirst().getSupportingInfo()) + .extracting("referenceElement.resourceType", "referenceElement.idPart") + .containsExactly( + Tuple.tuple(ResourceType.DocumentReference.name(), "narrative-statement-1"), + Tuple.tuple(ResourceType.DocumentReference.name(), "narrative-statement-2"), + Tuple.tuple(ResourceType.DocumentReference.name(), "narrative-statement-3") + ); } private RCMRMT030101UKRequestStatement getNestedRequestStatement(RCMRMT030101UKEhrComposition ehrComposition) {