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 com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.trading.mapper.BizIsolationPenMapper;
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;

@ExtendWith(MockitoExtension.class)
@DisplayName("PenCodeGenerator")
class PenCodeGeneratorTest
{
    @Mock
    private BizIsolationPenMapper mapper;

    @InjectMocks
    private PenCodeGenerator generator;

    @Test
    @DisplayName("首条编号01")
    void firstCode()
    {
        when(mapper.selectMaxPenCodeForUpdate()).thenReturn(null);
        assertEquals("01", generator.allocateNextCode());
    }

    @Test
    @DisplayName("编号上限")
    void exhausted()
    {
        when(mapper.selectMaxPenCodeForUpdate()).thenReturn("99");
        assertThrows(ServiceException.class, () -> generator.allocateNextCode());
    }
}
