aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2021-01-30 22:58:14 +0000
committerAndreas Beeker <kiwiwings@apache.org>2021-01-30 22:58:14 +0000
commitaa9ec651ea09abf21612ff768bd7b2b555087430 (patch)
tree8730f105e72a04d58658c9720d8b725ab20e0553 /src
parentcaf2d32393f6179673a615e9f0db5ef06956654e (diff)
downloadpoi-aa9ec651ea09abf21612ff768bd7b2b555087430.tar.gz
poi-aa9ec651ea09abf21612ff768bd7b2b555087430.zip
Sonar fixes
add asserts to tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886070 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java3
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java17
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java3
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java51
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java25
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java11
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/dev/TestReSave.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java4
-rw-r--r--src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java42
-rw-r--r--src/testcases/org/apache/poi/ss/format/TestCellFormat.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java37
-rw-r--r--src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java35
-rw-r--r--src/testcases/org/apache/poi/ss/formula/udf/TestUDFFinder.java (renamed from src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java)42
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java112
15 files changed, 157 insertions, 235 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java b/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java
index 3c689093e6..753e2046d2 100644
--- a/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java
+++ b/src/ooxml/testcases/org/apache/poi/ss/tests/formula/functions/TestVlookup.java
@@ -33,10 +33,13 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
/**
* Test the VLOOKUP function
*/
+@Execution(ExecutionMode.CONCURRENT)
class TestVlookup {
@Test
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
index 7789dc6a40..e065b26adb 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
@@ -345,17 +345,16 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
wb2.close();
}
- @Disabled("currently writing the same sheet multiple times is not supported...")
@Test
void bug53515() throws Exception {
- Workbook wb1 = new SXSSFWorkbook(10);
- populateWorkbook(wb1);
- saveTwice(wb1);
- Workbook wb2 = new XSSFWorkbook();
- populateWorkbook(wb2);
- saveTwice(wb2);
- wb2.close();
- wb1.close();
+ try (Workbook wb1 = new SXSSFWorkbook(10)) {
+ populateWorkbook(wb1);
+ saveTwice(wb1);
+ try (Workbook wb2 = new XSSFWorkbook()) {
+ populateWorkbook(wb2);
+ saveTwice(wb2);
+ }
+ }
}
@Disabled("Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files, "
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
index aed0763f81..4c9baa3a04 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
@@ -17,6 +17,7 @@
package org.apache.poi.xssf.usermodel;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -369,7 +370,7 @@ public final class TestUnfixedBugs {
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
formulaEvaluator.setIgnoreMissingWorkbooks(true);
- formulaEvaluator.evaluateAll();
+ assertDoesNotThrow(formulaEvaluator::evaluateAll);
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
index 5d9a74e27a..aea85b4cc1 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java
@@ -25,21 +25,17 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
+import com.microsoft.schemas.vml.CTShape;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.ss.usermodel.BaseTestCellComment;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.CreationHelper;
-import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -50,13 +46,10 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.xmlbeans.XmlObject;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
-import com.microsoft.schemas.vml.CTShape;
-
public final class TestXSSFComment extends BaseTestCellComment {
private static final String TEST_RICHTEXTSTRING = "test richtextstring";
@@ -262,48 +255,6 @@ public final class TestXSSFComment extends BaseTestCellComment {
}
}
- @Disabled("Used for manual testing with opening the resulting Workbook in Excel")
- @Test
- void testBug58175a() throws IOException {
- try (Workbook wb = new SXSSFWorkbook()) {
- Sheet sheet = wb.createSheet();
-
- Row row = sheet.createRow(1);
- Cell cell = row.createCell(3);
-
- cell.setCellValue("F4");
-
- Drawing<?> drawing = sheet.createDrawingPatriarch();
-
- CreationHelper factory = wb.getCreationHelper();
-
- // When the comment box is visible, have it show in a 1x3 space
- ClientAnchor anchor = factory.createClientAnchor();
- anchor.setCol1(cell.getColumnIndex());
- anchor.setCol2(cell.getColumnIndex() + 1);
- anchor.setRow1(row.getRowNum());
- anchor.setRow2(row.getRowNum() + 3);
-
- // Create the comment and set the text+author
- Comment comment = drawing.createCellComment(anchor);
- RichTextString str = factory.createRichTextString("Hello, World!");
- comment.setString(str);
- comment.setAuthor("Apache POI");
-
- /* fixed the problem as well
- * comment.setColumn(cell.getColumnIndex());
- * comment.setRow(cell.getRowIndex());
- */
-
- // Assign the comment to the cell
- cell.setCellComment(comment);
-
- try (OutputStream out = new FileOutputStream("C:\\temp\\58175.xlsx")) {
- wb.write(out);
- }
- }
- }
-
@Test
void testBug55814() throws IOException {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("55814.xlsx")) {
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
index 6680e56be4..501d10e8ab 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
@@ -16,9 +16,21 @@
==================================================================== */
package org.apache.poi.xssf.usermodel;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
-import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.FontUnderline;
@@ -33,19 +45,16 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
-import java.awt.*;
-import java.io.IOException;
-import java.util.List;
-
-import static org.junit.jupiter.api.Assertions.*;
-
class TestXSSFDrawing {
@Test
void bug54803() throws Exception {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("bug54803.xlsx")) {
XSSFSheet sheet = wb.getSheetAt(0);
sheet.createDrawingPatriarch();
- XSSFTestDataSamples.writeOutAndReadBack(wb).close();
+ try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb)) {
+ XSSFSheet sheet2 = wb2.getSheetAt(0);
+ assertNotNull(sheet2.getDrawingPatriarch());
+ }
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java
index 446a597253..f0507e3590 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java
@@ -17,11 +17,16 @@
package org.apache.poi.xssf.usermodel;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import org.apache.poi.ss.usermodel.PageOrder;
import org.apache.poi.ss.usermodel.PaperSize;
import org.apache.poi.ss.usermodel.PrintCellComments;
import org.apache.poi.ss.usermodel.PrintOrientation;
import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup;
@@ -30,10 +35,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
/**
* Tests for {@link XSSFPrintSetup}
*/
@@ -290,7 +291,7 @@ class TestXSSFPrintSetup {
* Open a file with print settings, save and check.
* Then, change, save, read, check
*/
- @Test
+ @Disabled
void testRoundTrip() {
// TODO
}
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
index 2778027760..7c6cf1b1f5 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
@@ -28,7 +28,10 @@ import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.NullOutputStream;
import org.apache.poi.util.RecordFormatException;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
+@Execution(ExecutionMode.CONCURRENT)
class TestBiffViewer extends BaseTestIteratingXLS {
@BeforeAll
public static void setup() {
diff --git a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
index a22b9412de..063e561ba3 100644
--- a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
+++ b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java
@@ -30,7 +30,10 @@ import org.apache.poi.util.RecordFormatException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Execution;
+import org.junit.jupiter.api.parallel.ExecutionMode;
+@Execution(ExecutionMode.CONCURRENT)
class TestReSave extends BaseTestIteratingXLS {
@BeforeAll
public static void setup() {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
index 98b32575c8..b2a793f972 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
@@ -38,6 +39,7 @@ import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
final class TestHSSFPicture extends BaseTestPicture {
@@ -61,7 +63,7 @@ final class TestHSSFPicture extends BaseTestPicture {
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("45829.png");
int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
HSSFPicture pic = p1.createPicture(new HSSFClientAnchor(), idx1);
- pic.resize();
+ assertDoesNotThrow((Executable) pic::resize);
}
}
diff --git a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
index 58e146c997..1fa1802bea 100644
--- a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
+++ b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
@@ -16,29 +16,29 @@
==================================================================== */
package org.apache.poi.poifs.dev;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
+import java.security.Permission;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.property.PropertyTable;
+import org.apache.poi.util.NullPrintStream;
import org.apache.poi.util.TempFile;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class TestPOIFSDump {
@@ -47,12 +47,7 @@ public class TestPOIFSDump {
@BeforeAll
public static void setUp() throws UnsupportedEncodingException {
SYSTEM = System.out;
- System.setOut(new PrintStream(new OutputStream() {
- @Override
- public void write(int b) {
-
- }
- }, false, "UTF-8"));
+ System.setOut(new NullPrintStream());
}
@AfterAll
@@ -137,15 +132,10 @@ public class TestPOIFSDump {
@Test
void testMain() throws Exception {
- POIFSDump.main(new String[] {
- TEST_FILE
- });
+ POIFSDump.main(new String[]{TEST_FILE});
for(String option : DUMP_OPTIONS) {
- POIFSDump.main(new String[]{
- option,
- TEST_FILE
- });
+ assertDoesNotThrow(() -> POIFSDump.main(new String[]{option, TEST_FILE}));
}
}
@Test
@@ -159,10 +149,26 @@ public class TestPOIFSDump {
}
}
- @Disabled("Calls System.exit()")
@Test
void testMainNoArgs() throws Exception {
- POIFSDump.main(new String[] {});
+ SecurityManager sm = System.getSecurityManager();
+ try {
+ System.setSecurityManager(new SecurityManager() {
+ @Override
+ public void checkExit(int status) {
+ throw new SecurityException();
+ }
+
+ @Override
+ public void checkPermission(Permission perm) {
+ // Allow other activities by default
+ }
+ });
+
+ assertThrows(SecurityException.class, () -> POIFSDump.main(new String[]{}));
+ } finally {
+ System.setSecurityManager(sm);
+ }
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/format/TestCellFormat.java b/src/testcases/org/apache/poi/ss/format/TestCellFormat.java
index 2c8da04394..3c0476a9c3 100644
--- a/src/testcases/org/apache/poi/ss/format/TestCellFormat.java
+++ b/src/testcases/org/apache/poi/ss/format/TestCellFormat.java
@@ -73,9 +73,9 @@ class TestCellFormat {
@Test
void testSome() {
JLabel l = new JLabel();
- CellFormat fmt = CellFormat.getInstance(
- "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)");
+ CellFormat fmt = CellFormat.getInstance("\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)");
fmt.apply(l, 1.1);
+ assertEquals("$1.10 ", l.getText());
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java b/src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java
deleted file mode 100644
index 02a6886be0..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/udf/TestAggregatingUDFFinder.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.ss.formula.udf;
-
-import org.apache.poi.ss.formula.atp.AnalysisToolPak;
-import org.junit.jupiter.api.Test;
-
-class TestAggregatingUDFFinder extends BaseTestUDFFinder {
-
- public TestAggregatingUDFFinder() {
- _instance = new AggregatingUDFFinder(AnalysisToolPak.instance);
- }
-
- @Test
- void findFunction() {
- confirmFindFunction("BESSELJ");
- }
-
- @Test
- void add() {
- ((AggregatingUDFFinder)_instance).add(AnalysisToolPak.instance);
- }
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java b/src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java
deleted file mode 100644
index daa9ffedbb..0000000000
--- a/src/testcases/org/apache/poi/ss/formula/udf/TestDefaultUDFFinder.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.ss.formula.udf;
-
-import org.apache.poi.ss.formula.functions.FreeRefFunction;
-import org.junit.jupiter.api.Test;
-
-class TestDefaultUDFFinder extends BaseTestUDFFinder {
-
- public TestDefaultUDFFinder() {
- _instance = new DefaultUDFFinder(
- new String[] { "NotImplemented" },
- new FreeRefFunction[] { NotImplemented }
- );
- }
-
- @Test
- void findFunction() {
- confirmFindFunction("NotImplemented");
- }
-}
diff --git a/src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java b/src/testcases/org/apache/poi/ss/formula/udf/TestUDFFinder.java
index 207e196ae3..9628c0af97 100644
--- a/src/testcases/org/apache/poi/ss/formula/udf/BaseTestUDFFinder.java
+++ b/src/testcases/org/apache/poi/ss/formula/udf/TestUDFFinder.java
@@ -18,23 +18,41 @@ package org.apache.poi.ss.formula.udf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import java.util.stream.Stream;
+
import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.atp.AnalysisToolPak;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class TestUDFFinder {
+ public static Stream<Arguments> instances() {
+ UDFFinder notImplFinder = new DefaultUDFFinder(
+ new String[] { "NotImplemented" },
+ new FreeRefFunction[] { TestUDFFinder::notImplemented }
+ );
+
+ AggregatingUDFFinder aggUDF = new AggregatingUDFFinder(notImplFinder);
+ aggUDF.add(AnalysisToolPak.instance);
+
+ return Stream.of(
+ Arguments.of("NotImplemented", notImplFinder),
+ Arguments.of("BESSELJ", new AggregatingUDFFinder(AnalysisToolPak.instance)),
+ Arguments.of("BESSELJ", aggUDF)
+ );
+ }
-public class BaseTestUDFFinder {
-
- protected UDFFinder _instance;
- protected static final FreeRefFunction NotImplemented = new FreeRefFunction() {
- @Override
- public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
- throw new RuntimeException("not implemented");
- }
- };
-
- protected void confirmFindFunction(String name) {
- FreeRefFunction func = _instance.findFunction(name);
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("instances")
+ void confirmFindFunction(String functionName, UDFFinder instance) {
+ FreeRefFunction func = instance.findFunction(functionName);
assertNotNull(func);
}
+ private static ValueEval notImplemented(ValueEval[] args, OperationEvaluationContext ec) {
+ throw new RuntimeException("not implemented");
+ }
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
index d5881c2a05..c79abea7dc 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
@@ -42,6 +42,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaParseException;
+import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.ss.util.PaneInformation;
@@ -1012,18 +1013,18 @@ public abstract class BaseTestBugzillaIssues {
Name name1 = wb.createName();
name1.setNameName("FMLA");
- name1.setRefersToFormula("Sheet1!$B$3");
+ assertDoesNotThrow(() -> name1.setRefersToFormula("Sheet1!$B$3"));
}
}
@Test
void bug56981() throws IOException {
- try (Workbook wb = _testDataProvider.createWorkbook()) {
- CellStyle vertTop = wb.createCellStyle();
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
+ CellStyle vertTop = wb1.createCellStyle();
vertTop.setVerticalAlignment(VerticalAlignment.TOP);
- CellStyle vertBottom = wb.createCellStyle();
+ CellStyle vertBottom = wb1.createCellStyle();
vertBottom.setVerticalAlignment(VerticalAlignment.BOTTOM);
- Sheet sheet = wb.createSheet("Sheet 1");
+ Sheet sheet = wb1.createSheet("Sheet 1");
Row row = sheet.createRow(0);
Cell top = row.createCell(0);
Cell bottom = row.createCell(1);
@@ -1033,64 +1034,61 @@ public abstract class BaseTestBugzillaIssues {
bottom.setCellValue("Bottom");
bottom.setCellStyle(vertBottom);
row.setHeightInPoints(85.75f); // make it obvious
+
+ try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
+ Cell cell = wb2.getSheetAt(0).getRow(0).getCell(1);
+ assertEquals(VerticalAlignment.BOTTOM, cell.getCellStyle().getVerticalAlignment());
+ }
}
}
@Test
void test57973() throws IOException {
- try (Workbook wb = _testDataProvider.createWorkbook()) {
-
- CreationHelper factory = wb.getCreationHelper();
-
- Sheet sheet = wb.createSheet();
- Drawing<?> drawing = sheet.createDrawingPatriarch();
- ClientAnchor anchor = factory.createClientAnchor();
-
- Cell cell0 = sheet.createRow(0).createCell(0);
- cell0.setCellValue("Cell0");
-
- Comment comment0 = drawing.createCellComment(anchor);
- RichTextString str0 = factory.createRichTextString("Hello, World1!");
- comment0.setString(str0);
- comment0.setAuthor("Apache POI");
- cell0.setCellComment(comment0);
-
- anchor = factory.createClientAnchor();
- anchor.setCol1(1);
- anchor.setCol2(1);
- anchor.setRow1(1);
- anchor.setRow2(1);
- Cell cell1 = sheet.createRow(3).createCell(5);
- cell1.setCellValue("F4");
- Comment comment1 = drawing.createCellComment(anchor);
- RichTextString str1 = factory.createRichTextString("Hello, World2!");
- comment1.setString(str1);
- comment1.setAuthor("Apache POI");
- cell1.setCellComment(comment1);
-
- Cell cell2 = sheet.createRow(2).createCell(2);
- cell2.setCellValue("C3");
-
- anchor = factory.createClientAnchor();
- anchor.setCol1(2);
- anchor.setCol2(2);
- anchor.setRow1(2);
- anchor.setRow2(2);
+ String[] vals = { "Cell0", "F4", "C3" };
+ try (Workbook wb1 = _testDataProvider.createWorkbook()) {
+ CreationHelper helper1 = wb1.getCreationHelper();
+ Sheet sheet1 = wb1.createSheet();
+ Drawing<?> drawing1 = sheet1.createDrawingPatriarch();
+
+ for (int i=0; i< vals.length; i++) {
+ Cell cell = sheet1.createRow(i).createCell(i);
+ cell.setCellValue(vals[i]);
+ ClientAnchor anchor = helper1.createClientAnchor();
+ anchor.setCol1(i);
+ anchor.setCol2(i);
+ anchor.setRow1(i);
+ anchor.setRow2(i);
+
+ Comment comment = drawing1.createCellComment(anchor);
+ RichTextString str = helper1.createRichTextString("Hello, World"+i);
+ comment.setString(str);
+ comment.setAuthor("Apache POI");
+ cell.setCellComment(comment);
+ comment.setColumn(i);
+ comment.setRow(i);
+
+ //apply custom font to the text in the comment
+ Font font = wb1.createFont();
+ font.setFontName("Arial");
+ font.setFontHeightInPoints((short) (14+i));
+ font.setBold(true);
+ font.setColor(IndexedColors.RED.getIndex());
+ str.applyFont(font);
+ }
- Comment comment2 = drawing.createCellComment(anchor);
- RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
- //apply custom font to the text in the comment
- Font font = wb.createFont();
- font.setFontName("Arial");
- font.setFontHeightInPoints((short) 14);
- font.setBold(true);
- font.setColor(IndexedColors.RED.getIndex());
- str2.applyFont(font);
-
- comment2.setString(str2);
- comment2.setAuthor("Apache POI");
- comment2.setColumn(2);
- comment2.setRow(2);
+ try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
+ Sheet sheet2 = wb2.getSheetAt(0);
+
+ for (int i=0; i<vals.length; i++) {
+ Cell cell = sheet2.getRow(i).getCell(i);
+ assertEquals(vals[i], cell.getStringCellValue());
+ CellAddress cr = new CellAddress(cell);
+ Comment comment = sheet2.getCellComment(cr);
+ assertEquals("Apache POI", comment.getAuthor());
+ RichTextString str = comment.getString();
+ assertEquals("Hello, World"+i, str.getString());
+ }
+ }
}
}