aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2021-01-22 23:00:51 +0000
committerAndreas Beeker <kiwiwings@apache.org>2021-01-22 23:00:51 +0000
commit0e5f513830b8ecb2923f02d3f5eb1e6f1388cb05 (patch)
treed75a488d9be999bac359e928ab06050be13c3733 /src/testcases/org/apache/poi/ss
parent1b55a7930e8c011c27ab3b901bb32512bd398066 (diff)
downloadpoi-0e5f513830b8ecb2923f02d3f5eb1e6f1388cb05.tar.gz
poi-0e5f513830b8ecb2923f02d3f5eb1e6f1388cb05.zip
Sonar fixes
add asserts to tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885819 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss')
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java79
1 files changed, 44 insertions, 35 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
index 2e3979daf1..4d16a6424f 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
@@ -25,6 +25,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.LocaleUtil;
@@ -292,41 +293,47 @@ public abstract class BaseTestSheetAutosizeColumn {
*/
@Test
void largeRowNumbers() throws Exception {
- Workbook workbook = _testDataProvider.createWorkbook();
- Sheet sheet = workbook.createSheet();
- trackColumnsForAutoSizingIfSXSSF(sheet);
-
- Row r0 = sheet.createRow(0);
- r0.createCell(0).setCellValue("I am ROW 0");
- Row r200 = sheet.createRow(200);
- r200.createCell(0).setCellValue("I am ROW 200");
-
- // This should work fine
- sheet.autoSizeColumn(0);
-
- // Get close to 32767
- Row r32765 = sheet.createRow(32765);
- r32765.createCell(0).setCellValue("Nearly there...");
- sheet.autoSizeColumn(0);
-
- // To it
- Row r32767 = sheet.createRow(32767);
- r32767.createCell(0).setCellValue("At the boundary");
- sheet.autoSizeColumn(0);
-
- // And passed it
- Row r32768 = sheet.createRow(32768);
- r32768.createCell(0).setCellValue("Passed");
- Row r32769 = sheet.createRow(32769);
- r32769.createCell(0).setCellValue("More Passed");
- sheet.autoSizeColumn(0);
-
- // Long way passed
- Row r60708 = sheet.createRow(60708);
- r60708.createCell(0).setCellValue("Near the end");
- sheet.autoSizeColumn(0);
-
- workbook.close();
+ try (Workbook workbook = _testDataProvider.createWorkbook()) {
+ boolean isHssf = workbook instanceof HSSFWorkbook;
+ Sheet sheet = workbook.createSheet();
+ trackColumnsForAutoSizingIfSXSSF(sheet);
+
+ Row r0 = sheet.createRow(0);
+ r0.createCell(0).setCellValue("I am ROW 0");
+ Row r200 = sheet.createRow(200);
+ r200.createCell(0).setCellValue("I am ROW 200");
+
+ // This should work fine
+ sheet.autoSizeColumn(0);
+ assertEquals(isHssf ? 3645 : 3545, sheet.getColumnWidth(0));
+
+ // Get close to 32767
+ Row r32765 = sheet.createRow(32765);
+ r32765.createCell(0).setCellValue("Nearly there...");
+ sheet.autoSizeColumn(0);
+ assertEquals(isHssf ? 3645 : 3554, sheet.getColumnWidth(0), 2);
+
+ // To it
+ Row r32767 = sheet.createRow(32767);
+ r32767.createCell(0).setCellValue("At the boundary");
+ sheet.autoSizeColumn(0);
+ assertEquals(isHssf ? 3875 : 4001, sheet.getColumnWidth(0));
+
+ // And passed it
+ Row r32768 = sheet.createRow(32768);
+ r32768.createCell(0).setCellValue("Passed");
+ Row r32769 = sheet.createRow(32769);
+ r32769.createCell(0).setCellValue("More Passed");
+ sheet.autoSizeColumn(0);
+ assertEquals(isHssf ? 3875 : 4001, sheet.getColumnWidth(0));
+
+ // Long way passed
+ Row r60708 = sheet.createRow(60708);
+ r60708.createCell(0).setCellValue("Near the end");
+ sheet.autoSizeColumn(0);
+ assertEquals(isHssf ? 3875 : 4001, sheet.getColumnWidth(0));
+
+ }
}
// TODO should we have this stuff in the FormulaEvaluator?
@@ -348,6 +355,7 @@ public abstract class BaseTestSheetAutosizeColumn {
@Test
void testExcelExporter() throws IOException {
try (final Workbook wb = _testDataProvider.createWorkbook()) {
+ boolean isHssf = wb instanceof HSSFWorkbook;
final Sheet sheet = wb.createSheet("test");
trackColumnsForAutoSizingIfSXSSF(sheet);
final Row row = sheet.createRow(0);
@@ -360,6 +368,7 @@ public abstract class BaseTestSheetAutosizeColumn {
cell.setCellStyle(csDateTime);
sheet.autoSizeColumn(0);
+ assertEquals(isHssf ? 3249 : 3262, sheet.getColumnWidth(0));
}
}
} \ No newline at end of file