修复 SmsSendServiceTest 单元测试的报错

This commit is contained in:
YunaiV 2022-11-11 00:30:42 +08:00
parent 19d9d66a38
commit c6b8a09356

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.system.service.sms; package cn.iocoder.yudao.module.system.service.sms;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO;
import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO;
import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage;
import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer;
@ -35,12 +36,15 @@ public class SmsSendServiceTest extends BaseMockitoUnitTest {
@InjectMocks @InjectMocks
private SmsSendServiceImpl smsService; private SmsSendServiceImpl smsService;
@Mock
private SmsChannelService smsChannelService;
@Mock @Mock
private SmsTemplateService smsTemplateService; private SmsTemplateService smsTemplateService;
@Mock @Mock
private SmsLogService smsLogService; private SmsLogService smsLogService;
@Mock @Mock
private SmsProducer smsProducer; private SmsProducer smsProducer;
@Mock @Mock
private SmsClientFactory smsClientFactory; private SmsClientFactory smsClientFactory;
@ -66,6 +70,9 @@ public class SmsSendServiceTest extends BaseMockitoUnitTest {
String content = randomString(); String content = randomString();
when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams)))
.thenReturn(content); .thenReturn(content);
// mock SmsChannelService 的方法
SmsChannelDO smsChannel = randomPojo(SmsChannelDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
when(smsChannelService.getSmsChannel(eq(template.getChannelId()))).thenReturn(smsChannel);
// mock SmsLogService 的方法 // mock SmsLogService 的方法
Long smsLogId = randomLongId(); Long smsLogId = randomLongId();
when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.TRUE), eq(template), when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.TRUE), eq(template),
@ -103,6 +110,9 @@ public class SmsSendServiceTest extends BaseMockitoUnitTest {
String content = randomString(); String content = randomString();
when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams))) when(smsTemplateService.formatSmsTemplateContent(eq(template.getContent()), eq(templateParams)))
.thenReturn(content); .thenReturn(content);
// mock SmsChannelService 的方法
SmsChannelDO smsChannel = randomPojo(SmsChannelDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
when(smsChannelService.getSmsChannel(eq(template.getChannelId()))).thenReturn(smsChannel);
// mock SmsLogService 的方法 // mock SmsLogService 的方法
Long smsLogId = randomLongId(); Long smsLogId = randomLongId();
when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.FALSE), eq(template), when(smsLogService.createSmsLog(eq(mobile), eq(userId), eq(userType), eq(Boolean.FALSE), eq(template),