aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorVladislav Galas <gallon@apache.org>2019-01-04 10:10:30 +0000
committerVladislav Galas <gallon@apache.org>2019-01-04 10:10:30 +0000
commit1f9b858ae5b41aef1f599c2f47de519d1e36be30 (patch)
tree1c2c541cf89554f8245031e9e2a2b302a82b3ff3 /src/testcases
parent8600f648904ed6ef5e21c1009f48955d8ada89f3 (diff)
downloadpoi-1f9b858ae5b41aef1f599c2f47de519d1e36be30.tar.gz
poi-1f9b858ae5b41aef1f599c2f47de519d1e36be30.zip
Bug 63057: made SXSSFCell.setCellValue(String|RichTextString) exception-safe.
Also removed unused code. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1850342 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
index eab4222ba3..a699161410 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
@@ -1156,4 +1156,47 @@ public abstract class BaseTestCell {
boolean result = cell.getBooleanCellValue();
assertFalse(result);
}
+
+ @Test
+ public void setStringCellValue_ifThrows_shallNotChangeCell() {
+ Cell cell = _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
+
+ final double value = 2.78;
+ cell.setCellValue(value);
+ assertEquals(CellType.NUMERIC, cell.getCellType());
+
+ int badLength = cell.getSheet().getWorkbook().getSpreadsheetVersion().getMaxTextLength() + 1;
+ String badStringValue = new String(new byte[badLength]);
+
+ try {
+ cell.setCellValue(badStringValue);
+ } catch (IllegalArgumentException e) {
+ // no-op, expected to throw but we need to assert something more
+ }
+
+ assertEquals(CellType.NUMERIC, cell.getCellType());
+ assertEquals(value, cell.getNumericCellValue(), 0);
+ }
+
+ @Test
+ public void setStringCellValueWithRichTextString_ifThrows_shallNotChangeCell() {
+ Cell cell = _testDataProvider.createWorkbook().createSheet().createRow(0).createCell(0);
+
+ final double value = 2.78;
+ cell.setCellValue(value);
+ assertEquals(CellType.NUMERIC, cell.getCellType());
+
+ int badLength = cell.getSheet().getWorkbook().getSpreadsheetVersion().getMaxTextLength() + 1;
+ RichTextString badStringValue = cell.getSheet().getWorkbook().getCreationHelper().
+ createRichTextString(new String(new byte[badLength]));
+
+ try {
+ cell.setCellValue(badStringValue);
+ } catch (IllegalArgumentException e) {
+ // no-op, expected to throw but we need to assert something more
+ }
+
+ assertEquals(CellType.NUMERIC, cell.getCellType());
+ assertEquals(value, cell.getNumericCellValue(), 0);
+ }
}