package org.dromara.test; import org.dromara.common.core.config.RuoYiConfig; import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.time.LocalDate; import java.time.Month; import java.util.concurrent.TimeUnit; /** * 单元测试案例 * * @author Lion Li */ @SpringBootTest // 此注解只能在 springboot 主包下使用 需包含 main 方法与 yml 配置文件 @DisplayName("单元测试案例") public class DemoUnitTest { @Autowired private RuoYiConfig ruoYiConfig; @DisplayName("测试 @SpringBootTest @Test @DisplayName 注解") @Test public void testTest() { System.out.println(ruoYiConfig); } @Disabled @DisplayName("测试 @Disabled 注解") @Test public void testDisabled() { System.out.println(ruoYiConfig); } @Timeout(value = 2L, unit = TimeUnit.SECONDS) @DisplayName("测试 @Timeout 注解") @Test public void testTimeout() throws InterruptedException { Thread.sleep(3000); System.out.println(ruoYiConfig); } @DisplayName("测试 @RepeatedTest 注解") @RepeatedTest(3) public void testRepeatedTest() { System.out.println(666); } @BeforeAll public static void testBeforeAll() { System.out.println("@BeforeAll =================="); } @BeforeEach public void testBeforeEach() { System.out.println("@BeforeEach =================="); } @AfterEach public void testAfterEach() { System.out.println("@AfterEach =================="); } @AfterAll public static void testAfterAll() { System.out.println("@AfterAll =================="); } /** * @Description TODO 获取本季度的第一天或最后一天 * @Param: [today, isFirst: true 表示开始时间,false表示结束时间] * @return: java.lang.String */ public static String getStartOrEndDayOfQuarter(LocalDate today, Boolean isFirst) { LocalDate resDate = LocalDate.now(); if (today == null) { today = resDate; } Month month = today.getMonth(); Month firstMonthOfQuarter = month.firstMonthOfQuarter(); Month endMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2); if (isFirst) { resDate = LocalDate.of(today.getYear(), firstMonthOfQuarter, 1); } else { resDate = LocalDate.of(today.getYear(), endMonthOfQuarter, endMonthOfQuarter.length(today.isLeapYear())); } return resDate.toString(); } public static void main(String[] args) { System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-05-04"), false)); System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-06-04"), false)); System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-07-04"), false)); System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-01-04"), false)); System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-02-04"), false)); } }