From 5226ed80dd87ca47e3f97798e974b4235ad3ba75 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 1 Nov 2020 09:21:16 +0000 Subject: [PATCH] Improve error messages on missing Factory-implementations, fix Sonar issues and IDE warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1883035 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/extractor/ExtractorFactory.java | 6 ++- .../poi/ss/usermodel/WorkbookFactory.java | 3 +- .../poifs/crypt/tests/TestHxxFEncryption.java | 2 +- .../poi/xssf/model/TestThemesTable.java | 46 +++++++++---------- .../poi/hssf/record/TestNameRecord.java | 3 -- .../eval/BaseTestCircularReferences.java | 3 +- .../org/apache/poi/util/TestLocaleUtil.java | 28 +++++------ 7 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/java/org/apache/poi/extractor/ExtractorFactory.java b/src/java/org/apache/poi/extractor/ExtractorFactory.java index a908a73085..0833535189 100644 --- a/src/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/src/java/org/apache/poi/extractor/ExtractorFactory.java @@ -307,8 +307,10 @@ public final class ExtractorFactory { } } } - throw new IOException("Your InputStream was neither an OLE2 stream, nor an OOXML stream " + - "or you haven't provide the poi-ooxml*.jar and/or poi-scratchpad*.jar in the classpath/modulepath - FileMagic: "+fm); + throw new IOException( + "Your InputStream was neither an OLE2 stream, nor an OOXML stream " + + "or you haven't provide the poi-ooxml*.jar and/or poi-scratchpad*.jar in the classpath/modulepath - FileMagic: " + fm + + ", providers: " + Singleton.INSTANCE.provider); } public static void addProvider(ExtractorProvider provider){ diff --git a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java index c0f376f65f..b730731f7c 100644 --- a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java +++ b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java @@ -296,7 +296,8 @@ public final class WorkbookFactory { } } throw new IOException("Your InputStream was neither an OLE2 stream, nor an OOXML stream " + - "or you haven't provide the poi-ooxml*.jar in the classpath/modulepath - FileMagic: "+fm); + "or you haven't provide the poi-ooxml*.jar in the classpath/modulepath - FileMagic: " + fm + + ", having providers: " + Singleton.INSTANCE.provider); } public static void addProvider(WorkbookProvider provider){ diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java index 393186e68d..a687045645 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/tests/TestHxxFEncryption.java @@ -49,7 +49,7 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class TestHxxFEncryption { - @Parameter(value = 0) + @Parameter public POIDataSamples sampleDir; @Parameter(value = 1) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestThemesTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestThemesTable.java index 2642fb0074..81bb44b90e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestThemesTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestThemesTable.java @@ -45,12 +45,14 @@ import org.junit.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; public class TestThemesTable { - private final String testFileSimple = "Themes.xlsx"; - private final String testFileComplex = "Themes2.xlsx"; - // TODO .xls version available too, add HSSF support then check + private static final String testFileComplex = "Themes2.xlsx"; + // TODO .xls version available too, add HSSF support then check + + // For offline testing + private static final boolean createFiles = false; // What colours they should show up as - private static String[] rgbExpected = { + private static final String[] rgbExpected = { "ffffff", // Lt1 "000000", // Dk1 "eeece1", // Lt2 @@ -68,6 +70,7 @@ public class TestThemesTable { @Test public void testThemesTableColors() throws Exception { // Load our two test workbooks + String testFileSimple = "Themes.xlsx"; XSSFWorkbook simple = XSSFTestDataSamples.openSampleWorkbook(testFileSimple); XSSFWorkbook complex = XSSFTestDataSamples.openSampleWorkbook(testFileComplex); // Save and re-load them, to check for stability across that @@ -84,13 +87,10 @@ public class TestThemesTable { workbooks.put("Re-Saved_" + testFileSimple, simpleRS); workbooks.put(testFileComplex, complex); workbooks.put("Re-Saved_" + testFileComplex, complexRS); - + // Sanity check - assertEquals(rgbExpected.length, rgbExpected.length); - - // For offline testing - boolean createFiles = false; - + assertEquals(12, rgbExpected.length); + // Check each workbook in turn, and verify that the colours // for the theme-applied cells in Column A are correct for (String whatWorkbook : workbooks.keySet()) { @@ -98,7 +98,7 @@ public class TestThemesTable { XSSFSheet sheet = workbook.getSheetAt(0); int startRN = 0; if (whatWorkbook.endsWith(testFileComplex)) startRN++; - + for (int rn=startRN; rn