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.BizMarketStall;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("MarketStallValidation")
class MarketStallValidationTest
{

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

    @Test
    @DisplayName("空备注转 null")
    void emptyRemarkToNull()
    {
        BizMarketStall row = new BizMarketStall();
        row.setRemark("   ");
        MarketStallValidation.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();
    }
}
