Skip to content

Commit

Permalink
Fix Sonarqube
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Apr 30, 2024
1 parent aaa3011 commit de54520
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions optout/src/test/java/gov/cms/ab2d/optout/OptOutHandlerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gov.cms.ab2d.optout;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import com.amazonaws.services.s3.event.S3EventNotification;
import gov.cms.ab2d.testutils.AB2DPostgresqlContainer;
Expand All @@ -18,6 +20,7 @@
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.Mockito.*;

Expand All @@ -28,15 +31,13 @@ class OptOutHandlerTest {
@Container
private static final PostgreSQLContainer POSTGRE_SQL_CONTAINER = new AB2DPostgresqlContainer();
private final static OptOutHandler handler = spy(new OptOutHandler());
// private final static OptOutProcessor OPT_OUT_PROCESSOR = mock(OptOutProcessor.class);
private final static SQSEvent sqsEvent = mock(SQSEvent.class);
private final static SQSEvent.SQSMessage sqsMessage = mock(SQSEvent.SQSMessage.class);

@BeforeAll
static void beforeAll() throws IOException {
when(sqsEvent.getRecords()).thenReturn(Collections.singletonList(sqsMessage));
when(sqsMessage.getBody()).thenReturn(getPayload());
// when(handler.processorInit(any(LambdaLogger.class))).thenReturn(OPT_OUT_PROCESSOR);
}

@Test
Expand All @@ -51,20 +52,15 @@ void getBucketAndFileNamesTest() throws IOException, ParseException {
assertEquals(TEST_BFD_BUCKET_NAME, handler.getBucketName(notification));
}

// @Test
// void optOutHandlerInvoke() {
// Context context = mock(Context.class);
// LambdaLogger logger = mock(LambdaLogger.class);
// when(context.getLogger()).thenReturn(logger);
//
// assertDoesNotThrow(() -> handler.handleRequest(sqsEvent, context));
// }
@Test
void optOutHandlerInvoke() {
Context context = mock(Context.class);
LambdaLogger logger = mock(LambdaLogger.class);
when(context.getLogger()).thenReturn(logger);

assertThrows(OptOutException.class, () -> handler.handleRequest(sqsEvent, context));
}

// @Test
// void optOutHandlerException() throws URISyntaxException {
// doThrow(new OptOutException("errorMessage", new AmazonS3Exception("errorMessage"))).when(OPT_OUT_PROCESSOR).process();
// assertThrows(OptOutException.class, OPT_OUT_PROCESSOR.process(anyString(), anyString(), anyString()));
// }

static private String getPayload() throws IOException {
return Files.readString(Paths.get("src/test/resources/sqsEvent.json"));
Expand Down

0 comments on commit de54520

Please sign in to comment.