]> source.dussan.org Git - poi.git/commitdiff
add unit test for Cell.getCellComment
authorJaven O'Neal <onealj@apache.org>
Fri, 17 Jun 2016 08:54:08 +0000 (08:54 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 17 Jun 2016 08:54:08 +0000 (08:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748813 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

index 2b579b3503050dc2e6f82636b00bd9366004500a..d701d7c58bca4453019d4ed1275eb61683e4308f 100644 (file)
@@ -979,4 +979,35 @@ public abstract class BaseTestCell {
         
         wb.close();
     }
+
+    @Test
+    public void getCellComment() throws IOException {
+        Workbook wb = _testDataProvider.createWorkbook();
+        Sheet sheet = wb.createSheet();
+        CreationHelper factory = wb.getCreationHelper();
+        Row row = sheet.createRow(0);
+        Cell cell = row.createCell(1);
+        
+        // cell does not have a comment
+        assertNull(cell.getCellComment());
+        // add a cell comment
+        ClientAnchor anchor = factory.createClientAnchor();
+        anchor.setCol1(cell.getColumnIndex());
+        anchor.setCol2(cell.getColumnIndex()+1);
+        anchor.setRow1(row.getRowNum());
+        anchor.setRow2(row.getRowNum()+3);
+
+        Drawing drawing = sheet.createDrawingPatriarch();
+        Comment comment = drawing.createCellComment(anchor);
+        RichTextString str = factory.createRichTextString("Hello, World!");
+        comment.setString(str);
+
+        comment.setAuthor("Apache POI");
+        cell.setCellComment(comment);
+        // ideally assertSame, but XSSFCell creates a new XSSFCellComment wrapping the same bean for every call to getCellComment.
+        assertEquals(comment, cell.getCellComment());
+
+        wb.close();
+    }
 }