From 8c495d746e7ae644ac7172b264dcc74e062fae36 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 24 Jul 2021 14:22:08 +0000 Subject: [PATCH] add test case for copying a cell with hyperlink git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891778 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/TestXSSFRow.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java index 4e6899dfc2..3c913467a3 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java @@ -23,13 +23,9 @@ import static org.junit.jupiter.api.Assertions.assertSame; import java.io.IOException; +import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.ss.tests.usermodel.BaseTestXRow; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellCopyPolicy; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.RichTextString; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.junit.jupiter.api.Test; @@ -153,6 +149,27 @@ public final class TestXSSFRow extends BaseTestXRow { workbook.close(); } + @Test + void testCopyRowWithHyperlink() throws IOException { + final XSSFWorkbook workbook = new XSSFWorkbook(); + final Sheet srcSheet = workbook.createSheet("src"); + final XSSFSheet destSheet = workbook.createSheet("dest"); + Row srcRow = srcSheet.createRow(0); + Cell srcCell = srcRow.createCell(0); + Hyperlink srcHyperlink = new XSSFHyperlink(HyperlinkType.URL); + srcHyperlink.setAddress("https://poi.apache.org"); + srcCell.setHyperlink(srcHyperlink); + + final XSSFRow destRow = destSheet.createRow(0); + destRow.copyRowFrom(srcRow, new CellCopyPolicy()); + + Cell destCell = destRow.getCell(0); + assertEquals(srcCell.getHyperlink().getAddress(), destCell.getHyperlink().getAddress(), "cell hyperlink addresses match"); + assertEquals(srcCell.getHyperlink().getType(), destCell.getHyperlink().getType(), "cell hyperlink types match"); + + workbook.close(); + } + @Test void testCopyRowOverwritesExistingRow() throws IOException { final XSSFWorkbook workbook = new XSSFWorkbook();