]> source.dussan.org Git - poi.git/commitdiff
add comment tests
authorPJ Fanning <fanningpj@apache.org>
Sun, 21 Nov 2021 17:45:08 +0000 (17:45 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sun, 21 Nov 2021 17:45:08 +0000 (17:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895241 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java

index fdf29208d4eb1ef8a69518a0c1f0f523288b3701..28c73d7ba5a8c3752f55ea4f0aa3e87347966b6d 100644 (file)
@@ -33,15 +33,7 @@ import java.util.UUID;
 import com.microsoft.schemas.vml.CTShape;
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 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.IndexedColors;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.XSSFITestDataProvider;
@@ -387,6 +379,48 @@ public final class TestXSSFComment extends BaseTestCellComment {
         }
     }
 
+    @Test
+    void testMoveCommentIsSaved() throws Exception {
+        try (
+                UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+                XSSFWorkbook workbook = new XSSFWorkbook();
+        ) {
+            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);
+            String uniqueText = UUID.randomUUID().toString();
+            comment.setString(factory.createRichTextString(uniqueText));
+            comment.setAuthor("author" + uniqueText);
+            Comment comment1 = sheet.getCellComment(new CellAddress("A1"));
+            assertEquals(comment.getString().getString(), comment1.getString().getString());
+
+            comment.setAddress(1, 1);
+            Comment comment2 = sheet.getCellComment(new CellAddress("B2"));
+            assertEquals(comment.getString().getString(), comment2.getString().getString());
+            assertNull( sheet.getCellComment(new CellAddress("A1")), "comment still found on A1?");
+
+            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("B2", address0.formatAsString());
+            }
+        }
+    }
+
+
     private void _testMove(Workbook workbook) throws Exception {
         CommentsTable commentsTable = new CommentsTable();
         try {