From 3569409d69b56f1c8e5083f10cafc04c3a931838 Mon Sep 17 00:00:00 2001 From: hospel <12736698+ole4ryb@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:53:09 +0000 Subject: [PATCH] test for FhirParseService --- .../common/service/FhirParseServiceTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java diff --git a/service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java b/service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java new file mode 100644 index 0000000000..84a4c900fc --- /dev/null +++ b/service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java @@ -0,0 +1,37 @@ +package uk.nhs.adaptors.gp2gp.common.service; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.parser.IParser; +import ca.uhn.fhir.parser.StrictErrorHandler; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class FhirParseServiceTest { + + private ArgumentCaptor captor = ArgumentCaptor.forClass(StrictErrorHandler.class); + + @Test + void fhirParseServiceInitializedWithStrictErrorHandlerAndNewJsonParserTest() { + + FhirContext fhirContext = mock(FhirContext.class); + IParser parser = mock(IParser.class); + when(fhirContext.newJsonParser()).thenReturn(parser); + + FhirParseService service = new FhirParseService(fhirContext); + + verify(fhirContext).setParserErrorHandler(captor.capture()); + StrictErrorHandler strictErrorHandler = captor.getValue(); + assertNotNull(strictErrorHandler, "StrictErrorHandler should not be null"); + verify(fhirContext, times(2)).newJsonParser(); + } +} \ No newline at end of file