From 0d686a0db87f9a297b45298e3f27e646ddcf69e8 Mon Sep 17 00:00:00 2001 From: ruhanga Date: Fri, 13 Nov 2020 09:54:36 +0300 Subject: [PATCH] FM2-312: Minor refactoring on tests --- .../MedicationRequestTranslatorImplTest.java | 12 ----- .../ServiceRequestTranslatorImplTest.java | 48 +++++++++---------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java index b4e1d85ad..2fe3c9d86 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/MedicationRequestTranslatorImplTest.java @@ -139,18 +139,6 @@ public void setup() { medicationRequest = new MedicationRequest(); medicationRequest.setId(DRUG_ORDER_UUID); - try { - Class clazz = drugOrder.getClass(); - Field orderNumberField = clazz.getSuperclass().getDeclaredField("orderNumber"); - Boolean isAccessible = orderNumberField.isAccessible(); - if (!isAccessible) { - orderNumberField.setAccessible(true); - } - orderNumberField.set(((Order) drugOrder), "ORD-1"); - } - catch (Exception e) { - e.printStackTrace(); - } } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImplTest.java index fdcfde0be..42813b0d4 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ServiceRequestTranslatorImplTest.java @@ -30,9 +30,9 @@ import org.exparity.hamcrest.date.DateMatchers; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; +import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Period; import org.hl7.fhir.r4.model.Reference; -import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.ServiceRequest; import org.hl7.fhir.r4.model.Task; import org.junit.Before; @@ -493,29 +493,29 @@ public void toFhirResource_shouldTranslateRequester() { assertThat(result.getReference(), containsString(PRACTITIONER_UUID)); } - @Test - public void toFhirResource_shouldTranslateOrderNumber() { - - TestOrder order = new TestOrder(); - Provider requester = new Provider(); - Reference requesterReference = new Reference(); - - requester.setUuid(PRACTITIONER_UUID); - order.setUuid(SERVICE_REQUEST_UUID); - order.setOrderer(requester); - setOrderNumberByReflection(order, TEST_ORDER_NUMBER); - requesterReference.setType(FhirConstants.PRACTITIONER) - .setReference(FhirConstants.PRACTITIONER + "/" + PRACTITIONER_UUID); - - when(taskService.searchForTasks(any(), any(), any(), any(), any(), any())) - .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); - when(practitionerReferenceTranslator.toFhirResource(requester)).thenReturn(requesterReference); - - Identifier result = translator.toFhirResource(order).getIdentifier().get(0); - - assertThat(result, notNullValue()); - assertThat(result.getValue(), containsString(TEST_ORDER_NUMBER)); - } + @Test + public void toFhirResource_shouldTranslateOrderNumber() { + + TestOrder order = new TestOrder(); + Provider requester = new Provider(); + Reference requesterReference = new Reference(); + + requester.setUuid(PRACTITIONER_UUID); + order.setUuid(SERVICE_REQUEST_UUID); + order.setOrderer(requester); + setOrderNumberByReflection(order, TEST_ORDER_NUMBER); + requesterReference.setType(FhirConstants.PRACTITIONER) + .setReference(FhirConstants.PRACTITIONER + "/" + PRACTITIONER_UUID); + + when(taskService.searchForTasks(any(), any(), any(), any(), any(), any())) + .thenReturn(new MockIBundleProvider<>(Collections.emptyList(), PREFERRED_PAGE_SIZE, COUNT)); + when(practitionerReferenceTranslator.toFhirResource(requester)).thenReturn(requesterReference); + + Identifier result = translator.toFhirResource(order).getIdentifier().get(0); + + assertThat(result, notNullValue()); + assertThat(result.getValue(), containsString(TEST_ORDER_NUMBER)); + } private List setUpBasedOnScenario(Task.TaskStatus status) { Reference basedOnRef = new Reference();