diff options
author | Javen O'Neal <onealj@apache.org> | 2016-08-22 17:57:45 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2016-08-22 17:57:45 +0000 |
commit | b72e9510e5271ecc5a43ad02be6149031def92e6 (patch) | |
tree | 944278a0053f20ccfa3e4e7fb3fec9a8c74a6f8b /src/testcases | |
parent | d89c5e36e536c83d7b137a8d88bfd8b6191dfe4c (diff) | |
download | poi-b72e9510e5271ecc5a43ad02be6149031def92e6.tar.gz poi-b72e9510e5271ecc5a43ad02be6149031def92e6.zip |
bug 59791: improve Cell.CELL_TYPE_* backwards compatibility
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1757235 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java | 18 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java | 30 |
2 files changed, 39 insertions, 9 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java index ede6a6df1e..e594fdec96 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java @@ -136,45 +136,45 @@ public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm Row row = sheet.createRow(0); Cell cell0 = row.createCell(0); - cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell0.setCellType(CellType.NUMERIC); cell0.setCellValue(100); Cell cell1 = row.createCell(1); - cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell1.setCellType(CellType.NUMERIC); cell1.setCellValue(120); Cell cell2 = row.createCell(2); - cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell2.setCellType(CellType.NUMERIC); cell2.setCellValue(130); // row 1 row = sheet.createRow(1); cell0 = row.createCell(0); - cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell0.setCellType(CellType.NUMERIC); cell0.setCellValue(200); cell1 = row.createCell(1); - cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell1.setCellType(CellType.NUMERIC); cell1.setCellValue(220); cell2 = row.createCell(2); - cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell2.setCellType(CellType.NUMERIC); cell2.setCellValue(230); // row 2 row = sheet.createRow(2); cell0 = row.createCell(0); - cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell0.setCellType(CellType.NUMERIC); cell0.setCellValue(300); cell1 = row.createCell(1); - cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell1.setCellType(CellType.NUMERIC); cell1.setCellValue(320); cell2 = row.createCell(2); - cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); + cell2.setCellType(CellType.NUMERIC); cell2.setCellValue(330); // Create conditional formatting, CELL1 should be yellow if CELL0 is not blank. diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index b2ae06cb9a..db46687c12 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -1015,4 +1015,34 @@ public abstract class BaseTestCell { wb.close(); } + + @Test + public void primitiveToEnumReplacementDoesNotBreakBackwardsCompatibility() { + // bug 59836 + // until we have changes POI from working on primitives (int) to enums, + // we should make sure we minimize backwards compatibility breakages. + // This method tests the old way of working with cell types, alignment, etc. + Workbook wb = _testDataProvider.createWorkbook(); + Sheet sheet = wb.createSheet(); + Row row = sheet.createRow(0); + Cell cell = row.createCell(0); + + // Cell.CELL_TYPE_* -> CellType.* + cell.setCellValue(5.0); + assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); + assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); // make sure old way and new way are compatible + + // make sure switch(int|Enum) still works. Cases must be statically resolvable in Java 6 ("constant expression required") + switch(cell.getCellType()) { + case Cell.CELL_TYPE_NUMERIC: + // expected + break; + case Cell.CELL_TYPE_STRING: + case Cell.CELL_TYPE_ERROR: + case Cell.CELL_TYPE_FORMULA: + case Cell.CELL_TYPE_BLANK: + default: + fail("unexpected cell type: " + cell.getCellType()); + } + } } |