Skip to content

Commit

Permalink
[SELC-441] feat: Solved errors in junit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpaolodidato89 authored Mar 6, 2024
1 parent f2a1575 commit ef8ff1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package it.pagopa.selfcare.user.service;

import io.quarkus.mailer.Mail;
import io.quarkus.mailer.Mailer;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
Expand All @@ -16,11 +13,11 @@
import software.amazon.awssdk.services.ses.model.SendEmailRequest;
import software.amazon.awssdk.services.ses.model.SendEmailResponse;


import java.util.Map;

import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@QuarkusTest
@TestProfile(AwsMailServiceImplTest.AwsProfile.class)
Expand Down Expand Up @@ -52,10 +49,12 @@ void testSendMailNotification() {
when(sesClient.sendEmail(any(SendEmailRequest.class)))
.thenReturn(SendEmailResponse.builder().build());

awsMailService.sendMail("email", "content", "subject")
UniAssertSubscriber<Void> subscriber = awsMailService.sendMail("email", "content", "subject")
.subscribe()
.withSubscriber(UniAssertSubscriber.create());

subscriber.awaitItem();

ArgumentCaptor<SendEmailRequest> mailArgumentCaptor = ArgumentCaptor.forClass(SendEmailRequest.class);
Mockito.verify(sesClient, Mockito.times(1))
.sendEmail(mailArgumentCaptor.capture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ class UserServiceTest {

@InjectMock
private UserInstitutionService userInstitutionService;

@InjectMock
private UserNotificationService userNotificationService;

@InjectMock
private UserInfoService userInfoService;

Expand Down Expand Up @@ -116,13 +118,12 @@ void getUsersEmailsTest() {
UniAssertSubscriber<List<String>> subscriber = userService
.getUsersEmails("institutionId", "productId")
.subscribe()
.withSubscriber(UniAssertSubscriber.create())
.assertCompleted();
.withSubscriber(UniAssertSubscriber.create());

List<String> actual = subscriber.assertCompleted().getItem();
assertNotNull(actual);
assertEquals(1, actual.size());
assertEquals("[email protected]", actual.get(0));
subscriber.assertCompleted();

verify(userRegistryApi).findByIdUsingGET(anyString(), anyString());
verify(userInstitutionService).findAllWithFilter(any());
}

@Test
Expand Down Expand Up @@ -487,11 +488,13 @@ void testUpdateUserStatus() {
any())
).thenReturn(Uni.createFrom().nullItem());

userService.updateUserProductStatus("userId", "institutionId", "productId", OnboardedProductState.ACTIVE,
var subscriber = userService.updateUserProductStatus("userId", "institutionId", "productId", OnboardedProductState.ACTIVE,
LoggedUser.builder().build())
.subscribe()
.withSubscriber(UniAssertSubscriber.create());

subscriber.awaitItem();

verify(userNotificationService, times(1)).sendEmailNotification(
any(UserResource.class),
any(UserInstitution.class),
Expand Down

0 comments on commit ef8ff1e

Please sign in to comment.