add asserts to tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886070 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_1_0
@@ -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 |
@@ -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, " |
@@ -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); | |||
} | |||
} | |||
@@ -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")) { |
@@ -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()); | |||
} | |||
} | |||
} | |||
@@ -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 | |||
} |
@@ -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() { |
@@ -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() { |
@@ -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); | |||
} | |||
} | |||
@@ -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 |
@@ -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 |
@@ -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 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"); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} | |||
} | |||
} | |||