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