修复单元测试报错

This commit is contained in:
YunaiV 2023-07-24 07:03:19 +08:00
parent d68fa54e55
commit 60d5d942c6

View File

@ -84,6 +84,9 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
o.setParams(Lists.newArrayList("code", "op")); o.setParams(Lists.newArrayList("code", "op"));
}); });
when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template);
String title = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getTitle()), eq(templateParams)))
.thenReturn(title);
String content = RandomUtils.randomString(); String content = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams)))
.thenReturn(content); .thenReturn(content);
@ -101,7 +104,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
assertEquals(mailLogId, resultMailLogId); assertEquals(mailLogId, resultMailLogId);
// 断言调用 // 断言调用
verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(user.getEmail()), verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(user.getEmail()),
eq(account.getId()), eq(template.getNickname()), eq(template.getTitle()), eq(content)); eq(account.getId()), eq(template.getNickname()), eq(title), eq(content));
} }
@Test @Test
@ -122,6 +125,9 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
o.setParams(Lists.newArrayList("code", "op")); o.setParams(Lists.newArrayList("code", "op"));
}); });
when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template);
String title = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getTitle()), eq(templateParams)))
.thenReturn(title);
String content = RandomUtils.randomString(); String content = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams)))
.thenReturn(content); .thenReturn(content);
@ -139,7 +145,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
assertEquals(mailLogId, resultMailLogId); assertEquals(mailLogId, resultMailLogId);
// 断言调用 // 断言调用
verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(mail), verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(mail),
eq(account.getId()), eq(template.getNickname()), eq(template.getTitle()), eq(content)); eq(account.getId()), eq(template.getNickname()), eq(title), eq(content));
} }
/** /**
@ -161,6 +167,9 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
o.setParams(Lists.newArrayList("code", "op")); o.setParams(Lists.newArrayList("code", "op"));
}); });
when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template);
String title = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getTitle()), eq(templateParams)))
.thenReturn(title);
String content = RandomUtils.randomString(); String content = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams)))
.thenReturn(content); .thenReturn(content);
@ -178,7 +187,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
assertEquals(mailLogId, resultMailLogId); assertEquals(mailLogId, resultMailLogId);
// 断言调用 // 断言调用
verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(mail), verify(mailProducer).sendMailSendMessage(eq(mailLogId), eq(mail),
eq(account.getId()), eq(template.getNickname()), eq(template.getTitle()), eq(content)); eq(account.getId()), eq(template.getNickname()), eq(title), eq(content));
} }
/** /**
@ -200,6 +209,9 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
o.setParams(Lists.newArrayList("code", "op")); o.setParams(Lists.newArrayList("code", "op"));
}); });
when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template); when(mailTemplateService.getMailTemplateByCodeFromCache(eq(templateCode))).thenReturn(template);
String title = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getTitle()), eq(templateParams)))
.thenReturn(title);
String content = RandomUtils.randomString(); String content = RandomUtils.randomString();
when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams))) when(mailTemplateService.formatMailTemplateContent(eq(template.getContent()), eq(templateParams)))
.thenReturn(content); .thenReturn(content);
@ -267,15 +279,15 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest {
// mock 方法发送邮件 // mock 方法发送邮件
String messageId = randomString(); String messageId = randomString();
mailUtilMock.when(() -> MailUtil.send(argThat(mailAccount -> { mailUtilMock.when(() -> MailUtil.send(argThat(mailAccount -> {
assertEquals("芋艿 <7685@qq.com>", mailAccount.getFrom()); assertEquals("芋艿 <7685@qq.com>", mailAccount.getFrom());
assertTrue(mailAccount.isAuth()); assertTrue(mailAccount.isAuth());
assertEquals(account.getUsername(), mailAccount.getUser()); assertEquals(account.getUsername(), mailAccount.getUser());
assertEquals(account.getPassword(), mailAccount.getPass()); assertEquals(account.getPassword(), mailAccount.getPass());
assertEquals(account.getHost(), mailAccount.getHost()); assertEquals(account.getHost(), mailAccount.getHost());
assertEquals(account.getPort(), mailAccount.getPort()); assertEquals(account.getPort(), mailAccount.getPort());
assertEquals(account.getSslEnable(), mailAccount.isSslEnable()); assertEquals(account.getSslEnable(), mailAccount.isSslEnable());
return true; return true;
}), eq(message.getMail()), eq(message.getTitle()), eq(message.getContent()), eq(true))) }), eq(message.getMail()), eq(message.getTitle()), eq(message.getContent()), eq(true)))
.thenReturn(messageId); .thenReturn(messageId);
// 调用 // 调用