Skip to content

Commit ed6a7fe

Browse files
committed
add test
1 parent 9e1760f commit ed6a7fe

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/main/java/org/apache/commons/csv/DbQueryExport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void exportQueryPage(Function<Map<String, Object>, List<String>> pageQuer
7171
}
7272
}
7373

74-
private static List<Integer> calIndexList(int sum, int pageNum) {
74+
public static List<Integer> calIndexList(int sum, int pageNum) {
7575
List<Integer> list = new ArrayList<>(sum / pageNum);
7676
Integer startIndex = 0;
7777
if (sum <= pageNum) {

src/test/java/org/apache/commons/csv/DbQueryExportTest.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.*;
2323
import java.nio.charset.StandardCharsets;
2424
import java.util.HashMap;
25+
import java.util.List;
2526
import java.util.Map;
2627

2728
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,6 +34,26 @@ public class DbQueryExportTest {
3334

3435
private static final File BASE = new File("src/test/resources/DbQueryExport");
3536

37+
@Test
38+
public void testCalIndexList() {
39+
List<Integer> indexList = DbQueryExport.calIndexList(10000000, 100000);
40+
assertEquals(100, indexList.size());
41+
assertEquals(0, indexList.get(0));
42+
}
43+
44+
@Test
45+
public void testParam() {
46+
ExportParam exportParam = new ExportParam();
47+
exportParam.setHeader("name,gender,email");
48+
exportParam.setSum(10000000);
49+
exportParam.setPageSize(100000);
50+
exportParam.setRecordSeparator(Constants.CRLF);
51+
Map<String, Object> searchParam = new HashMap<>(16);
52+
exportParam.setSearchParam(searchParam);
53+
assertEquals(10000000, exportParam.getSum());
54+
assertEquals(100000, exportParam.getPageSize());
55+
}
56+
3657
@Test
3758
public void testExport() {
3859
String filePath = BASE + File.separator + "export-table.csv";
@@ -56,10 +77,6 @@ public void testExport() {
5677
assertEquals(2, searchParam.size());
5778
assertEquals(9900000, searchParam.get(Constants.PADE_QUERY_INDEX));
5879
} catch (IOException e) {
59-
} finally {
60-
// coverage/coveralls — Coverage decreased (-4.8%) to 88.385% delete file
61-
// Do not delete local , export csv file
62-
file.delete();
6380
}
6481
}
6582
}

0 commit comments

Comments
 (0)