Commit 1e2bcf9aca580f01ef05ddbed3703f8202e08cc5
1 parent
61672e01
多模块重构 13:修复各种单元测试的报错
Showing
17 changed files
with
108 additions
and
237 deletions
pom.xml
| ... | ... | @@ -61,7 +61,7 @@ |
| 61 | 61 | <artifactId>maven-surefire-plugin</artifactId> |
| 62 | 62 | <version>${maven-surefire-plugin.version}</version> |
| 63 | 63 | </plugin> |
| 64 | - <!-- TODO 看看咋放到 bom 里 --> | |
| 64 | + <!-- maven-compiler-plugin 插件,解决 Lombok + MapStruct 组合 --> | |
| 65 | 65 | <plugin> |
| 66 | 66 | <groupId>org.apache.maven.plugins</groupId> |
| 67 | 67 | <artifactId>maven-compiler-plugin</artifactId> | ... | ... |
yudao-module-bpm/yudao-module-bpm-base/src/test/resources/application-unit-test.yaml
yudao-module-bpm/yudao-module-bpm-base/src/test/resources/logback-spring.xml renamed to yudao-module-bpm/yudao-module-bpm-base/src/test/resources/logback.xml
yudao-module-infra/yudao-module-infra-impl/pom.xml
| ... | ... | @@ -103,26 +103,4 @@ |
| 103 | 103 | </dependency> |
| 104 | 104 | </dependencies> |
| 105 | 105 | |
| 106 | - <build> | |
| 107 | - <!-- 设置构建的 jar 包名 --> | |
| 108 | - <finalName>${artifactId}</finalName> | |
| 109 | - <plugins> | |
| 110 | - <!-- 打包 --> | |
| 111 | - <plugin> | |
| 112 | - <groupId>org.springframework.boot</groupId> | |
| 113 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 114 | - <configuration> | |
| 115 | - <fork>true</fork> | |
| 116 | - </configuration> | |
| 117 | - <executions> | |
| 118 | - <execution> | |
| 119 | - <goals> | |
| 120 | - <goal>repackage</goal> <!-- 将引入的 jar 打入其中 --> | |
| 121 | - </goals> | |
| 122 | - </execution> | |
| 123 | - </executions> | |
| 124 | - </plugin> | |
| 125 | - </plugins> | |
| 126 | - </build> | |
| 127 | - | |
| 128 | 106 | </project> | ... | ... |
yudao-module-member/yudao-module-member-impl/src/test/resources/file/erweima.jpg renamed to yudao-module-infra/yudao-module-infra-impl/src/test/resources/file/erweima.jpg
18 KB
yudao-module-infra/yudao-module-infra-impl/src/test/resources/logback-spring.xml renamed to yudao-module-infra/yudao-module-infra-impl/src/test/resources/logback.xml
yudao-module-infra/yudao-module-infra-impl/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -105,7 +105,7 @@ CREATE TABLE IF NOT EXISTS "infra_api_access_log" ( |
| 105 | 105 | ) COMMENT 'API 访问日志表'; |
| 106 | 106 | |
| 107 | 107 | CREATE TABLE IF NOT EXISTS "infra_api_error_log" ( |
| 108 | - "id" integer not null GENERATED BY DEFAULT AS IDENTITY, | |
| 108 | + "id" bigint not null GENERATED BY DEFAULT AS IDENTITY, | |
| 109 | 109 | "trace_id" varchar(64) not null, |
| 110 | 110 | "user_id" bigint not null default '0', |
| 111 | 111 | "user_type" tinyint not null default '0', | ... | ... |
yudao-module-member/yudao-module-member-impl/pom.xml
| ... | ... | @@ -81,26 +81,4 @@ |
| 81 | 81 | |
| 82 | 82 | </dependencies> |
| 83 | 83 | |
| 84 | - <build> | |
| 85 | - <!-- 设置构建的 jar 包名 --> | |
| 86 | - <finalName>${artifactId}</finalName> | |
| 87 | - <plugins> | |
| 88 | - <!-- 打包 --> | |
| 89 | - <plugin> | |
| 90 | - <groupId>org.springframework.boot</groupId> | |
| 91 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 92 | - <configuration> | |
| 93 | - <fork>true</fork> | |
| 94 | - </configuration> | |
| 95 | - <executions> | |
| 96 | - <execution> | |
| 97 | - <goals> | |
| 98 | - <goal>repackage</goal> <!-- 将引入的 jar 打入其中 --> | |
| 99 | - </goals> | |
| 100 | - </execution> | |
| 101 | - </executions> | |
| 102 | - </plugin> | |
| 103 | - </plugins> | |
| 104 | - </build> | |
| 105 | - | |
| 106 | 84 | </project> | ... | ... |
yudao-module-member/yudao-module-member-impl/src/test/resources/logback-spring.xml renamed to yudao-module-member/yudao-module-member-impl/src/test/resources/logback.xml
yudao-module-pay/yudao-module-pay-impl/pom.xml
| ... | ... | @@ -78,26 +78,4 @@ |
| 78 | 78 | |
| 79 | 79 | </dependencies> |
| 80 | 80 | |
| 81 | - <build> | |
| 82 | - <!-- 设置构建的 jar 包名 --> | |
| 83 | - <finalName>${artifactId}</finalName> | |
| 84 | - <plugins> | |
| 85 | - <!-- 打包 --> | |
| 86 | - <plugin> | |
| 87 | - <groupId>org.springframework.boot</groupId> | |
| 88 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 89 | - <configuration> | |
| 90 | - <fork>true</fork> | |
| 91 | - </configuration> | |
| 92 | - <executions> | |
| 93 | - <execution> | |
| 94 | - <goals> | |
| 95 | - <goal>repackage</goal> <!-- 将引入的 jar 打入其中 --> | |
| 96 | - </goals> | |
| 97 | - </execution> | |
| 98 | - </executions> | |
| 99 | - </plugin> | |
| 100 | - </plugins> | |
| 101 | - </build> | |
| 102 | - | |
| 103 | 81 | </project> | ... | ... |
yudao-module-pay/yudao-module-pay-impl/src/test/resources/logback-spring.xml renamed to yudao-module-pay/yudao-module-pay-impl/src/test/resources/logback.xml
yudao-module-system/yudao-module-system-impl/pom.xml
| ... | ... | @@ -98,26 +98,4 @@ |
| 98 | 98 | |
| 99 | 99 | </dependencies> |
| 100 | 100 | |
| 101 | - <build> | |
| 102 | - <!-- 设置构建的 jar 包名 --> | |
| 103 | - <finalName>${artifactId}</finalName> | |
| 104 | - <plugins> | |
| 105 | - <!-- 打包 --> | |
| 106 | - <plugin> | |
| 107 | - <groupId>org.springframework.boot</groupId> | |
| 108 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 109 | - <configuration> | |
| 110 | - <fork>true</fork> | |
| 111 | - </configuration> | |
| 112 | - <executions> | |
| 113 | - <execution> | |
| 114 | - <goals> | |
| 115 | - <goal>repackage</goal> <!-- 将引入的 jar 打入其中 --> | |
| 116 | - </goals> | |
| 117 | - </execution> | |
| 118 | - </executions> | |
| 119 | - </plugin> | |
| 120 | - </plugins> | |
| 121 | - </build> | |
| 122 | - | |
| 123 | 101 | </project> | ... | ... |
yudao-module-system/yudao-module-system-impl/src/test/resources/logback-spring.xml renamed to yudao-module-system/yudao-module-system-impl/src/test/resources/logback.xml
yudao-module-tool/yudao-module-tool-impl/pom.xml
| ... | ... | @@ -79,26 +79,4 @@ |
| 79 | 79 | </dependency> |
| 80 | 80 | </dependencies> |
| 81 | 81 | |
| 82 | - <build> | |
| 83 | - <!-- 设置构建的 jar 包名 --> | |
| 84 | - <finalName>${artifactId}</finalName> | |
| 85 | - <plugins> | |
| 86 | - <!-- 打包 --> | |
| 87 | - <plugin> | |
| 88 | - <groupId>org.springframework.boot</groupId> | |
| 89 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 90 | - <configuration> | |
| 91 | - <fork>true</fork> | |
| 92 | - </configuration> | |
| 93 | - <executions> | |
| 94 | - <execution> | |
| 95 | - <goals> | |
| 96 | - <goal>repackage</goal> <!-- 将引入的 jar 打入其中 --> | |
| 97 | - </goals> | |
| 98 | - </execution> | |
| 99 | - </executions> | |
| 100 | - </plugin> | |
| 101 | - </plugins> | |
| 102 | - </build> | |
| 103 | - | |
| 104 | 82 | </project> | ... | ... |
yudao-module-tool/yudao-module-tool-impl/src/main/java/cn/iocoder/yudao/module/tool/dal/dataobject/test/TestDemoDO.java
| ... | ... | @@ -5,8 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableId; |
| 5 | 5 | import com.baomidou.mybatisplus.annotation.TableName; |
| 6 | 6 | import lombok.*; |
| 7 | 7 | |
| 8 | -import java.util.Date; | |
| 9 | - | |
| 10 | 8 | /** |
| 11 | 9 | * 字典类型 DO |
| 12 | 10 | * |
| ... | ... | @@ -46,25 +44,5 @@ public class TestDemoDO extends BaseDO { |
| 46 | 44 | * 备注 |
| 47 | 45 | */ |
| 48 | 46 | private String remark; |
| 49 | - /** | |
| 50 | - * 创建者 | |
| 51 | - */ | |
| 52 | - private String creator; | |
| 53 | - /** | |
| 54 | - * 创建时间 | |
| 55 | - */ | |
| 56 | - private Date createTime; | |
| 57 | - /** | |
| 58 | - * 更新者 | |
| 59 | - */ | |
| 60 | - private String updater; | |
| 61 | - /** | |
| 62 | - * 更新时间 | |
| 63 | - */ | |
| 64 | - private Date updateTime; | |
| 65 | - /** | |
| 66 | - * 是否删除 | |
| 67 | - */ | |
| 68 | - private Boolean deleted; | |
| 69 | 47 | |
| 70 | 48 | } | ... | ... |
yudao-module-tool/yudao-module-tool-impl/src/main/java/cn/iocoder/yudao/module/tool/service/codegen/inner/CodegenBuilder.java
| 1 | 1 | package cn.iocoder.yudao.module.tool.service.codegen.inner; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | +import cn.hutool.core.util.ReflectUtil; | |
| 4 | 5 | import cn.hutool.core.util.StrUtil; |
| 5 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 6 | 6 | import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; |
| 7 | 7 | import cn.iocoder.yudao.module.tool.convert.codegen.CodegenConvert; |
| 8 | 8 | import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO; |
| ... | ... | @@ -96,7 +96,7 @@ public class CodegenBuilder { |
| 96 | 96 | .build(); |
| 97 | 97 | |
| 98 | 98 | static { |
| 99 | - Arrays.stream(TenantBaseDO.class.getDeclaredFields()).forEach(field -> BASE_DO_FIELDS.add(field.getName())); | |
| 99 | + Arrays.stream(ReflectUtil.getFields(TenantBaseDO.class)).forEach(field -> BASE_DO_FIELDS.add(field.getName())); | |
| 100 | 100 | // 处理 OPERATION 相关的字段 |
| 101 | 101 | CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); |
| 102 | 102 | UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); | ... | ... |
yudao-module-tool/yudao-module-tool-impl/src/test/java/cn/iocoder/yudao/module/tool/service/test/TestDemoServiceImplTest.java
| 1 | 1 | package cn.iocoder.yudao.module.tool.service.test; |
| 2 | 2 | |
| 3 | -import org.junit.jupiter.api.Test; | |
| 4 | -import org.springframework.boot.test.mock.mockito.MockBean; | |
| 5 | - | |
| 6 | -import javax.annotation.Resource; | |
| 7 | - | |
| 8 | -import cn.iocoder.yudao.module.tool.test.BaseDbUnitTest; | |
| 9 | -import cn.iocoder.yudao.module.tool.controller.admin.test.vo.*; | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; | |
| 6 | +import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoCreateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoExportReqVO; | |
| 8 | +import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoPageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoUpdateReqVO; | |
| 10 | 10 | import cn.iocoder.yudao.module.tool.dal.dataobject.test.TestDemoDO; |
| 11 | 11 | import cn.iocoder.yudao.module.tool.dal.mysql.test.TestDemoMapper; |
| 12 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 12 | +import cn.iocoder.yudao.module.tool.test.BaseDbUnitTest; | |
| 13 | +import org.junit.jupiter.api.Test; | |
| 14 | +import org.springframework.context.annotation.Import; | |
| 13 | 15 | |
| 14 | 16 | import javax.annotation.Resource; |
| 15 | -import org.springframework.context.annotation.Import; | |
| 16 | -import java.util.*; | |
| 17 | - | |
| 18 | -import static cn.hutool.core.util.RandomUtil.*; | |
| 19 | -import static cn.iocoder.yudao.module.tool.enums.ErrorCodeConstants.*; | |
| 20 | -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 21 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 22 | -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 23 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 17 | +import java.util.List; | |
| 18 | + | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | |
| 20 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | |
| 21 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | |
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | |
| 24 | +import static cn.iocoder.yudao.module.tool.enums.ErrorCodeConstants.TEST_DEMO_NOT_EXISTS; | |
| 24 | 25 | import static org.junit.jupiter.api.Assertions.*; |
| 25 | -import static org.mockito.Mockito.*; | |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | -* {@link TestDemoServiceImpl} 的单元测试类 | |
| 29 | -* | |
| 30 | -* @author 芋道源码 | |
| 31 | -*/ | |
| 28 | + * {@link TestDemoServiceImpl} 的单元测试类 | |
| 29 | + * | |
| 30 | + * @author 芋道源码 | |
| 31 | + */ | |
| 32 | 32 | @Import(TestDemoServiceImpl.class) |
| 33 | 33 | public class TestDemoServiceImplTest extends BaseDbUnitTest { |
| 34 | 34 | |
| ... | ... | @@ -88,8 +88,8 @@ public class TestDemoServiceImplTest extends BaseDbUnitTest { |
| 88 | 88 | |
| 89 | 89 | // 调用 |
| 90 | 90 | testDemoService.deleteTestDemo(id); |
| 91 | - // 校验数据不存在了 | |
| 92 | - assertNull(testDemoMapper.selectById(id)); | |
| 91 | + // 校验数据不存在了 | |
| 92 | + assertNull(testDemoMapper.selectById(id)); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | @Test |
| ... | ... | @@ -101,87 +101,87 @@ public class TestDemoServiceImplTest extends BaseDbUnitTest { |
| 101 | 101 | assertServiceException(() -> testDemoService.deleteTestDemo(id), TEST_DEMO_NOT_EXISTS); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - @Test // TODO 请修改 null 为需要的值 | |
| 104 | + @Test | |
| 105 | 105 | public void testGetTestDemoPage() { |
| 106 | - // mock 数据 | |
| 107 | - TestDemoDO dbTestDemo = randomPojo(TestDemoDO.class, o -> { // 等会查询到 | |
| 108 | - o.setName(null); | |
| 109 | - o.setStatus(null); | |
| 110 | - o.setType(null); | |
| 111 | - o.setCategory(null); | |
| 112 | - o.setRemark(null); | |
| 113 | - o.setCreateTime(null); | |
| 114 | - }); | |
| 115 | - testDemoMapper.insert(dbTestDemo); | |
| 116 | - // 测试 name 不匹配 | |
| 117 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setName(null))); | |
| 118 | - // 测试 status 不匹配 | |
| 119 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setStatus(null))); | |
| 120 | - // 测试 type 不匹配 | |
| 121 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setType(null))); | |
| 122 | - // 测试 category 不匹配 | |
| 123 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCategory(null))); | |
| 124 | - // 测试 remark 不匹配 | |
| 125 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setRemark(null))); | |
| 126 | - // 测试 createTime 不匹配 | |
| 127 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCreateTime(null))); | |
| 128 | - // 准备参数 | |
| 129 | - TestDemoPageReqVO reqVO = new TestDemoPageReqVO(); | |
| 130 | - reqVO.setName(null); | |
| 131 | - reqVO.setStatus(null); | |
| 132 | - reqVO.setType(null); | |
| 133 | - reqVO.setCategory(null); | |
| 134 | - reqVO.setRemark(null); | |
| 135 | - reqVO.setBeginCreateTime(null); | |
| 136 | - reqVO.setEndCreateTime(null); | |
| 137 | - | |
| 138 | - // 调用 | |
| 139 | - PageResult<TestDemoDO> pageResult = testDemoService.getTestDemoPage(reqVO); | |
| 140 | - // 断言 | |
| 141 | - assertEquals(1, pageResult.getTotal()); | |
| 142 | - assertEquals(1, pageResult.getList().size()); | |
| 143 | - assertPojoEquals(dbTestDemo, pageResult.getList().get(0)); | |
| 106 | + // mock 数据 | |
| 107 | + TestDemoDO dbTestDemo = randomPojo(TestDemoDO.class, o -> { // 等会查询到 | |
| 108 | + o.setName("芋道源码"); | |
| 109 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 110 | + o.setType(1); | |
| 111 | + o.setCategory(2); | |
| 112 | + o.setRemark("哈哈哈"); | |
| 113 | + o.setCreateTime(DateUtils.buildTime(2021, 11, 11)); | |
| 114 | + }); | |
| 115 | + testDemoMapper.insert(dbTestDemo); | |
| 116 | + // 测试 name 不匹配 | |
| 117 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setName("不匹配"))); | |
| 118 | + // 测试 status 不匹配 | |
| 119 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | |
| 120 | + // 测试 type 不匹配 | |
| 121 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setType(2))); | |
| 122 | + // 测试 category 不匹配 | |
| 123 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCategory(1))); | |
| 124 | + // 测试 remark 不匹配 | |
| 125 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setRemark("呵呵呵"))); | |
| 126 | + // 测试 createTime 不匹配 | |
| 127 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCreateTime(DateUtils.buildTime(2021, 12, 12)))); | |
| 128 | + // 准备参数 | |
| 129 | + TestDemoPageReqVO reqVO = new TestDemoPageReqVO(); | |
| 130 | + reqVO.setName("芋道"); | |
| 131 | + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 132 | + reqVO.setType(1); | |
| 133 | + reqVO.setCategory(2); | |
| 134 | + reqVO.setRemark("哈哈哈"); | |
| 135 | + reqVO.setBeginCreateTime(DateUtils.buildTime(2021, 11, 10)); | |
| 136 | + reqVO.setEndCreateTime(DateUtils.buildTime(2021, 11, 12)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<TestDemoDO> pageResult = testDemoService.getTestDemoPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbTestDemo, pageResult.getList().get(0)); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - @Test // TODO 请修改 null 为需要的值 | |
| 146 | + @Test | |
| 147 | 147 | public void testGetTestDemoList() { |
| 148 | - // mock 数据 | |
| 149 | - TestDemoDO dbTestDemo = randomPojo(TestDemoDO.class, o -> { // 等会查询到 | |
| 150 | - o.setName(null); | |
| 151 | - o.setStatus(null); | |
| 152 | - o.setType(null); | |
| 153 | - o.setCategory(null); | |
| 154 | - o.setRemark(null); | |
| 155 | - o.setCreateTime(null); | |
| 156 | - }); | |
| 157 | - testDemoMapper.insert(dbTestDemo); | |
| 158 | - // 测试 name 不匹配 | |
| 159 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setName(null))); | |
| 160 | - // 测试 status 不匹配 | |
| 161 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setStatus(null))); | |
| 162 | - // 测试 type 不匹配 | |
| 163 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setType(null))); | |
| 164 | - // 测试 category 不匹配 | |
| 165 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCategory(null))); | |
| 166 | - // 测试 remark 不匹配 | |
| 167 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setRemark(null))); | |
| 168 | - // 测试 createTime 不匹配 | |
| 169 | - testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCreateTime(null))); | |
| 170 | - // 准备参数 | |
| 171 | - TestDemoExportReqVO reqVO = new TestDemoExportReqVO(); | |
| 172 | - reqVO.setName(null); | |
| 173 | - reqVO.setStatus(null); | |
| 174 | - reqVO.setType(null); | |
| 175 | - reqVO.setCategory(null); | |
| 176 | - reqVO.setRemark(null); | |
| 177 | - reqVO.setBeginCreateTime(null); | |
| 178 | - reqVO.setEndCreateTime(null); | |
| 179 | - | |
| 180 | - // 调用 | |
| 181 | - List<TestDemoDO> list = testDemoService.getTestDemoList(reqVO); | |
| 182 | - // 断言 | |
| 183 | - assertEquals(1, list.size()); | |
| 184 | - assertPojoEquals(dbTestDemo, list.get(0)); | |
| 148 | + // mock 数据 | |
| 149 | + TestDemoDO dbTestDemo = randomPojo(TestDemoDO.class, o -> { // 等会查询到 | |
| 150 | + o.setName("芋道源码"); | |
| 151 | + o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 152 | + o.setType(1); | |
| 153 | + o.setCategory(2); | |
| 154 | + o.setRemark("哈哈哈"); | |
| 155 | + o.setCreateTime(DateUtils.buildTime(2021, 11, 11)); | |
| 156 | + }); | |
| 157 | + testDemoMapper.insert(dbTestDemo); | |
| 158 | + // 测试 name 不匹配 | |
| 159 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setName("不匹配"))); | |
| 160 | + // 测试 status 不匹配 | |
| 161 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | |
| 162 | + // 测试 type 不匹配 | |
| 163 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setType(2))); | |
| 164 | + // 测试 category 不匹配 | |
| 165 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCategory(1))); | |
| 166 | + // 测试 remark 不匹配 | |
| 167 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setRemark("呵呵呵"))); | |
| 168 | + // 测试 createTime 不匹配 | |
| 169 | + testDemoMapper.insert(cloneIgnoreId(dbTestDemo, o -> o.setCreateTime(DateUtils.buildTime(2021, 12, 12)))); | |
| 170 | + // 准备参数 | |
| 171 | + TestDemoExportReqVO reqVO = new TestDemoExportReqVO(); | |
| 172 | + reqVO.setName("芋道"); | |
| 173 | + reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 174 | + reqVO.setType(1); | |
| 175 | + reqVO.setCategory(2); | |
| 176 | + reqVO.setRemark("哈哈哈"); | |
| 177 | + reqVO.setBeginCreateTime(DateUtils.buildTime(2021, 11, 10)); | |
| 178 | + reqVO.setEndCreateTime(DateUtils.buildTime(2021, 11, 12)); | |
| 179 | + | |
| 180 | + // 调用 | |
| 181 | + List<TestDemoDO> list = testDemoService.getTestDemoList(reqVO); | |
| 182 | + // 断言 | |
| 183 | + assertEquals(1, list.size()); | |
| 184 | + assertPojoEquals(dbTestDemo, list.get(0)); | |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | } | ... | ... |