🐛 部分测试

This commit is contained in:
你一个人在这儿干嘛你是来拉屎的吧 2023-04-02 22:11:48 +08:00 committed by Zeeland
parent 5981e6bd31
commit daef6ef07d
4 changed files with 149 additions and 0 deletions

View File

@ -1,7 +1,23 @@
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.CurrencyRule;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
class CurrencyRuleServiceTest extends BaseServiceTest { class CurrencyRuleServiceTest extends BaseServiceTest {
@Autowired
private CurrencyRuleService currencyRuleService;
@Test
void currencyService() {
List<CurrencyRule> all = currencyRuleService.findAll();
assertEquals(0, all.size());
}
} }

View File

@ -1,7 +1,70 @@
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.ArticleDTO;
import com.rymcu.forest.dto.BankAccountDTO;
import com.rymcu.forest.dto.UserInfoDTO;
import com.rymcu.forest.dto.admin.Dashboard;
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 java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
class DashboardServiceTest extends BaseServiceTest { class DashboardServiceTest extends BaseServiceTest {
@Autowired
private DashboardService dashboardService;
@BeforeEach
void setUp() {
}
@Test
@DisplayName("统计系统数据")
void dashboard() {
Dashboard result = dashboardService.dashboard();
assertEquals(1, result.getCountArticleNum());
}
@Test
@DisplayName("统计最近三十天数据")
void lastThirtyDaysData() {
Map result = dashboardService.lastThirtyDaysData();
assertEquals(5, result.size());
assertEquals(30, ((List) result.get("visits")).size());
}
@Test
@DisplayName("获取历史数据")
void history() {
Map result = dashboardService.history();
assertEquals(5, result.size());
assertEquals(12, ((List) result.get("visits")).size());
}
@Test
@DisplayName("获取新增用户列表")
void newUsers() {
List<UserInfoDTO> result = dashboardService.newUsers();
assertEquals(0L, result.size());
}
@Test
@DisplayName("获取新增银行账号列表")
void newBankAccounts() {
List<BankAccountDTO> result = dashboardService.newBankAccounts();
assertEquals(0L, result.size());
}
@Test
@DisplayName("获取新增文章列表")
void newArticles() {
List<ArticleDTO> result = dashboardService.newArticles();
assertEquals(0L, result.size());
}
} }

View File

@ -1,31 +1,80 @@
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.UserDTO;
import com.rymcu.forest.entity.Follow;
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 java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class FollowServiceTest extends BaseServiceTest { class FollowServiceTest extends BaseServiceTest {
private final Long followingId = 1L;
private final Long idUser = 2L;
private final String followingType = "0";
private final Follow follow;
@Autowired
private FollowService followService;
{
follow = new Follow();
follow.setFollowerId(idUser);
follow.setFollowingType(followingType);
follow.setFollowingId(followingId);
}
@Test @Test
void isFollow() { void isFollow() {
Boolean b = followService.isFollow(followingId.intValue(), followingType, idUser);
assertFalse(b);
} }
@Test @Test
@DisplayName("关注操作")
void follow() { void follow() {
Boolean b = followService.follow(follow, "nickname");
assertTrue(b);
} }
@Test @Test
@DisplayName("取消关注操作")
void cancelFollow() { void cancelFollow() {
Boolean b = followService.cancelFollow(follow);
assertTrue(b);
} }
@Test @Test
@DisplayName("获取关注用户者数据")
void findByFollowingId() { void findByFollowingId() {
List<Follow> list = followService.findByFollowingId(followingType, followingId);
assertTrue(list.isEmpty());
} }
@Test @Test
@DisplayName("查询用户粉丝")
void findUserFollowersByUser() { void findUserFollowersByUser() {
UserDTO userDTO = new UserDTO();
userDTO.setIdUser(idUser);
List<UserDTO> list = followService.findUserFollowersByUser(userDTO);
assertTrue(list.isEmpty());
} }
@Test @Test
@DisplayName("查询用户关注用户")
void findUserFollowingsByUser() { void findUserFollowingsByUser() {
UserDTO userDTO = new UserDTO();
userDTO.setIdUser(idUser);
List<UserDTO> list = followService.findUserFollowingsByUser(userDTO);
assertTrue(list.isEmpty());
} }
} }

View File

@ -2,19 +2,40 @@ package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest; import com.rymcu.forest.base.BaseServiceTest;
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 static org.junit.jupiter.api.Assertions.assertEquals;
class ForestFileServiceTest extends BaseServiceTest { class ForestFileServiceTest extends BaseServiceTest {
private final String fileUrl = "localhost/upload/file/123.jpg";
private final String filePath = "upload/file/123.jpg";
private final String md5Value = "md5Value";
private final long createdBy = 1L;
private final long fileSize = 1024L;
private final String fileType = "jpg";
@Autowired
private ForestFileService forestFileService;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
forestFileService.insertForestFile(fileUrl, filePath, md5Value, createdBy, fileSize, fileType);
} }
@Test @Test
@DisplayName("通过md5获取文件访问链接")
void getFileUrlByMd5() { void getFileUrlByMd5() {
String fileUrlByMd5 = forestFileService.getFileUrlByMd5(md5Value, createdBy, fileType);
assertEquals(fileUrl, fileUrlByMd5);
} }
@Test @Test
@DisplayName("插入文件对象")
void insertForestFile() { void insertForestFile() {
int i = forestFileService.insertForestFile(fileUrl, filePath, md5Value, createdBy, fileSize, fileType);
assertEquals(1, i);
} }
} }