From bd90806460641545efbbbc0b6f482430f802b8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=A0=E4=B8=80=E4=B8=AA=E4=BA=BA=E5=9C=A8=E8=BF=99?= =?UTF-8?q?=E5=84=BF=E5=B9=B2=E5=98=9B=E4=BD=A0=E6=98=AF=E6=9D=A5=E6=8B=89?= =?UTF-8?q?=E5=B1=8E=E7=9A=84=E5=90=A7?= <1421374934@qq.com> Date: Mon, 3 Apr 2023 22:06:57 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E9=83=A8=E5=88=86=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/service/JavaMailServiceTest.java | 23 +++++++++-- .../service/LoginRecordServiceTest.java | 39 +++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/rymcu/forest/service/JavaMailServiceTest.java b/src/test/java/com/rymcu/forest/service/JavaMailServiceTest.java index b0040e3..1f97ef0 100644 --- a/src/test/java/com/rymcu/forest/service/JavaMailServiceTest.java +++ b/src/test/java/com/rymcu/forest/service/JavaMailServiceTest.java @@ -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())); + } } \ No newline at end of file diff --git a/src/test/java/com/rymcu/forest/service/LoginRecordServiceTest.java b/src/test/java/com/rymcu/forest/service/LoginRecordServiceTest.java index ddf25ed..c560b72 100644 --- a/src/test/java/com/rymcu/forest/service/LoginRecordServiceTest.java +++ b/src/test/java/com/rymcu/forest/service/LoginRecordServiceTest.java @@ -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 loginRecordByIdUser = loginRecordService.findLoginRecordByIdUser(1); + assertTrue(loginRecordByIdUser.isEmpty()); + + } + + + @Test + @DisplayName("测试全部") + void doAll() { + LoginRecord loginRecord = loginRecordService.saveLoginRecord(1L); + assertNotNull(loginRecord); + + List loginRecordByIdUser = loginRecordService.findLoginRecordByIdUser(1); + assertFalse(loginRecordByIdUser.isEmpty()); + } } \ No newline at end of file