package com.jsowell.pile.config; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; /** * AutoSettleConfig 配置类单元测试 * * @author jsowell * @date 2026-08-11 */ public class AutoSettleConfigTest { private AutoSettleConfig config; @Before public void setUp() { config = new AutoSettleConfig(); } @Test public void testDefaultValues() { System.out.println("【测试1】默认值测试"); Assert.assertFalse("功能开关默认应该是关闭", config.getEnabled()); Assert.assertEquals("超时阈值默认10分钟", Integer.valueOf(10), config.getTimeoutMinutes()); Assert.assertEquals("批次大小默认100", Integer.valueOf(100), config.getBatchSize()); Assert.assertEquals("金额阈值比例默认1.5", Double.valueOf(1.5), config.getAmountThresholdRatio()); Assert.assertEquals("数据新鲜度默认30分钟", Integer.valueOf(30), config.getDataFreshnessMinutes()); Assert.assertTrue("告警开关默认开启", config.getAlertEnabled()); Assert.assertEquals("锁超时默认300秒", Long.valueOf(300L), config.getLockTimeout()); Assert.assertEquals("默认cron表达式", "0 */10 * * * ?", config.getInterval()); System.out.println("✅ 默认值测试通过"); } @Test public void testGrayscaleDisabled() { System.out.println("\n【测试2】灰度未启用测试"); config.setGrayscaleStationIds(null); Assert.assertFalse("灰度站点为null,应该未启用", config.isGrayscaleEnabled()); config.setGrayscaleStationIds(Collections.emptyList()); Assert.assertFalse("灰度站点为空列表,应该未启用", config.isGrayscaleEnabled()); // 未启用灰度时,所有站点都应该在范围内 Assert.assertTrue("未启用灰度,站点1应在范围内", config.isStationInGrayscale(1L)); Assert.assertTrue("未启用灰度,站点999应在范围内", config.isStationInGrayscale(999L)); System.out.println("✅ 灰度未启用测试通过"); } @Test public void testGrayscaleEnabled() { System.out.println("\n【测试3】灰度已启用测试"); List stationIds = Arrays.asList(1001L, 1002L, 1003L); config.setGrayscaleStationIds(stationIds); Assert.assertTrue("灰度站点列表非空,应该已启用", config.isGrayscaleEnabled()); Assert.assertTrue("站点1001在灰度列表中", config.isStationInGrayscale(1001L)); Assert.assertTrue("站点1002在灰度列表中", config.isStationInGrayscale(1002L)); Assert.assertTrue("站点1003在灰度列表中", config.isStationInGrayscale(1003L)); Assert.assertFalse("站点9999不在灰度列表中", config.isStationInGrayscale(9999L)); System.out.println("✅ 灰度已启用测试通过"); } @Test public void testSettersAndGetters() { System.out.println("\n【测试4】Setter/Getter测试"); config.setEnabled(true); config.setTimeoutMinutes(20); config.setInterval("0 */5 * * * ?"); config.setBatchSize(200); config.setAmountThresholdRatio(2.0); config.setDataFreshnessMinutes(60); config.setAlertEnabled(false); config.setLockTimeout(600L); Assert.assertTrue(config.getEnabled()); Assert.assertEquals(Integer.valueOf(20), config.getTimeoutMinutes()); Assert.assertEquals("0 */5 * * * ?", config.getInterval()); Assert.assertEquals(Integer.valueOf(200), config.getBatchSize()); Assert.assertEquals(Double.valueOf(2.0), config.getAmountThresholdRatio()); Assert.assertEquals(Integer.valueOf(60), config.getDataFreshnessMinutes()); Assert.assertFalse(config.getAlertEnabled()); Assert.assertEquals(Long.valueOf(600L), config.getLockTimeout()); System.out.println("✅ Setter/Getter测试通过"); } }