summaryrefslogtreecommitdiffstats
path: root/poi-ooxml
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-11-26 13:28:53 +0000
committerPJ Fanning <fanningpj@apache.org>2021-11-26 13:28:53 +0000
commitb2b8bee161d3caaf0c2aa660f38912277ed89584 (patch)
tree68fc4e646213c6b23e7e58d64d7c60fe1372fd22 /poi-ooxml
parent29b3ad25df2cf324d16e73c0ab8d76f1739f273b (diff)
downloadpoi-b2b8bee161d3caaf0c2aa660f38912277ed89584.tar.gz
poi-b2b8bee161d3caaf0c2aa660f38912277ed89584.zip
add test for comment modification
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895352 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java
index 76dfd8bc43..8a5a17ce2c 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java
@@ -391,6 +391,21 @@ public final class TestXSSFComment extends BaseTestCellComment {
}
}
+ @Test
+ void testModifiedCommentIsSaved() throws Exception {
+ _testModificationIsSaved(new XSSFWorkbook());
+ }
+
+ @Test
+ void testModifiedCommentIsSavedSXSSF() throws Exception {
+ SXSSFWorkbook workbook = new SXSSFWorkbook();
+ try {
+ _testModificationIsSaved(workbook);
+ } finally {
+ workbook.dispose();
+ }
+ }
+
private void _testMove(Workbook workbook) throws Exception {
CommentsTable commentsTable = new CommentsTable();
try {
@@ -494,4 +509,43 @@ public final class TestXSSFComment extends BaseTestCellComment {
}
}
}
+
+ private void _testModificationIsSaved(Workbook workbook) throws Exception {
+ try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ CreationHelper factory = workbook.getCreationHelper();
+ Sheet sheet = workbook.createSheet();
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+ cell.setCellValue("CellA1");
+ ClientAnchor anchor = factory.createClientAnchor();
+ anchor.setCol1(0);
+ anchor.setCol2(1);
+ anchor.setRow1(row.getRowNum());
+ anchor.setRow2(row.getRowNum());
+ Drawing drawing = sheet.createDrawingPatriarch();
+ Comment comment = drawing.createCellComment(anchor);
+ comment.setString(factory.createRichTextString("initText"));
+ comment.setAuthor("initAuthor");
+
+ String uniqueText = UUID.randomUUID().toString();
+ comment.setString(factory.createRichTextString(uniqueText));
+ comment.setAuthor("author" + uniqueText);
+
+ workbook.write(bos);
+
+ try (XSSFWorkbook workbook2 = new XSSFWorkbook(bos.toInputStream())) {
+ XSSFSheet wb2Sheet = workbook2.getSheetAt(0);
+ Map<CellAddress, XSSFComment> cellComments = wb2Sheet.getCellComments();
+ assertEquals(1, cellComments.size());
+ CellAddress address0 = (CellAddress) cellComments.keySet().toArray()[0];
+ assertEquals("A1", address0.formatAsString());
+ XSSFComment savedComment = cellComments.get(address0);
+ assertEquals(comment.getString().getString(), savedComment.getString().getString());
+ assertEquals(comment.getAuthor(), savedComment.getAuthor());
+ }
+ } finally {
+ workbook.close();
+ }
+ }
+
}