|
@@ -0,0 +1,162 @@
|
|
|
+// package cn.iocoder.yudao.module.cash.service.paymentinfo;
|
|
|
+//
|
|
|
+// import org.junit.jupiter.api.Disabled;
|
|
|
+// import org.junit.jupiter.api.Test;
|
|
|
+// import org.springframework.boot.test.mock.mockito.MockBean;
|
|
|
+//
|
|
|
+// import javax.annotation.Resource;
|
|
|
+//
|
|
|
+// import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
|
|
+//
|
|
|
+// import cn.iocoder.yudao.module.cash.controller.admin.paymentinfo.vo.*;
|
|
|
+// import cn.iocoder.yudao.module.cash.dal.dataobject.paymentinfo.PaymentInfoDO;
|
|
|
+// import cn.iocoder.yudao.module.cash.dal.mysql.paymentinfo.PaymentInfoMapper;
|
|
|
+// import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+//
|
|
|
+// import javax.annotation.Resource;
|
|
|
+// import org.springframework.context.annotation.Import;
|
|
|
+// import java.util.*;
|
|
|
+// import java.time.LocalDateTime;
|
|
|
+//
|
|
|
+// import static cn.hutool.core.util.RandomUtil.*;
|
|
|
+// import static cn.iocoder.yudao.module.cash.enums.ErrorCodeConstants.*;
|
|
|
+// import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
|
|
+// import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
|
|
+// import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
|
|
+// import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
|
|
+// import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
|
|
+// import static org.junit.jupiter.api.Assertions.*;
|
|
|
+// import static org.mockito.Mockito.*;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * {@link PaymentInfoServiceImpl} 的单元测试类
|
|
|
+// *
|
|
|
+// * @author dp
|
|
|
+// */
|
|
|
+// @Import(PaymentInfoServiceImpl.class)
|
|
|
+// public class PaymentInfoServiceImplTest extends BaseDbUnitTest {
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private PaymentInfoServiceImpl paymentInfoService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private PaymentInfoMapper paymentInfoMapper;
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testCreatePaymentInfo_success() {
|
|
|
+// // 准备参数
|
|
|
+// PaymentInfoSaveReqVO createReqVO = randomPojo(PaymentInfoSaveReqVO.class).setId(null);
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// Long paymentInfoId = paymentInfoService.createPaymentInfo(createReqVO);
|
|
|
+// // 断言
|
|
|
+// assertNotNull(paymentInfoId);
|
|
|
+// // 校验记录的属性是否正确
|
|
|
+// PaymentInfoDO paymentInfo = paymentInfoMapper.selectById(paymentInfoId);
|
|
|
+// assertPojoEquals(createReqVO, paymentInfo, "id");
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testUpdatePaymentInfo_success() {
|
|
|
+// // mock 数据
|
|
|
+// PaymentInfoDO dbPaymentInfo = randomPojo(PaymentInfoDO.class);
|
|
|
+// paymentInfoMapper.insert(dbPaymentInfo);// @Sql: 先插入出一条存在的数据
|
|
|
+// // 准备参数
|
|
|
+// PaymentInfoSaveReqVO updateReqVO = randomPojo(PaymentInfoSaveReqVO.class, o -> {
|
|
|
+// o.setId(dbPaymentInfo.getId()); // 设置更新的 ID
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// paymentInfoService.updatePaymentInfo(updateReqVO);
|
|
|
+// // 校验是否更新正确
|
|
|
+// PaymentInfoDO paymentInfo = paymentInfoMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
+// assertPojoEquals(updateReqVO, paymentInfo);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testUpdatePaymentInfo_notExists() {
|
|
|
+// // 准备参数
|
|
|
+// PaymentInfoSaveReqVO updateReqVO = randomPojo(PaymentInfoSaveReqVO.class);
|
|
|
+//
|
|
|
+// // 调用, 并断言异常
|
|
|
+// assertServiceException(() -> paymentInfoService.updatePaymentInfo(updateReqVO), PAYMENT_INFO_NOT_EXISTS);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testDeletePaymentInfo_success() {
|
|
|
+// // mock 数据
|
|
|
+// PaymentInfoDO dbPaymentInfo = randomPojo(PaymentInfoDO.class);
|
|
|
+// paymentInfoMapper.insert(dbPaymentInfo);// @Sql: 先插入出一条存在的数据
|
|
|
+// // 准备参数
|
|
|
+// Long id = dbPaymentInfo.getId();
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// paymentInfoService.deletePaymentInfo(id);
|
|
|
+// // 校验数据不存在了
|
|
|
+// assertNull(paymentInfoMapper.selectById(id));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void testDeletePaymentInfo_notExists() {
|
|
|
+// // 准备参数
|
|
|
+// Long id = randomLongId();
|
|
|
+//
|
|
|
+// // 调用, 并断言异常
|
|
|
+// assertServiceException(() -> paymentInfoService.deletePaymentInfo(id), PAYMENT_INFO_NOT_EXISTS);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
+// public void testGetPaymentInfoPage() {
|
|
|
+// // mock 数据
|
|
|
+// PaymentInfoDO dbPaymentInfo = randomPojo(PaymentInfoDO.class, o -> { // 等会查询到
|
|
|
+// o.setPaymentInfoUuid(null);
|
|
|
+// o.setPaymentTitle(null);
|
|
|
+// o.setPaymentDate(null);
|
|
|
+// o.setPaymentMoney(null);
|
|
|
+// o.setPayee(null);
|
|
|
+// o.setReason(null);
|
|
|
+// o.setStatus(null);
|
|
|
+// o.setRemarks(null);
|
|
|
+// o.setCreateTime(null);
|
|
|
+// });
|
|
|
+// paymentInfoMapper.insert(dbPaymentInfo);
|
|
|
+// // 测试 paymentInfoUuid 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setPaymentInfoUuid(null)));
|
|
|
+// // 测试 paymentTitle 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setPaymentTitle(null)));
|
|
|
+// // 测试 paymentDate 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setPaymentDate(null)));
|
|
|
+// // 测试 paymentMoney 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setPaymentMoney(null)));
|
|
|
+// // 测试 payee 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setPayee(null)));
|
|
|
+// // 测试 reason 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setReason(null)));
|
|
|
+// // 测试 status 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setStatus(null)));
|
|
|
+// // 测试 remarks 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setRemarks(null)));
|
|
|
+// // 测试 createTime 不匹配
|
|
|
+// paymentInfoMapper.insert(cloneIgnoreId(dbPaymentInfo, o -> o.setCreateTime(null)));
|
|
|
+// // 准备参数
|
|
|
+// PaymentInfoPageReqVO reqVO = new PaymentInfoPageReqVO();
|
|
|
+// reqVO.setPaymentInfoUuid(null);
|
|
|
+// reqVO.setPaymentTitle(null);
|
|
|
+// reqVO.setPaymentDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+// reqVO.setPaymentMoney(null);
|
|
|
+// reqVO.setPayee(null);
|
|
|
+// reqVO.setReason(null);
|
|
|
+// reqVO.setStatus(null);
|
|
|
+// reqVO.setRemarks(null);
|
|
|
+// reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+//
|
|
|
+// // 调用
|
|
|
+// PageResult<PaymentInfoDO> pageResult = paymentInfoService.getPaymentInfoPage(reqVO);
|
|
|
+// // 断言
|
|
|
+// assertEquals(1, pageResult.getTotal());
|
|
|
+// assertEquals(1, pageResult.getList().size());
|
|
|
+// assertPojoEquals(dbPaymentInfo, pageResult.getList().get(0));
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|