🐛 部分测试

This commit is contained in:
你一个人在这儿干嘛你是来拉屎的吧 2023-04-03 22:06:57 +08:00 committed by Zeeland
parent daef6ef07d
commit bd90806460
2 changed files with 59 additions and 3 deletions

View File

@ -1,19 +1,36 @@
package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest;
import com.rymcu.forest.dto.NotificationDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.mail.MessagingException;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* javaMail测试
*/
class JavaMailServiceTest extends BaseServiceTest {
private static final String REALITY_EMAIL = "1421374934@qq.com";
@Autowired
private JavaMailService javaMailService;
@Test
void sendEmailCode() {
void sendEmailCode() throws MessagingException {
assertEquals(1, javaMailService.sendEmailCode(REALITY_EMAIL));
}
@Test
void sendForgetPasswordEmail() {
void sendForgetPasswordEmail() throws MessagingException {
assertEquals(1, javaMailService.sendForgetPasswordEmail(REALITY_EMAIL));
}
@Test
void sendNotification() {
void sendNotification() throws MessagingException {
assertEquals(0, javaMailService.sendNotification(new NotificationDTO()));
}
}

View File

@ -1,20 +1,59 @@
package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest;
import com.rymcu.forest.entity.LoginRecord;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class LoginRecordServiceTest extends BaseServiceTest {
@Autowired
private LoginRecordService loginRecordService;
@BeforeEach
void setUp() {
//设置user-agent
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes == null) {
return;
}
MockHttpServletRequest request = (MockHttpServletRequest) attributes.getRequest();
request.addHeader("user-agent", "Windows 10 or Windows Server 2016\", \"windows nt 10\\\\.0\", \"windows nt (10\\\\.0)\" ");
}
@Test
@DisplayName("保存登录记录")
void saveLoginRecord() {
LoginRecord loginRecord = loginRecordService.saveLoginRecord(1L);
assertNotNull(loginRecord);
}
@Test
@DisplayName("获取用户登录记录")
void findLoginRecordByIdUser() {
List<LoginRecord> loginRecordByIdUser = loginRecordService.findLoginRecordByIdUser(1);
assertTrue(loginRecordByIdUser.isEmpty());
}
@Test
@DisplayName("测试全部")
void doAll() {
LoginRecord loginRecord = loginRecordService.saveLoginRecord(1L);
assertNotNull(loginRecord);
List<LoginRecord> loginRecordByIdUser = loginRecordService.findLoginRecordByIdUser(1);
assertFalse(loginRecordByIdUser.isEmpty());
}
}