龚焕茏
2024-03-08 0fa29e0dc36990e5826be5f6d1bcc84c9a13201a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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));
    }
 
 
}