|
@@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer;
|
|
|
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.junit.jupiter.api.Assertions;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.mockito.InjectMocks;
|
|
|
import org.mockito.Mock;
|
|
@@ -35,7 +36,7 @@ import static org.mockito.Mockito.*;
|
|
|
public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
|
|
|
@InjectMocks
|
|
|
- private SmsSendServiceImpl smsService;
|
|
|
+ private SmsSendServiceImpl smsSendService;
|
|
|
|
|
|
@Mock
|
|
|
private AdminUserService adminUserService;
|
|
@@ -80,7 +81,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
eq(content), eq(templateParams))).thenReturn(smsLogId);
|
|
|
|
|
|
// 调用
|
|
|
- Long resultSmsLogId = smsService.sendSingleSmsToAdmin(null, userId, templateCode, templateParams);
|
|
|
+ Long resultSmsLogId = smsSendService.sendSingleSmsToAdmin(null, userId, templateCode, templateParams);
|
|
|
// 断言
|
|
|
assertEquals(smsLogId, resultSmsLogId);
|
|
|
// 断言调用
|
|
@@ -119,7 +120,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
eq(content), eq(templateParams))).thenReturn(smsLogId);
|
|
|
|
|
|
// 调用
|
|
|
- Long resultSmsLogId = smsService.sendSingleSmsToMember(null, userId, templateCode, templateParams);
|
|
|
+ Long resultSmsLogId = smsSendService.sendSingleSmsToMember(null, userId, templateCode, templateParams);
|
|
|
// 断言
|
|
|
assertEquals(smsLogId, resultSmsLogId);
|
|
|
// 断言调用
|
|
@@ -159,7 +160,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
eq(content), eq(templateParams))).thenReturn(smsLogId);
|
|
|
|
|
|
// 调用
|
|
|
- Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams);
|
|
|
+ Long resultSmsLogId = smsSendService.sendSingleSms(mobile, userId, userType, templateCode, templateParams);
|
|
|
// 断言
|
|
|
assertEquals(smsLogId, resultSmsLogId);
|
|
|
// 断言调用
|
|
@@ -199,7 +200,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
eq(content), eq(templateParams))).thenReturn(smsLogId);
|
|
|
|
|
|
// 调用
|
|
|
- Long resultSmsLogId = smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams);
|
|
|
+ Long resultSmsLogId = smsSendService.sendSingleSms(mobile, userId, userType, templateCode, templateParams);
|
|
|
// 断言
|
|
|
assertEquals(smsLogId, resultSmsLogId);
|
|
|
// 断言调用
|
|
@@ -214,7 +215,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
// mock 方法
|
|
|
|
|
|
// 调用,并断言异常
|
|
|
- assertServiceException(() -> smsService.validateSmsTemplate(templateCode),
|
|
|
+ assertServiceException(() -> smsSendService.validateSmsTemplate(templateCode),
|
|
|
SMS_SEND_TEMPLATE_NOT_EXISTS);
|
|
|
}
|
|
|
|
|
@@ -227,7 +228,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
// mock 方法
|
|
|
|
|
|
// 调用,并断言异常
|
|
|
- assertServiceException(() -> smsService.buildTemplateParams(template, templateParams),
|
|
|
+ assertServiceException(() -> smsSendService.buildTemplateParams(template, templateParams),
|
|
|
SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS, "code");
|
|
|
}
|
|
|
|
|
@@ -237,10 +238,24 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
// mock 方法
|
|
|
|
|
|
// 调用,并断言异常
|
|
|
- assertServiceException(() -> smsService.validateMobile(null),
|
|
|
+ assertServiceException(() -> smsSendService.validateMobile(null),
|
|
|
SMS_SEND_MOBILE_NOT_EXISTS);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testSendBatchNotify() {
|
|
|
+ // 准备参数
|
|
|
+ // mock 方法
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ UnsupportedOperationException exception = Assertions.assertThrows(
|
|
|
+ UnsupportedOperationException.class,
|
|
|
+ () -> smsSendService.sendBatchSms(null, null, null, null, null)
|
|
|
+ );
|
|
|
+ // 断言
|
|
|
+ assertEquals("暂时不支持该操作,感兴趣可以实现该功能哟!", exception.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public void testDoSendSms() throws Throwable {
|
|
@@ -255,7 +270,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
eq(message.getTemplateParams()))).thenReturn(sendResult);
|
|
|
|
|
|
// 调用
|
|
|
- smsService.doSendSms(message);
|
|
|
+ smsSendService.doSendSms(message);
|
|
|
// 断言
|
|
|
verify(smsLogService).updateSmsSendResult(eq(message.getLogId()),
|
|
|
eq(sendResult.getSuccess()), eq(sendResult.getApiCode()),
|
|
@@ -274,7 +289,7 @@ public class SmsSendServiceImplTest extends BaseMockitoUnitTest {
|
|
|
List<SmsReceiveRespDTO> receiveResults = randomPojoList(SmsReceiveRespDTO.class);
|
|
|
|
|
|
// 调用
|
|
|
- smsService.receiveSmsStatus(channelCode, text);
|
|
|
+ smsSendService.receiveSmsStatus(channelCode, text);
|
|
|
// 断言
|
|
|
receiveResults.forEach(result -> smsLogService.updateSmsReceiveResult(eq(result.getLogId()), eq(result.getSuccess()),
|
|
|
eq(result.getReceiveTime()), eq(result.getErrorCode()), eq(result.getErrorCode())));
|