Skip to content

Commit 852fb6a

Browse files
committed
add unit test
1 parent c11d07d commit 852fb6a

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.poi.excel.insert;
2+
3+
import org.apache.poi.ss.usermodel.Workbook;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
import org.junit.jupiter.api.Assertions;
7+
8+
import java.io.File;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
import java.net.URISyntaxException;
12+
import java.nio.file.Paths;
13+
14+
public class ExcelInsertRowUnitTest {
15+
private static final String FILE_NAME = "test.xlsx";
16+
private static final String NEW_FILE_NAME = "new_test.xlsx";
17+
private String fileLocation;
18+
private InsertRowHelper insertRowHelper;
19+
20+
@Before
21+
public void setup() throws URISyntaxException {
22+
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
23+
insertRowHelper = new InsertRowHelper();
24+
}
25+
26+
@Test
27+
public void givenWorkbook_whenInsertRowBetween_thenRowCreated() throws IOException {
28+
Workbook newWorkbook = insertRowHelper.insertRowBetweenRows(fileLocation, 2, 1);
29+
FileOutputStream outputStream = new FileOutputStream(NEW_FILE_NAME);
30+
newWorkbook.write(outputStream);
31+
File file = new File(NEW_FILE_NAME);
32+
33+
final int expectedRowResult = 5;
34+
Assertions.assertEquals(expectedRowResult, newWorkbook.getSheetAt(0).getLastRowNum());
35+
36+
outputStream.close();
37+
file.delete();
38+
newWorkbook.close();
39+
}
40+
41+
}

0 commit comments

Comments
 (0)