mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Sonar fixes
add asserts to tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886070 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
caf2d32393
commit
aa9ec651ea
@ -33,10 +33,13 @@ import org.apache.poi.ss.usermodel.Workbook;
|
|||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.parallel.Execution;
|
||||||
|
import org.junit.jupiter.api.parallel.ExecutionMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the VLOOKUP function
|
* Test the VLOOKUP function
|
||||||
*/
|
*/
|
||||||
|
@Execution(ExecutionMode.CONCURRENT)
|
||||||
class TestVlookup {
|
class TestVlookup {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -345,17 +345,16 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
|
|||||||
wb2.close();
|
wb2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("currently writing the same sheet multiple times is not supported...")
|
|
||||||
@Test
|
@Test
|
||||||
void bug53515() throws Exception {
|
void bug53515() throws Exception {
|
||||||
Workbook wb1 = new SXSSFWorkbook(10);
|
try (Workbook wb1 = new SXSSFWorkbook(10)) {
|
||||||
populateWorkbook(wb1);
|
populateWorkbook(wb1);
|
||||||
saveTwice(wb1);
|
saveTwice(wb1);
|
||||||
Workbook wb2 = new XSSFWorkbook();
|
try (Workbook wb2 = new XSSFWorkbook()) {
|
||||||
populateWorkbook(wb2);
|
populateWorkbook(wb2);
|
||||||
saveTwice(wb2);
|
saveTwice(wb2);
|
||||||
wb2.close();
|
}
|
||||||
wb1.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files, "
|
@Disabled("Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files, "
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
@ -369,7 +370,7 @@ public final class TestUnfixedBugs {
|
|||||||
|
|
||||||
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||||
formulaEvaluator.setIgnoreMissingWorkbooks(true);
|
formulaEvaluator.setIgnoreMissingWorkbooks(true);
|
||||||
formulaEvaluator.evaluateAll();
|
assertDoesNotThrow(formulaEvaluator::evaluateAll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
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.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
|
import com.microsoft.schemas.vml.CTShape;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||||
import org.apache.poi.ss.usermodel.BaseTestCellComment;
|
import org.apache.poi.ss.usermodel.BaseTestCellComment;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||||
import org.apache.poi.ss.usermodel.Comment;
|
import org.apache.poi.ss.usermodel.Comment;
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
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.IndexedColors;
|
||||||
import org.apache.poi.ss.usermodel.RichTextString;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
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.model.CommentsTable;
|
||||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
|
||||||
|
|
||||||
import com.microsoft.schemas.vml.CTShape;
|
|
||||||
|
|
||||||
public final class TestXSSFComment extends BaseTestCellComment {
|
public final class TestXSSFComment extends BaseTestCellComment {
|
||||||
|
|
||||||
private static final String TEST_RICHTEXTSTRING = "test richtextstring";
|
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
|
@Test
|
||||||
void testBug55814() throws IOException {
|
void testBug55814() throws IOException {
|
||||||
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("55814.xlsx")) {
|
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("55814.xlsx")) {
|
||||||
|
|||||||
@ -16,9 +16,21 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xssf.usermodel;
|
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;
|
||||||
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
|
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||||
import org.apache.poi.ss.usermodel.FontUnderline;
|
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.main.STTextUnderlineType;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
|
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 {
|
class TestXSSFDrawing {
|
||||||
@Test
|
@Test
|
||||||
void bug54803() throws Exception {
|
void bug54803() throws Exception {
|
||||||
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("bug54803.xlsx")) {
|
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("bug54803.xlsx")) {
|
||||||
XSSFSheet sheet = wb.getSheetAt(0);
|
XSSFSheet sheet = wb.getSheetAt(0);
|
||||||
sheet.createDrawingPatriarch();
|
sheet.createDrawingPatriarch();
|
||||||
XSSFTestDataSamples.writeOutAndReadBack(wb).close();
|
try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb)) {
|
||||||
|
XSSFSheet sheet2 = wb2.getSheetAt(0);
|
||||||
|
assertNotNull(sheet2.getDrawingPatriarch());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,11 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
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.PageOrder;
|
||||||
import org.apache.poi.ss.usermodel.PaperSize;
|
import org.apache.poi.ss.usermodel.PaperSize;
|
||||||
import org.apache.poi.ss.usermodel.PrintCellComments;
|
import org.apache.poi.ss.usermodel.PrintCellComments;
|
||||||
import org.apache.poi.ss.usermodel.PrintOrientation;
|
import org.apache.poi.ss.usermodel.PrintOrientation;
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup;
|
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.STOrientation;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
|
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}
|
* Tests for {@link XSSFPrintSetup}
|
||||||
*/
|
*/
|
||||||
@ -290,7 +291,7 @@ class TestXSSFPrintSetup {
|
|||||||
* Open a file with print settings, save and check.
|
* Open a file with print settings, save and check.
|
||||||
* Then, change, save, read, check
|
* Then, change, save, read, check
|
||||||
*/
|
*/
|
||||||
@Test
|
@Disabled
|
||||||
void testRoundTrip() {
|
void testRoundTrip() {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,10 @@ import org.apache.poi.util.LocaleUtil;
|
|||||||
import org.apache.poi.util.NullOutputStream;
|
import org.apache.poi.util.NullOutputStream;
|
||||||
import org.apache.poi.util.RecordFormatException;
|
import org.apache.poi.util.RecordFormatException;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
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 {
|
class TestBiffViewer extends BaseTestIteratingXLS {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
|
|||||||
@ -30,7 +30,10 @@ import org.apache.poi.util.RecordFormatException;
|
|||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
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 {
|
class TestReSave extends BaseTestIteratingXLS {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
|
|||||||
|
|
||||||
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
|
import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
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 static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.PictureData;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.function.Executable;
|
||||||
|
|
||||||
final class TestHSSFPicture extends BaseTestPicture {
|
final class TestHSSFPicture extends BaseTestPicture {
|
||||||
|
|
||||||
@ -61,7 +63,7 @@ final class TestHSSFPicture extends BaseTestPicture {
|
|||||||
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("45829.png");
|
byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("45829.png");
|
||||||
int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
|
int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
|
||||||
HSSFPicture pic = p1.createPicture(new HSSFClientAnchor(), idx1);
|
HSSFPicture pic = p1.createPicture(new HSSFClientAnchor(), idx1);
|
||||||
pic.resize();
|
assertDoesNotThrow((Executable) pic::resize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,29 +16,29 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.poifs.dev;
|
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.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.security.Permission;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
|
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
|
||||||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.poifs.property.PropertyTable;
|
import org.apache.poi.poifs.property.PropertyTable;
|
||||||
|
import org.apache.poi.util.NullPrintStream;
|
||||||
import org.apache.poi.util.TempFile;
|
import org.apache.poi.util.TempFile;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestPOIFSDump {
|
public class TestPOIFSDump {
|
||||||
@ -47,12 +47,7 @@ public class TestPOIFSDump {
|
|||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void setUp() throws UnsupportedEncodingException {
|
public static void setUp() throws UnsupportedEncodingException {
|
||||||
SYSTEM = System.out;
|
SYSTEM = System.out;
|
||||||
System.setOut(new PrintStream(new OutputStream() {
|
System.setOut(new NullPrintStream());
|
||||||
@Override
|
|
||||||
public void write(int b) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}, false, "UTF-8"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@ -137,15 +132,10 @@ public class TestPOIFSDump {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMain() throws Exception {
|
void testMain() throws Exception {
|
||||||
POIFSDump.main(new String[] {
|
POIFSDump.main(new String[]{TEST_FILE});
|
||||||
TEST_FILE
|
|
||||||
});
|
|
||||||
|
|
||||||
for(String option : DUMP_OPTIONS) {
|
for(String option : DUMP_OPTIONS) {
|
||||||
POIFSDump.main(new String[]{
|
assertDoesNotThrow(() -> POIFSDump.main(new String[]{option, TEST_FILE}));
|
||||||
option,
|
|
||||||
TEST_FILE
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@ -159,10 +149,26 @@ public class TestPOIFSDump {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("Calls System.exit()")
|
|
||||||
@Test
|
@Test
|
||||||
void testMainNoArgs() throws Exception {
|
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
|
@Test
|
||||||
|
|||||||
@ -73,9 +73,9 @@ class TestCellFormat {
|
|||||||
@Test
|
@Test
|
||||||
void testSome() {
|
void testSome() {
|
||||||
JLabel l = new JLabel();
|
JLabel l = new JLabel();
|
||||||
CellFormat fmt = CellFormat.getInstance(
|
CellFormat fmt = CellFormat.getInstance("\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)");
|
||||||
"\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)");
|
|
||||||
fmt.apply(l, 1.1);
|
fmt.apply(l, 1.1);
|
||||||
|
assertEquals("$1.10 ", l.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -18,23 +18,41 @@ package org.apache.poi.ss.formula.udf;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
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.OperationEvaluationContext;
|
||||||
|
import org.apache.poi.ss.formula.atp.AnalysisToolPak;
|
||||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||||
import org.apache.poi.ss.formula.functions.FreeRefFunction;
|
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 BaseTestUDFFinder {
|
public class TestUDFFinder {
|
||||||
|
public static Stream<Arguments> instances() {
|
||||||
|
UDFFinder notImplFinder = new DefaultUDFFinder(
|
||||||
|
new String[] { "NotImplemented" },
|
||||||
|
new FreeRefFunction[] { TestUDFFinder::notImplemented }
|
||||||
|
);
|
||||||
|
|
||||||
protected UDFFinder _instance;
|
AggregatingUDFFinder aggUDF = new AggregatingUDFFinder(notImplFinder);
|
||||||
protected static final FreeRefFunction NotImplemented = new FreeRefFunction() {
|
aggUDF.add(AnalysisToolPak.instance);
|
||||||
@Override
|
|
||||||
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
|
|
||||||
throw new RuntimeException("not implemented");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
protected void confirmFindFunction(String name) {
|
return Stream.of(
|
||||||
FreeRefFunction func = _instance.findFunction(name);
|
Arguments.of("NotImplemented", notImplFinder),
|
||||||
|
Arguments.of("BESSELJ", new AggregatingUDFFinder(AnalysisToolPak.instance)),
|
||||||
|
Arguments.of("BESSELJ", aggUDF)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest(name = "{0}")
|
||||||
|
@MethodSource("instances")
|
||||||
|
void confirmFindFunction(String functionName, UDFFinder instance) {
|
||||||
|
FreeRefFunction func = instance.findFunction(functionName);
|
||||||
assertNotNull(func);
|
assertNotNull(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ValueEval notImplemented(ValueEval[] args, OperationEvaluationContext ec) {
|
||||||
|
throw new RuntimeException("not implemented");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -42,6 +42,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.SpreadsheetVersion;
|
import org.apache.poi.ss.SpreadsheetVersion;
|
||||||
import org.apache.poi.ss.formula.FormulaParseException;
|
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.CellRangeAddress;
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
import org.apache.poi.ss.util.PaneInformation;
|
import org.apache.poi.ss.util.PaneInformation;
|
||||||
@ -1012,18 +1013,18 @@ public abstract class BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
Name name1 = wb.createName();
|
Name name1 = wb.createName();
|
||||||
name1.setNameName("FMLA");
|
name1.setNameName("FMLA");
|
||||||
name1.setRefersToFormula("Sheet1!$B$3");
|
assertDoesNotThrow(() -> name1.setRefersToFormula("Sheet1!$B$3"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void bug56981() throws IOException {
|
void bug56981() throws IOException {
|
||||||
try (Workbook wb = _testDataProvider.createWorkbook()) {
|
try (Workbook wb1 = _testDataProvider.createWorkbook()) {
|
||||||
CellStyle vertTop = wb.createCellStyle();
|
CellStyle vertTop = wb1.createCellStyle();
|
||||||
vertTop.setVerticalAlignment(VerticalAlignment.TOP);
|
vertTop.setVerticalAlignment(VerticalAlignment.TOP);
|
||||||
CellStyle vertBottom = wb.createCellStyle();
|
CellStyle vertBottom = wb1.createCellStyle();
|
||||||
vertBottom.setVerticalAlignment(VerticalAlignment.BOTTOM);
|
vertBottom.setVerticalAlignment(VerticalAlignment.BOTTOM);
|
||||||
Sheet sheet = wb.createSheet("Sheet 1");
|
Sheet sheet = wb1.createSheet("Sheet 1");
|
||||||
Row row = sheet.createRow(0);
|
Row row = sheet.createRow(0);
|
||||||
Cell top = row.createCell(0);
|
Cell top = row.createCell(0);
|
||||||
Cell bottom = row.createCell(1);
|
Cell bottom = row.createCell(1);
|
||||||
@ -1033,64 +1034,61 @@ public abstract class BaseTestBugzillaIssues {
|
|||||||
bottom.setCellValue("Bottom");
|
bottom.setCellValue("Bottom");
|
||||||
bottom.setCellStyle(vertBottom);
|
bottom.setCellStyle(vertBottom);
|
||||||
row.setHeightInPoints(85.75f); // make it obvious
|
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
|
@Test
|
||||||
void test57973() throws IOException {
|
void test57973() throws IOException {
|
||||||
try (Workbook wb = _testDataProvider.createWorkbook()) {
|
String[] vals = { "Cell0", "F4", "C3" };
|
||||||
|
try (Workbook wb1 = _testDataProvider.createWorkbook()) {
|
||||||
|
CreationHelper helper1 = wb1.getCreationHelper();
|
||||||
|
Sheet sheet1 = wb1.createSheet();
|
||||||
|
Drawing<?> drawing1 = sheet1.createDrawingPatriarch();
|
||||||
|
|
||||||
CreationHelper factory = wb.getCreationHelper();
|
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);
|
||||||
|
|
||||||
Sheet sheet = wb.createSheet();
|
Comment comment = drawing1.createCellComment(anchor);
|
||||||
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
RichTextString str = helper1.createRichTextString("Hello, World"+i);
|
||||||
ClientAnchor anchor = factory.createClientAnchor();
|
comment.setString(str);
|
||||||
|
comment.setAuthor("Apache POI");
|
||||||
|
cell.setCellComment(comment);
|
||||||
|
comment.setColumn(i);
|
||||||
|
comment.setRow(i);
|
||||||
|
|
||||||
Cell cell0 = sheet.createRow(0).createCell(0);
|
//apply custom font to the text in the comment
|
||||||
cell0.setCellValue("Cell0");
|
Font font = wb1.createFont();
|
||||||
|
font.setFontName("Arial");
|
||||||
|
font.setFontHeightInPoints((short) (14+i));
|
||||||
|
font.setBold(true);
|
||||||
|
font.setColor(IndexedColors.RED.getIndex());
|
||||||
|
str.applyFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
Comment comment0 = drawing.createCellComment(anchor);
|
try (Workbook wb2 = _testDataProvider.writeOutAndReadBack(wb1)) {
|
||||||
RichTextString str0 = factory.createRichTextString("Hello, World1!");
|
Sheet sheet2 = wb2.getSheetAt(0);
|
||||||
comment0.setString(str0);
|
|
||||||
comment0.setAuthor("Apache POI");
|
|
||||||
cell0.setCellComment(comment0);
|
|
||||||
|
|
||||||
anchor = factory.createClientAnchor();
|
for (int i=0; i<vals.length; i++) {
|
||||||
anchor.setCol1(1);
|
Cell cell = sheet2.getRow(i).getCell(i);
|
||||||
anchor.setCol2(1);
|
assertEquals(vals[i], cell.getStringCellValue());
|
||||||
anchor.setRow1(1);
|
CellAddress cr = new CellAddress(cell);
|
||||||
anchor.setRow2(1);
|
Comment comment = sheet2.getCellComment(cr);
|
||||||
Cell cell1 = sheet.createRow(3).createCell(5);
|
assertEquals("Apache POI", comment.getAuthor());
|
||||||
cell1.setCellValue("F4");
|
RichTextString str = comment.getString();
|
||||||
Comment comment1 = drawing.createCellComment(anchor);
|
assertEquals("Hello, World"+i, str.getString());
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user