diff options
author | Dominik Stadler <centic@apache.org> | 2020-11-01 09:22:09 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2020-11-01 09:22:09 +0000 |
commit | d835bdef42a46f6b70baaf558e0a716914c2a2cb (patch) | |
tree | a0e5a1431acc98297c5f58515c0a9606eeeb5fce /src/ooxml/testcases | |
parent | 232d734941d4a082841e42b9451f2ed1b540bf04 (diff) | |
download | poi-d835bdef42a46f6b70baaf558e0a716914c2a2cb.tar.gz poi-d835bdef42a46f6b70baaf558e0a716914c2a2cb.zip |
Fix file-handle-leaks when re-writing documents or slideshows
When replacing a directory, we should close the previous one
Close some resources in tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1883038 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases')
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java | 2 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java | 22 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java b/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java index 9f2dc299b9..88a845df88 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java +++ b/src/ooxml/testcases/org/apache/poi/ss/tests/TestWorkbookFactory.java @@ -346,6 +346,8 @@ public final class TestWorkbookFactory { fail("Shouldn't be able to open with the wrong password"); } catch (EncryptedDocumentException e) { // expected here + } finally { + wb.close(); } try { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java index 2409829384..4bd1ad11f0 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidationConstraint.java @@ -26,8 +26,7 @@ import org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType; import org.apache.poi.ss.util.CellReference; import org.junit.Test; -import java.util.Collections; -import java.util.stream.Collectors; +import java.io.IOException; import java.util.stream.IntStream; public class TestXSSFDataValidationConstraint { @@ -46,7 +45,7 @@ public class TestXSSFDataValidationConstraint { // FIXME: whitespace wasn't stripped assertEquals(literal, constraint.getFormula1()); } - + @Test public void listLiteralsQuotesAreStripped_arrayConstructor() { // literal list, using array constructor @@ -63,13 +62,14 @@ public class TestXSSFDataValidationConstraint { String[] literal = IntStream.range(0, 129).mapToObj(i -> "a").toArray(String[]::new); assertThrows(IllegalArgumentException.class, () -> new XSSFDataValidationConstraint(literal)); } - + @Test - public void dataValidationListLiteralTooLongFromFile() { - XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("DataValidationListTooLong.xlsx"); - XSSFFormulaEvaluator fEval = wb.getCreationHelper().createFormulaEvaluator(); - DataValidationEvaluator dvEval = new DataValidationEvaluator(wb, fEval); - assertThrows(IllegalArgumentException.class, () -> dvEval.getValidationValuesForCell(new CellReference("Sheet0!A1"))); + public void dataValidationListLiteralTooLongFromFile() throws IOException { + try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("DataValidationListTooLong.xlsx")) { + XSSFFormulaEvaluator fEval = wb.getCreationHelper().createFormulaEvaluator(); + DataValidationEvaluator dvEval = new DataValidationEvaluator(wb, fEval); + assertThrows(IllegalArgumentException.class, () -> dvEval.getValidationValuesForCell(new CellReference("Sheet0!A1"))); + } } @Test @@ -80,7 +80,7 @@ public class TestXSSFDataValidationConstraint { assertNull(constraint.getExplicitListValues()); assertEquals("A1:A5", constraint.getFormula1()); } - + @Test public void namedRangeReference() { // named range list @@ -90,4 +90,4 @@ public class TestXSSFDataValidationConstraint { assertEquals("MyNamedRange", constraint.getFormula1()); } -} +} |