Skip to content

Commit 9415598

Browse files
committed
SheetUtility tests have been written
1 parent 9fc0f2f commit 9415598

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package tools;
2+
3+
import exceptions.ExtensionNotValidException;
4+
import exceptions.OpenWorkbookException;
5+
import exceptions.SheetNotFoundException;
6+
import org.apache.poi.ss.usermodel.Sheet;
7+
import org.apache.poi.ss.usermodel.Workbook;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.util.List;
14+
15+
class SheetUtilityTest {
16+
17+
private final File excelFile = new File("./src/test/resources/employee.xlsx");
18+
19+
@Test
20+
void length() throws OpenWorkbookException, ExtensionNotValidException, IOException {
21+
Integer length = SheetUtility.length(excelFile);
22+
Assertions.assertEquals(length, 2);
23+
}
24+
25+
@Test
26+
void getNames() throws OpenWorkbookException, ExtensionNotValidException, IOException {
27+
List<String> names = SheetUtility.getNames(excelFile);
28+
Assertions.assertEquals(names.get(0), "Employee");
29+
Assertions.assertEquals(names.get(1), "Office");
30+
31+
}
32+
33+
@Test
34+
void getIndex() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
35+
Integer index = SheetUtility.getIndex(excelFile, "Employee");
36+
Assertions.assertEquals(index, 0);
37+
}
38+
39+
@Test
40+
void getName() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
41+
String name = SheetUtility.getName(excelFile, 0);
42+
Assertions.assertEquals(name, "Employee");
43+
}
44+
45+
@Test
46+
void create() throws OpenWorkbookException, ExtensionNotValidException, IOException {
47+
Sheet sheet = SheetUtility.create(excelFile);
48+
Assertions.assertNotNull(sheet);
49+
}
50+
51+
@Test
52+
void testCreate() throws OpenWorkbookException, ExtensionNotValidException, IOException {
53+
String sheetName = "Admin";
54+
Sheet sheet = SheetUtility.create(excelFile, sheetName);
55+
Assertions.assertNotNull(sheet);
56+
Assertions.assertEquals(sheet.getSheetName(), sheetName);
57+
}
58+
59+
@Test
60+
void testCreate1() throws ExtensionNotValidException {
61+
String extension = "xlsx";
62+
Workbook workbook = WorkbookUtility.create(extension);
63+
Sheet sheet = SheetUtility.create(workbook);
64+
Assertions.assertNotNull(sheet);
65+
}
66+
67+
@Test
68+
void testCreate2() throws ExtensionNotValidException {
69+
String extension = "xlsx";
70+
String sheetName = "Admin";
71+
Workbook workbook = WorkbookUtility.create(extension);
72+
Sheet sheet = SheetUtility.create(workbook, sheetName);
73+
Assertions.assertNotNull(sheet);
74+
Assertions.assertEquals(sheet.getSheetName(), sheetName);
75+
}
76+
77+
@Test
78+
void get() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
79+
Sheet sheet = SheetUtility.get(excelFile);
80+
Assertions.assertNotNull(sheet);
81+
}
82+
83+
@Test
84+
void testGet() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
85+
String sheetName = "Employee";
86+
Sheet sheet = SheetUtility.get(excelFile, sheetName);
87+
Assertions.assertNotNull(sheet);
88+
Assertions.assertEquals(sheet.getSheetName(), sheetName);
89+
}
90+
91+
@Test
92+
void testGet1() throws OpenWorkbookException, SheetNotFoundException, ExtensionNotValidException, IOException {
93+
String sheetName = "Employee";
94+
Sheet sheet = SheetUtility.get(excelFile, 0);
95+
Assertions.assertNotNull(sheet);
96+
Assertions.assertEquals(sheet.getSheetName(), sheetName);
97+
}
98+
99+
@Test
100+
void testGet2() throws OpenWorkbookException, ExtensionNotValidException, IOException, SheetNotFoundException {
101+
Workbook workbook = WorkbookUtility.open(excelFile);
102+
Sheet sheet = SheetUtility.get(workbook);
103+
Assertions.assertNotNull(sheet);
104+
}
105+
106+
@Test
107+
void testGet3() throws OpenWorkbookException, ExtensionNotValidException, IOException, SheetNotFoundException {
108+
String sheetName = "Employee";
109+
Workbook workbook = WorkbookUtility.open(excelFile);
110+
Sheet sheet = SheetUtility.get(workbook, sheetName);
111+
Assertions.assertNotNull(sheet);
112+
Assertions.assertEquals(sheet.getSheetName(), sheetName);
113+
}
114+
115+
@Test
116+
void testGet4() throws OpenWorkbookException, ExtensionNotValidException, IOException, SheetNotFoundException {
117+
String sheetName = "Employee";
118+
Workbook workbook = WorkbookUtility.open(excelFile);
119+
Sheet sheet = SheetUtility.get(workbook, 0);
120+
Assertions.assertNotNull(sheet);
121+
Assertions.assertEquals(sheet.getSheetName(), sheetName);
122+
}
123+
124+
@Test
125+
void getOrCreate() throws OpenWorkbookException, ExtensionNotValidException, IOException {
126+
String sheetName = "Admin";
127+
Workbook workbook = WorkbookUtility.open(excelFile);
128+
Sheet sheet = SheetUtility.getOrCreate(workbook, sheetName);
129+
Assertions.assertNotNull(sheet);
130+
Assertions.assertEquals(sheet.getSheetName(), sheetName);
131+
}
132+
133+
@Test
134+
void isPresent() throws OpenWorkbookException, ExtensionNotValidException, IOException {
135+
String sheetName = "Employee";
136+
Workbook workbook = WorkbookUtility.open(excelFile);
137+
Assertions.assertEquals(true, SheetUtility.isPresent(workbook, sheetName));
138+
}
139+
140+
@Test
141+
void testIsPresent() throws OpenWorkbookException, ExtensionNotValidException, IOException {
142+
Workbook workbook = WorkbookUtility.open(excelFile);
143+
Assertions.assertEquals(true, SheetUtility.isPresent(workbook, 1));
144+
}
145+
146+
@Test
147+
void isNull() throws OpenWorkbookException, ExtensionNotValidException, IOException {
148+
String sheetName = "Car";
149+
Workbook workbook = WorkbookUtility.open(excelFile);
150+
Assertions.assertEquals(true, SheetUtility.isNull(workbook, sheetName));
151+
}
152+
153+
@Test
154+
void testIsNull() throws OpenWorkbookException, ExtensionNotValidException, IOException {
155+
Workbook workbook = WorkbookUtility.open(excelFile);
156+
Assertions.assertEquals(false, SheetUtility.isNull(workbook, 1));
157+
}
158+
}

0 commit comments

Comments
 (0)