Files
spring-boot-rest/apache-poi/src/test/java/com/baeldung/jexcel/JExcelIntegrationTest.java
freelansam 8155f46a4e JAVA-9566: Update apache-poi version and articles (#11748)
* JAVA-9566: Update apache-poi version and articles

* JAVA-9566: Update apache-poi version and articles
2022-01-31 21:48:39 +05:30

57 lines
1.4 KiB
Java

package com.baeldung.jexcel;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import jxl.read.biff.BiffException;
import jxl.write.WriteException;
public class JExcelIntegrationTest {
private JExcelHelper jExcelHelper;
private static String FILE_NAME = "temp.xls";
private String fileLocation;
@Before
public void generateExcelFile() throws IOException, WriteException {
File currDir = new File(".");
String path = currDir.getAbsolutePath();
fileLocation = path.substring(0, path.length() - 1) + FILE_NAME;
jExcelHelper = new JExcelHelper();
jExcelHelper.writeJExcel();
}
@Test
public void whenParsingJExcelFile_thenCorrect() throws IOException, BiffException {
Map<Integer, List<String>> data = jExcelHelper.readJExcel(fileLocation);
assertEquals("Name", data.get(0)
.get(0));
assertEquals("Age", data.get(0)
.get(1));
assertEquals("John Smith", data.get(2)
.get(0));
assertEquals("20", data.get(2)
.get(1));
}
@After
public void cleanup(){
File testFile = new File(fileLocation);
if (testFile.exists()) {
testFile.delete();
}
}
}