From a7b063e60bd42d48277cd2bad6f801e4f6770e1e Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Tue, 18 Jun 2024 12:11:41 -0400 Subject: [PATCH] add new test for coverage --- .../gov/cms/ab2d/optout/OptOutHandlerTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java b/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java index fef0e1a..6faf0cb 100644 --- a/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java +++ b/optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java @@ -15,6 +15,7 @@ import org.testcontainers.junit.jupiter.Testcontainers; import java.io.IOException; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collections; @@ -22,6 +23,8 @@ import static gov.cms.ab2d.optout.OptOutConstantsTest.*; import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; @Testcontainers @@ -59,8 +62,23 @@ void optOutHandlerInvoke() { when(context.getLogger()).thenReturn(logger); assertThrows(OptOutException.class, () -> handler.handleRequest(sqsEvent, context)); + verify(handler, times(1)).processSQSMessage(sqsMessage, context); + verify(logger, times(1)).log(anyString()); } + @Test + void itDoesNotLogWhenResultsAreNull() throws URISyntaxException { + Context context = mock(Context.class); + LambdaLogger logger = mock(LambdaLogger.class); + OptOutProcessor processor = mock(OptOutProcessor.class); + + when(context.getLogger()).thenReturn(logger); + when(handler.processorInit(any())).thenReturn(processor); + when(processor.process(anyString(), anyString(), anyString())).thenReturn(null); + + handler.handleRequest(sqsEvent, context); + verify(logger, times(0)).log(anyString()); + } static private String getPayload() throws IOException { return Files.readString(Paths.get("src/test/resources/sqsEvent.json"));