package com.cf.imes.module.system.validation.products;

import com.cf.imes.framework.test.core.ut.BaseMockitoUnitTest;
import com.cf.imes.module.system.enums.pay.DurationUnitEnum;
import jakarta.validation.ConstraintValidatorContext;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * 时长单位校验器单元测试
 *
 * @author Gqr
 * @since 2025/12/9 14:23
 */
public class DurationUnitValidatorTest extends BaseMockitoUnitTest {
    @Mock
    private ConstraintValidatorContext constraintValidatorContext;

    @Test
    void testValid() {
        DurationUnitValidator validator = new DurationUnitValidator();
        assertTrue(validator.isValid(DurationUnitEnum.YEAR.getCode(), constraintValidatorContext));
        assertTrue(validator.isValid(DurationUnitEnum.MONTH.getCode(), constraintValidatorContext));
        assertTrue(validator.isValid(DurationUnitEnum.DAY.getCode(), constraintValidatorContext));
        assertTrue(validator.isValid(null, constraintValidatorContext));
        assertFalse(validator.isValid(3, constraintValidatorContext));
    }
}
