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

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

index 75e5b8f4042f6ed33fb2adf366d67cf9277417f0..fdf29208d4eb1ef8a69518a0c1f0f523288b3701 100644 (file)
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.IOException;
+import java.util.Map;
 import java.util.UUID;
 
 import com.microsoft.schemas.vml.CTShape;
@@ -358,13 +359,43 @@ public final class TestXSSFComment extends BaseTestCellComment {
 
     @Test
     void testMoveComment() throws Exception {
+        _testMove(new XSSFWorkbook());
+    }
+
+    @Test
+    void testMoveCommentSXSSF() throws Exception {
+        SXSSFWorkbook workbook = new SXSSFWorkbook();
+        try {
+            _testMove(workbook);
+        } finally {
+            workbook.dispose();
+        }
+    }
+
+    @Test
+    void testMoveCommentCopy() throws Exception {
+        _testMoveCopy(new XSSFWorkbook());
+    }
+
+    @Test
+    void testMoveCommentCopySXSSF() throws Exception {
+        SXSSFWorkbook workbook = new SXSSFWorkbook();
+        try {
+            _testMoveCopy(workbook);
+        } finally {
+            workbook.dispose();
+        }
+    }
+
+    private void _testMove(Workbook workbook) throws Exception {
         CommentsTable commentsTable = new CommentsTable();
-        try (SXSSFWorkbook workbook = new SXSSFWorkbook()) {
+        try {
             CreationHelper factory = workbook.getCreationHelper();
-            SXSSFSheet sheet = workbook.createSheet();
+            Sheet sheet = workbook.createSheet();
             commentsTable.setSheet(sheet);
-            SXSSFRow row = sheet.createRow(0);
-            SXSSFCell cell = row.createCell(0);
+            Row row = sheet.createRow(0);
+            Cell cell = row.createCell(0);
+            cell.setCellValue("CellA1");
             ClientAnchor anchor = factory.createClientAnchor();
             anchor.setCol1(0);
             anchor.setCol2(1);
@@ -384,18 +415,20 @@ public final class TestXSSFComment extends BaseTestCellComment {
 
             XSSFComment comment2 = commentsTable.findCellComment(new CellAddress("B2"));
             assertEquals(comment.getString().getString(), comment2.getString().getString());
+        } finally {
+            workbook.close();
         }
     }
 
-    @Test
-    void testMoveCommentCopy() throws Exception {
+    private void _testMoveCopy(Workbook workbook) throws Exception {
         CommentsTable commentsTable = new CommentsTable();
-        try (SXSSFWorkbook workbook = new SXSSFWorkbook()) {
+        try {
             CreationHelper factory = workbook.getCreationHelper();
-            SXSSFSheet sheet = workbook.createSheet();
+            Sheet sheet = workbook.createSheet();
             commentsTable.setSheet(sheet);
-            SXSSFRow row = sheet.createRow(0);
-            SXSSFCell cell = row.createCell(0);
+            Row row = sheet.createRow(0);
+            Cell cell = row.createCell(0);
+            cell.setCellValue("CellA1");
             ClientAnchor anchor = factory.createClientAnchor();
             anchor.setCol1(0);
             anchor.setCol2(1);
@@ -416,6 +449,8 @@ public final class TestXSSFComment extends BaseTestCellComment {
 
             XSSFComment comment2 = commentsTable.findCellComment(new CellAddress("B2"));
             assertEquals(comment.getString().getString(), comment2.getString().getString());
+        } finally {
+            workbook.close();
         }
     }
 }