package com.ruoyi.web.modules.trading.support;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.trading.mapper.BizTradeOrderMapper;

@ExtendWith(MockitoExtension.class)
@DisplayName("TradeOrderNoGenerator")
class TradeOrderNoGeneratorTest
{
    @Mock
    private BizTradeOrderMapper bizTradeOrderMapper;

    @InjectMocks
    private TradeOrderNoGenerator generator;

    @Test
    @DisplayName("ZCZX-JYDDGL-UT-002 递增序号")
    void ut002_nextSeq()
    {
        when(bizTradeOrderMapper.selectMaxOrderNoSuffixByDatePrefix(org.mockito.ArgumentMatchers.anyString()))
                .thenReturn("008");
        when(bizTradeOrderMapper.countByOrderNo(org.mockito.ArgumentMatchers.anyString())).thenReturn(0);
        String no = generator.allocateNextOrderNo();
        assertEquals(11, no.length());
        assertEquals("009", no.substring(8));
    }

    @Test
    @DisplayName("ZCZX-JYDDGL-UT-003 超999拒绝")
    void ut003_limit()
    {
        when(bizTradeOrderMapper.selectMaxOrderNoSuffixByDatePrefix(org.mockito.ArgumentMatchers.anyString()))
                .thenReturn("999");
        assertThrows(ServiceException.class, () -> generator.allocateNextOrderNo());
    }
}
