diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-11-21 12:42:03 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-11-21 12:42:03 +0000 |
commit | 5267b055eba091fc87204bf3037bf23e351553f3 (patch) | |
tree | 40e2eab7f18e2c5d55ff52fff8542ba9a8f40f81 | |
parent | 30fb580612ec5e2dbeffbe4fcf8f35511be3001f (diff) | |
download | poi-5267b055eba091fc87204bf3037bf23e351553f3.tar.gz poi-5267b055eba091fc87204bf3037bf23e351553f3.zip |
add comment tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895229 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFComment.java | 67 |
1 files changed, 66 insertions, 1 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 44b663ce68..a44d8f6a50 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 @@ -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.UUID; import com.microsoft.schemas.vml.CTShape; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; @@ -46,13 +47,16 @@ import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.Comments; import org.apache.poi.xssf.model.CommentsTable; +import org.apache.poi.xssf.streaming.SXSSFCell; +import org.apache.poi.xssf.streaming.SXSSFRow; +import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.xmlbeans.XmlObject; import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; -public final class TestXSSFComment extends BaseTestCellComment { +public final class TestXSSFComment extends BaseTestCellComment { private static final String TEST_RICHTEXTSTRING = "test richtextstring"; @@ -351,4 +355,65 @@ public final class TestXSSFComment extends BaseTestCellComment { } } } + + @Test + void testMoveComment() throws Exception { + CommentsTable commentsTable = new CommentsTable(); + try (SXSSFWorkbook workbook = new SXSSFWorkbook()) { + CreationHelper factory = workbook.getCreationHelper(); + SXSSFSheet sheet = workbook.createSheet(); + SXSSFRow row = sheet.createRow(0); + SXSSFCell cell = row.createCell(0); + ClientAnchor anchor = factory.createClientAnchor(); + anchor.setCol1(0); + anchor.setCol2(1); + anchor.setRow1(row.getRowNum()); + anchor.setRow2(row.getRowNum()); + XSSFComment comment = commentsTable.createNewComment(sheet, anchor); + String uniqueText = UUID.randomUUID().toString(); + comment.setString(uniqueText); + comment.setAuthor("author" + uniqueText); + + XSSFComment comment1 = commentsTable.findCellComment(new CellAddress("A1")); + assertEquals(comment.getString().getString(), comment1.getString().getString()); + + comment.setAddress(1, 1); + assertNull(commentsTable.findCellComment(new CellAddress("A1")), + "no longer a comment on cell A1?"); + + XSSFComment comment2 = commentsTable.findCellComment(new CellAddress("B2")); + assertEquals(comment.getString().getString(), comment2.getString().getString()); + } + } + + @Test + void testMoveCommentCopy() throws Exception { + CommentsTable commentsTable = new CommentsTable(); + try (SXSSFWorkbook workbook = new SXSSFWorkbook()) { + CreationHelper factory = workbook.getCreationHelper(); + SXSSFSheet sheet = workbook.createSheet(); + SXSSFRow row = sheet.createRow(0); + SXSSFCell cell = row.createCell(0); + ClientAnchor anchor = factory.createClientAnchor(); + anchor.setCol1(0); + anchor.setCol2(1); + anchor.setRow1(row.getRowNum()); + anchor.setRow2(row.getRowNum()); + XSSFComment comment = commentsTable.createNewComment(sheet, anchor); + String uniqueText = UUID.randomUUID().toString(); + comment.setString(uniqueText); + comment.setAuthor("author" + uniqueText); + + XSSFComment comment1 = commentsTable.findCellComment(new CellAddress("A1")); + assertEquals(comment.getString().getString(), comment1.getString().getString()); + + //like testMoveComment but moves the copy of the comment (comment1) instead + comment1.setAddress(1, 1); + assertNull(commentsTable.findCellComment(new CellAddress("A1")), + "no longer a comment on cell A1?"); + + XSSFComment comment2 = commentsTable.findCellComment(new CellAddress("B2")); + assertEquals(comment.getString().getString(), comment2.getString().getString()); + } + } } |