aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
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/testcases/org/apache
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/testcases/org/apache')
-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
9 files changed, 120 insertions, 162 deletions
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());
+ }
+ }
}
}