puzhibing
7 小时以前 88580dae55106dcf4a8f80693b90638e07af02fa
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
package com.ruoyi.order.service.impl;
 
import org.junit.jupiter.api.Test;
 
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
 
class TOrderInvoicePageListQueryTest {
 
    @Test
    void pageListLoadsInvoiceDetailsAndUsersInBatches() throws IOException {
        Path sourcePath = Paths.get("src/main/java/com/ruoyi/order/service/impl/TOrderInvoiceServiceImpl.java");
        if (!Files.exists(sourcePath)) {
            sourcePath = Paths.get("ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderInvoiceServiceImpl.java");
        }
        String source = new String(Files.readAllBytes(sourcePath), StandardCharsets.UTF_8);
        String method = source.substring(
                source.indexOf("public PageInfo<TOrderInvoiceVO> pageList"),
                source.indexOf("public List<String> invoicingCompanyOptions"));
 
        assertEquals(1, occurrences(method, "orderInvoiceDetailService.list("));
        assertTrue(method.contains("appUserClient.getUserByIds(appUserIds)"));
        assertFalse(method.contains("appUserClient.getUserById("));
    }
 
    private int occurrences(String source, String target) {
        int count = 0;
        int index = 0;
        while ((index = source.indexOf(target, index)) >= 0) {
            count++;
            index += target.length();
        }
        return count;
    }
}