Skip to content

Commit

Permalink
chore: Add test for resend notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu committed Aug 28, 2024
1 parent 029daba commit 20e7d19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,26 +379,5 @@ void resendNotificationsActivity_failsParsingFilters() {

Mockito.verifyNoInteractions(notificationEventResenderService);
}

@Test
void resendNotificationsActivityException() throws JsonProcessingException {
ExecutionContext context = mock(ExecutionContext.class);
doReturn(Logger.getGlobal()).when(context).getLogger();
String filtersString = "{\"productId\":\"prod-pagopa\", \"status\":[\"COMPLETED\"]}";

doThrow(new NotificationException("Error")).when(notificationEventService).send(any(), any(), any(), any());
// when(notificationEventResenderService.resendNotifications(any(), any())).thenReturn(null);
List<Onboarding> onboardings = new ArrayList<>();
onboardings.add(new Onboarding());
when(onboardingService.getOnboardingsToResend(any(), anyInt(), anyInt())).thenReturn(onboardings);

String nextFilter = function.resendNotificationsActivity(filtersString, context);

ArgumentCaptor<ResendNotificationsFilters> filtersStringCaptor = ArgumentCaptor.forClass(ResendNotificationsFilters.class);
Mockito.verify(notificationEventResenderService, times(1))
.resendNotifications(filtersStringCaptor.capture(), any());
assertEquals("prod-pagopa", filtersStringCaptor.getValue().getProductId());
assertNull(nextFilter);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import io.quarkus.test.junit.QuarkusTest;
import it.pagopa.selfcare.onboarding.dto.ResendNotificationsFilters;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.exception.NotificationException;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import static it.pagopa.selfcare.onboarding.TestUtils.getMockedContext;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -64,6 +66,25 @@ void resendNotificationsEndsIncrementingPageIfIsWorkingOnIntermediatePage() {
assertEquals(1, resendNotificationsFilters.getPage());
}

@Test
void resendNotificationsActivityException() {
ExecutionContext context = mock(ExecutionContext.class);
doReturn(Logger.getGlobal()).when(context).getLogger();

doThrow(new NotificationException("Error")).when(notificationEventService).send(any(), any(), any(), any());

List<Onboarding> onboardings = new ArrayList<>();
onboardings.add(new Onboarding());
when(onboardingService.getOnboardingsToResend(any(), anyInt(), anyInt())).thenReturn(onboardings);

ResendNotificationsFilters resendNotificationsFilters = new ResendNotificationsFilters();
resendNotificationsFilters.setProductId("prod-pagopa");

ResendNotificationsFilters nextFilter = notificationEventResenderServiceDefault.resendNotifications(resendNotificationsFilters, context);

assertNull(nextFilter);
}

private List<Onboarding> mockOnboardingList(int size) {
List<Onboarding> onboardings = new ArrayList<>();
for (int i = 0; i < size; i++) {
Expand Down

0 comments on commit 20e7d19

Please sign in to comment.