Skip to content

Commit

Permalink
test for FhirParseService
Browse files Browse the repository at this point in the history
  • Loading branch information
ole4ryb committed Nov 22, 2024
1 parent bd65bd3 commit 3569409
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<StrictErrorHandler> 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();
}
}

0 comments on commit 3569409

Please sign in to comment.