diff options
author | Javen O'Neal <onealj@apache.org> | 2015-11-02 09:40:49 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2015-11-02 09:40:49 +0000 |
commit | 4a727300a7a32ea70f570bc5d9fe6dcfe6aa4fae (patch) | |
tree | 5fd9040a951b1cf520c8f26c747978e1f4670d2b /src/testcases/org/apache | |
parent | d593be901fdee63fa88758228fba915daf6f2496 (diff) | |
download | poi-4a727300a7a32ea70f570bc5d9fe6dcfe6aa4fae.tar.gz poi-4a727300a7a32ea70f570bc5d9fe6dcfe6aa4fae.zip |
bug 58572: move getHyperlinkList() and getHyperlink(row, col) from XSSFSheet to Sheet
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711923 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r-- | src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java index 51148f8041..4be6de3a71 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestHyperlink.java @@ -18,6 +18,11 @@ package org.apache.poi.ss.usermodel; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotSame; + +import java.util.List; + import org.junit.Test; import org.apache.poi.ss.ITestDataProvider; @@ -91,4 +96,45 @@ public abstract class BaseTestHyperlink { link = sheet.getRow(3).getCell(0).getHyperlink(); assertEquals("'Target Sheet'!A1", link.getAddress()); } + + @Test + public void testClone() { + System.out.println("testClone"); + final Workbook wb = _testDataProvider.createWorkbook(); + final CreationHelper createHelper = wb.getCreationHelper(); + + final Sheet sheet = wb.createSheet("Hyperlinks"); + final Row row = sheet.createRow(0); + final Cell cell1, cell2; + final Hyperlink link1, link2; + + //URL + cell1 = row.createCell(0); + cell2 = row.createCell(1); + cell1.setCellValue("URL Link"); + link1 = createHelper.createHyperlink(Hyperlink.LINK_URL); + link1.setAddress("http://poi.apache.org/"); + cell1.setHyperlink(link1); + + link2 = link1.clone(); + + // Change address (type is not changeable) + link2.setAddress("http://apache.org/"); + cell2.setHyperlink(link2); + + // Make sure hyperlinks were deep-copied, and modifying one does not modify the other. + assertNotSame(link1, link2); + assertNotEquals(link1, link2); + assertEquals("http://poi.apache.org/", link1.getAddress()); + assertEquals("http://apache.org/", link2.getAddress()); + assertEquals(link1, cell1.getHyperlink()); + assertEquals(link2, cell2.getHyperlink()); + + // Make sure both hyperlinks were added to the sheet + @SuppressWarnings("unchecked") + final List<Hyperlink> actualHyperlinks = (List<Hyperlink>) sheet.getHyperlinkList(); + assertEquals(2, actualHyperlinks.size()); + assertEquals(link1, actualHyperlinks.get(0)); + assertEquals(link2, actualHyperlinks.get(1)); + } } |