【同步】BOOT 和 CLOUD 的功能

master
YunaiV 3 weeks ago
parent 9defcf736c
commit f6eff05053

@ -13,13 +13,15 @@ import cn.iocoder.yudao.module.system.mq.producer.mail.MailProducer;
import cn.iocoder.yudao.module.system.service.member.MemberService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import org.assertj.core.util.Lists;
import org.dromara.hutool.extra.mail.*;
import org.dromara.hutool.extra.mail.MailAccount;
import org.dromara.hutool.extra.mail.MailUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -106,7 +108,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
// 调用
Long resultMailLogId = mailSendService.sendSingleMail(toMails, ccMails, bccMails, userId,
UserTypeEnum.ADMIN.getValue(), templateCode, templateParams);
UserTypeEnum.ADMIN.getValue(), templateCode, templateParams, (File[]) null);
// 断言
assertEquals(mailLogId, resultMailLogId);
// 断言调用
@ -114,7 +116,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
argThat(toMailSet -> toMailSet.contains(user.getEmail()) && toMailSet.contains("admin@test.com")),
argThat(ccMailSet -> ccMailSet.contains("cc@test.com")),
argThat(bccMailSet -> bccMailSet.contains("bcc@test.com")),
eq(account.getId()), eq(template.getNickname()), eq(title), eq(content));
eq(account.getId()), eq(template.getNickname()), eq(title), eq(content), isNull());
}
/**
@ -156,7 +158,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
eq(account), eq(template), eq(content), eq(templateParams), eq(true))).thenReturn(mailLogId);
// 调用
Long resultMailLogId = mailSendService.sendSingleMail(toMails, null, null, userId, userType, templateCode, templateParams);
Long resultMailLogId = mailSendService.sendSingleMail(toMails, null, null, userId, userType, templateCode, templateParams, (java.io.File[]) null);
// 断言
assertEquals(mailLogId, resultMailLogId);
// 断言调用
@ -164,7 +166,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
argThat(toMailSet -> toMailSet.contains(mail)),
argThat(Collection::isEmpty),
argThat(Collection::isEmpty),
eq(account.getId()), eq(template.getNickname()), eq(title), eq(content));
eq(account.getId()), eq(template.getNickname()), eq(title), eq(content), isNull());
}
/**
@ -206,12 +208,12 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
eq(account), eq(template), eq(content), eq(templateParams), eq(false))).thenReturn(mailLogId);
// 调用
Long resultMailLogId = mailSendService.sendSingleMail(toMails, null, null, userId, userType, templateCode, templateParams);
Long resultMailLogId = mailSendService.sendSingleMail(toMails, null, null, userId, userType, templateCode, templateParams, (java.io.File[]) null);
// 断言
assertEquals(mailLogId, resultMailLogId);
// 断言调用
verify(mailProducer, times(0)).sendMailSendMessage(anyLong(), any(), any(), any(),
anyLong(), anyString(), anyString(), anyString());
anyLong(), anyString(), anyString(), anyString(), any());
}
@Test
@ -261,7 +263,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
// 调用,并断言异常
assertServiceException(() -> mailSendService.sendSingleMail(toMails, null, null, userId,
UserTypeEnum.ADMIN.getValue(), templateCode, templateParams),
UserTypeEnum.ADMIN.getValue(), templateCode, templateParams, (java.io.File[]) null),
MAIL_SEND_MAIL_NOT_EXISTS);
}
@ -288,7 +290,7 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
assertEquals(account.getSslEnable(), mailAccount.isSslEnable());
return true;
}), eq(message.getToMails()), eq(message.getCcMails()), eq(message.getBccMails()),
eq(message.getTitle()), eq(message.getContent()), eq(true)))
eq(message.getTitle()), eq(message.getContent()), eq(true), eq(message.getAttachments())))
.thenReturn(messageId);
// 调用
@ -310,17 +312,8 @@ public class MailSendServiceImplTest extends BaseMockitoUnitTest {
// mock 方法(发送邮件)
Exception e = new NullPointerException("啦啦啦");
mailUtilMock.when(() -> MailUtil.send(argThat(mailAccount -> {
assertEquals("芋艿 <7685@qq.com>", mailAccount.getFrom());
assertTrue(mailAccount.isAuth());
assertEquals(account.getUsername(), mailAccount.getUser());
assertArrayEquals(account.getPassword().toCharArray(), mailAccount.getPass());
assertEquals(account.getHost(), mailAccount.getHost());
assertEquals(account.getPort(), mailAccount.getPort());
assertEquals(account.getSslEnable(), mailAccount.isSslEnable());
return true;
}), eq(message.getToMails()), eq(message.getCcMails()), eq(message.getBccMails()),
eq(message.getTitle()), eq(message.getContent()), eq(true))).thenThrow(e);
mailUtilMock.when(() -> MailUtil.send(any(MailAccount.class), any(), any(), any(),
any(), any(), eq(true), any(java.io.File[].class))).thenThrow(e);
// 调用
mailSendService.doSendMail(message);

Loading…
Cancel
Save