From 56d47448cefd3b5dc5fb1b0562b3df046ce7ec02 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 13 Nov 2022 19:22:13 +0000 Subject: [PATCH] Adjust tests, comments, JavaDoc, IDE suggestions Add more output for a flaky test which sometimes fails on very slow hardware Shutdown in tests gracefully Otherwise an NPE may "hide" a test-failure git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905273 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/xwpf/usermodel/XWPFPictureData.java | 2 +- .../java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java | 5 ++++- poi/src/test/java/org/apache/poi/hssf/model/TestRVA.java | 8 ++++++-- .../TestMatrixFormulasFromBinarySpreadsheet.java | 4 +++- .../poi/ss/formula/eval/TestFormulasFromSpreadsheet.java | 4 +++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java index 58fa5b0747..729651e868 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java @@ -39,7 +39,7 @@ public class XWPFPictureData extends POIXMLDocumentPart { private static int MAX_IMAGE_SIZE = DEFAULT_MAX_IMAGE_SIZE; /** - * @param length the max image size allowed for XSSF pictures + * @param length the max image size allowed for XWPF pictures */ public static void setMaxImageSize(int length) { MAX_IMAGE_SIZE = length; diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 7b5093d13e..8a2802f1b9 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -36,6 +36,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.util.*; @@ -3312,7 +3313,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { } LOG.atInfo().log(between(start, now())); - assertTrue(between(start, now()).getSeconds() < 25); + assertTrue(between(start, now()).getSeconds() < 25, + "Had start: " + start + ", now: " + now() + + ", diff: " + Duration.between(start, now()).getSeconds()); } } diff --git a/poi/src/test/java/org/apache/poi/hssf/model/TestRVA.java b/poi/src/test/java/org/apache/poi/hssf/model/TestRVA.java index fd94e0be19..97ec3f25dc 100644 --- a/poi/src/test/java/org/apache/poi/hssf/model/TestRVA.java +++ b/poi/src/test/java/org/apache/poi/hssf/model/TestRVA.java @@ -53,8 +53,12 @@ final class TestRVA { @AfterAll public static void closeResource() throws Exception { - workbook.close(); - poifs.close(); + if (workbook != null) { + workbook.close(); + } + if (poifs != null) { + poifs.close(); + } } public static Stream data() throws Exception { diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java index d56c3d6134..081635d85a 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java @@ -101,7 +101,9 @@ final class TestMatrixFormulasFromBinarySpreadsheet { @AfterAll public static void closeResource() throws Exception { LocaleUtil.setUserLocale(userLocale); - workbook.close(); + if (workbook != null) { + workbook.close(); + } } /* generating parameter instances */ diff --git a/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java b/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java index 98e10c0edc..fa5052458b 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java @@ -100,7 +100,9 @@ public final class TestFormulasFromSpreadsheet { @AfterAll public static void closeResource() throws Exception { LocaleUtil.setUserLocale(userLocale); - workbook.close(); + if (workbook != null) { + workbook.close(); + } } public static Stream data() {