Skip to content

Commit

Permalink
add new test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rwolfe-Nava committed Jun 18, 2024
1 parent f118fa0 commit a7b063e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
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;

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
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit a7b063e

Please sign in to comment.