From 720e866a4c83c6bbeefa640546b16390a3110d21 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 17 Jun 2016 08:54:08 +0000 Subject: [PATCH] add unit test for Cell.getCellComment git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748813 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/usermodel/BaseTestCell.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 2b579b350..d701d7c58 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -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(); + } }