aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2021-05-13 12:11:31 +0000
committerDominik Stadler <centic@apache.org>2021-05-13 12:11:31 +0000
commit0e8f4e3634da889cc9ed3e0c69f7368a4ff3c94a (patch)
tree5bd6dad624e667cccf2f037c67a8873cb88c4671
parent454d0452ef2b57519f9604ba548bb9251b555054 (diff)
downloadpoi-0e8f4e3634da889cc9ed3e0c69f7368a4ff3c94a.tar.gz
poi-0e8f4e3634da889cc9ed3e0c69f7368a4ff3c94a.zip
Bug 65227: Add some more tests, but the actual case is hard to reproduce with HSSF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1889838 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi/src/test/java/org/apache/poi/ss/util/TestSheetUtil.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/poi/src/test/java/org/apache/poi/ss/util/TestSheetUtil.java b/poi/src/test/java/org/apache/poi/ss/util/TestSheetUtil.java
index 1731d46371..0a69d41a0e 100644
--- a/poi/src/test/java/org/apache/poi/ss/util/TestSheetUtil.java
+++ b/poi/src/test/java/org/apache/poi/ss/util/TestSheetUtil.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -164,4 +165,54 @@ final class TestSheetUtil {
assertEquals(-1.0, SheetUtil.getColumnWidth(sheet, 0, true, 1, 2), 0.01, "Not having any widht for rows with all empty cells");
}
}
+
+ @Test
+ void testGetColumnWidthBlankCell() throws IOException {
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ sheet.createRow(1);
+ sheet.createRow(2);
+ Cell cell = row.createCell(0);
+
+ cell.setCellValue((String)null);
+
+ assertEquals(-1, SheetUtil.getColumnWidth(sheet, 0, true), "Having some width for rows with actual cells");
+ assertEquals(-1.0, SheetUtil.getColumnWidth(sheet, 0, true, 1, 2), 0.01, "Not having any widht for rows with all empty cells");
+ }
+ }
+
+ @Test
+ void testGetColumnWidthemptyString() throws IOException {
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ sheet.createRow(1);
+ sheet.createRow(2);
+ Cell cell = row.createCell(0);
+
+ cell.setCellValue("");
+
+ assertTrue(SheetUtil.getColumnWidth(sheet, 0, true) > 0, "Having some width for rows with actual cells");
+ assertEquals(-1.0, SheetUtil.getColumnWidth(sheet, 0, true, 1, 2), 0.01, "Not having any widht for rows with all empty cells");
+ }
+ }
+
+ @Test
+ void testGetColumnWidthNullString() throws IOException {
+ try (Workbook wb = new HSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("sheet");
+ Row row = sheet.createRow(0);
+ sheet.createRow(1);
+ sheet.createRow(2);
+ Cell cell = row.createCell(0);
+
+ cell.setCellValue((String)null);
+ //noinspection deprecation
+ cell.setCellType(CellType.STRING);
+
+ assertTrue(SheetUtil.getColumnWidth(sheet, 0, true) > 0, "Having some width for rows with actual cells");
+ assertEquals(-1.0, SheetUtil.getColumnWidth(sheet, 0, true, 1, 2), 0.01, "Not having any widht for rows with all empty cells");
+ }
+ }
}