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

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.trading.domain.BizIsolationPen;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("IsolationPenValidation")
class IsolationPenValidationTest
{

    @Test
    @DisplayName("备注长度")
    void remark()
    {
        assertThrows(ServiceException.class, () -> IsolationPenValidation.validateRemark(longStr(51)));
        assertDoesNotThrow(() -> IsolationPenValidation.validateRemark("A区圈位"));
    }

    @Test
    @DisplayName("空备注转 null")
    void emptyRemarkToNull()
    {
        BizIsolationPen row = new BizIsolationPen();
        row.setRemark("   ");
        IsolationPenValidation.validateRowForSave(row);
        assertNull(row.getRemark());
    }

    private static String longStr(int len)
    {
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++)
        {
            sb.append('备');
        }
        return sb.toString();
    }
}
