small improvement to xls tests
@@ -38,11 +38,13 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.Properties;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
@@ -112,7 +114,7 @@ public class XlsExporterTests extends RefineTest {
}
@Test
- public void exportSimpleXls(){
+ public void exportSimpleXls() throws IOException {
CreateGrid(2, 2);
try {
@@ -121,15 +123,19 @@ public class XlsExporterTests extends RefineTest {
Assert.fail();
}
- // TODO: Not a very effective test!
- // (it didn't crash though, and it created output)
Assert.assertEquals(stream.size(),4096);
+ try (HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(stream.toByteArray()))) {
+ org.apache.poi.ss.usermodel.Sheet ws = wb.getSheetAt(0);
+ org.apache.poi.ss.usermodel.Row row1 = ws.getRow(1);
+ org.apache.poi.ss.usermodel.Cell cell0 = row1.getCell(0);
+ Assert.assertEquals(cell0.toString(),"row0cell0");
+ }
}
@Test
public void exportDateType() throws IOException{
- OffsetDateTime odt = OffsetDateTime.now();
+ OffsetDateTime odt = OffsetDateTime.parse("2019-04-09T12:00+00:00");
createDateGrid(2, 2, odt);
try {
@@ -139,6 +145,13 @@ public class XlsExporterTests extends RefineTest {
}
Assert.assertEquals(stream.size(),4096);
+
+ try (HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(stream.toByteArray()))) {
+ org.apache.poi.ss.usermodel.Sheet ws = wb.getSheetAt(0);
+ org.apache.poi.ss.usermodel.Row row1 = ws.getRow(1);
+ org.apache.poi.ss.usermodel.Cell cell0 = row1.getCell(0);
+ Assert.assertTrue(cell0.toString().contains("2019"));
+ }
}
@Test(enabled=false)
