🐛 部分测试
This commit is contained in:
parent
daef6ef07d
commit
bd90806460
@ -1,19 +1,36 @@
|
|||||||
package com.rymcu.forest.service;
|
package com.rymcu.forest.service;
|
||||||
|
|
||||||
import com.rymcu.forest.base.BaseServiceTest;
|
import com.rymcu.forest.base.BaseServiceTest;
|
||||||
|
import com.rymcu.forest.dto.NotificationDTO;
|
||||||
import org.junit.jupiter.api.Test;
|
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 {
|
class JavaMailServiceTest extends BaseServiceTest {
|
||||||
|
|
||||||
|
private static final String REALITY_EMAIL = "1421374934@qq.com";
|
||||||
|
@Autowired
|
||||||
|
private JavaMailService javaMailService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sendEmailCode() {
|
void sendEmailCode() throws MessagingException {
|
||||||
|
assertEquals(1, javaMailService.sendEmailCode(REALITY_EMAIL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sendForgetPasswordEmail() {
|
void sendForgetPasswordEmail() throws MessagingException {
|
||||||
|
assertEquals(1, javaMailService.sendForgetPasswordEmail(REALITY_EMAIL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sendNotification() {
|
void sendNotification() throws MessagingException {
|
||||||
|
assertEquals(0, javaMailService.sendNotification(new NotificationDTO()));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,20 +1,59 @@
|
|||||||
package com.rymcu.forest.service;
|
package com.rymcu.forest.service;
|
||||||
|
|
||||||
import com.rymcu.forest.base.BaseServiceTest;
|
import com.rymcu.forest.base.BaseServiceTest;
|
||||||
|
import com.rymcu.forest.entity.LoginRecord;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
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 {
|
class LoginRecordServiceTest extends BaseServiceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LoginRecordService loginRecordService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
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
|
@Test
|
||||||
|
@DisplayName("保存登录记录")
|
||||||
void saveLoginRecord() {
|
void saveLoginRecord() {
|
||||||
|
LoginRecord loginRecord = loginRecordService.saveLoginRecord(1L);
|
||||||
|
assertNotNull(loginRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("获取用户登录记录")
|
||||||
void findLoginRecordByIdUser() {
|
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());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user