2026-06-24 f4bd1f3c89d906131495a0aca5aaf82966378510
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package cn.iocoder.yudao.module.trade.service.brokerage;
 
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO;
import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageWithdrawMapper;
import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
import jakarta.annotation.Resource;
import jakarta.validation.Validator;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
 
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.assertEquals;
 
// TODO 芋艿:后续 review
/**
 * {@link BrokerageWithdrawServiceImpl} 的单元测试类
 *
 * @author 芋道源码
 */
@Disabled // TODO 芋艿:后续 fix 补充的单测
@Import(BrokerageWithdrawServiceImpl.class)
public class BrokerageWithdrawServiceImplTest extends BaseDbUnitTest {
 
    @Resource
    private BrokerageWithdrawServiceImpl brokerageWithdrawService;
 
    @Resource
    private BrokerageWithdrawMapper brokerageWithdrawMapper;
 
    @MockitoBean
    private BrokerageRecordService brokerageRecordService;
    @MockitoBean
    private BrokerageUserService brokerageUserService;
    @MockitoBean
    private TradeConfigService tradeConfigService;
 
    @MockitoBean
    private NotifyMessageSendApi notifyMessageSendApi;
 
    @Resource
    private Validator validator;
 
    @Test
    @Disabled  // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
    public void testGetBrokerageWithdrawPage() {
        // mock 数据
        BrokerageWithdrawDO dbBrokerageWithdraw = randomPojo(BrokerageWithdrawDO.class, o -> { // 等会查询到
            o.setUserId(null);
            o.setType(null);
            o.setUserName(null);
            o.setUserAccount(null);
            o.setBankName(null);
            o.setStatus(null);
            o.setCreateTime(null);
        });
        brokerageWithdrawMapper.insert(dbBrokerageWithdraw);
        // 测试 userId 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setUserId(null)));
        // 测试 type 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setType(null)));
        // 测试 name 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setUserName(null)));
        // 测试 accountNo 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setUserAccount(null)));
        // 测试 bankName 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setBankName(null)));
        // 测试 status 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setStatus(null)));
        // 测试 auditReason 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setAuditReason(null)));
        // 测试 auditTime 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setAuditTime(null)));
        // 测试 remark 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setRemark(null)));
        // 测试 createTime 不匹配
        brokerageWithdrawMapper.insert(cloneIgnoreId(dbBrokerageWithdraw, o -> o.setCreateTime(null)));
        // 准备参数
        BrokerageWithdrawPageReqVO reqVO = new BrokerageWithdrawPageReqVO();
        reqVO.setUserId(null);
        reqVO.setType(null);
        reqVO.setUserName(null);
        reqVO.setUserAccount(null);
        reqVO.setBankName(null);
        reqVO.setStatus(null);
        reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
 
        // 调用
        PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(reqVO);
        // 断言
        assertEquals(1, pageResult.getTotal());
        assertEquals(1, pageResult.getList().size());
        assertPojoEquals(dbBrokerageWithdraw, pageResult.getList().get(0));
    }
 
    @Test
    public void testCalculateFeePrice() {
        //Integer withdrawPrice = 100;
        //// 测试手续费比例未设置
        //Integer percent = null;
        //assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 0);
        //// 测试手续费给为0
        //percent = 0;
        //assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 0);
        //// 测试手续费
        //percent = 1;
        //assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 1);
    }
}