Skip to content

Commit 788a508

Browse files
committed
ExcelUtility tests have been written
1 parent 9415598 commit 788a508

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package tools;
2+
3+
import exceptions.ExtensionNotValidException;
4+
import exceptions.OpenWorkbookException;
5+
import exceptions.SheetNotFoundException;
6+
import org.apache.commons.io.FilenameUtils;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.io.File;
11+
import java.io.IOException;
12+
import java.util.List;
13+
14+
class ExcelUtilityTest {
15+
16+
private final File excelFile = new File("./src/test/resources/employee.xlsx");
17+
18+
@Test
19+
void countAllRowsOfAllSheets() throws OpenWorkbookException, ExtensionNotValidException, IOException {
20+
List<Integer> results = ExcelUtility.countAllRowsOfAllSheets(excelFile);
21+
Assertions.assertEquals(3, results.get(0));
22+
Assertions.assertEquals(3, results.get(1));
23+
}
24+
25+
@Test
26+
void testCountAllRowsOfAllSheets() throws OpenWorkbookException, ExtensionNotValidException, IOException {
27+
List<Integer> results = ExcelUtility.countAllRowsOfAllSheets(excelFile, false);
28+
Assertions.assertEquals(3, results.get(0));
29+
Assertions.assertEquals(3, results.get(1));
30+
}
31+
32+
@Test
33+
void countAllRows() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
34+
Integer count = ExcelUtility.countAllRows(excelFile, "Office");
35+
Assertions.assertEquals(3, count);
36+
}
37+
38+
@Test
39+
void testCountAllRows() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
40+
Integer count = ExcelUtility.countAllRows(excelFile, "Office", false);
41+
Assertions.assertEquals(3, count);
42+
}
43+
44+
@Test
45+
void checkExcelExtension() throws ExtensionNotValidException {
46+
String filename = excelFile.getName();
47+
String extension = ExcelUtility.checkExcelExtension(filename);
48+
Assertions.assertEquals("xlsx", extension);
49+
}
50+
51+
@Test
52+
void isValidExcelExtension() {
53+
String filename = excelFile.getName();
54+
String extension = FilenameUtils.getExtension(filename);
55+
Assertions.assertEquals(true, ExcelUtility.isValidExcelExtension(extension));
56+
}
57+
58+
@Test
59+
void getIndexLastRow() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
60+
Integer index = ExcelUtility.getIndexLastRow(excelFile);
61+
Assertions.assertEquals(3, index);
62+
}
63+
64+
@Test
65+
void testGetIndexLastRow() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
66+
String sheetName = "Employee";
67+
Integer index = ExcelUtility.getIndexLastRow(excelFile, sheetName);
68+
Assertions.assertEquals(3, index);
69+
}
70+
71+
@Test
72+
void getIndexLastColumn() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
73+
Integer index = ExcelUtility.getIndexLastColumn(excelFile);
74+
Assertions.assertEquals(8, index);
75+
}
76+
77+
@Test
78+
void testGetIndexLastColumn() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
79+
String sheetName = "Employee";
80+
Integer index = ExcelUtility.getIndexLastColumn(excelFile, sheetName);
81+
Assertions.assertEquals(8, index);
82+
}
83+
84+
@Test
85+
void testGetIndexLastColumn1() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
86+
Integer index = ExcelUtility.getIndexLastColumn(excelFile, 1);
87+
Assertions.assertEquals(8, index);
88+
}
89+
90+
@Test
91+
void testGetIndexLastColumn2() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
92+
String sheetName = "Employee";
93+
Integer index = ExcelUtility.getIndexLastColumn(excelFile, sheetName, 1);
94+
Assertions.assertEquals(8, index);
95+
}
96+
}

0 commit comments

Comments
 (0)