pjfanning commented on code in PR #1601:
URL: https://github.com/apache/poi/pull/1601#discussion_r4727400461


##########
poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFHyperlink.java:
##########
@@ -195,26 +199,103 @@ void testImportContentKeepsShapeHyperlinks() throws 
IOException {
             XSLFPictureShape picture = slide1.createPicture(src.addPicture(new 
byte[]{1, 2, 3}, PictureType.PNG));
             picture.createHyperlink().linkToEmail("[email protected]");
 
+            // the slide link refers to the second slide by its part name, so 
the target deck has one too
+            XSLFSlide target = dst.createSlide();
+            dst.createSlide();
+            target.importContent(slide1);
+            assertShapeHyperlinks(target.getShapes(), 
slide2.getPackagePart().getPartName().getName());
+
+            try (XMLSlideShow read = 
XSLFTestDataSamples.writeOutAndReadBack(dst)) {
+                assertShapeHyperlinks(read.getSlides().get(0).getShapes(), 
"/ppt/slides/slide2.xml");
+            }
+        }
+    }
+
+    private static void assertShapeHyperlinks(List<XSLFShape> shapes, String 
slidePartName) {
+        XSLFHyperlink url = ((XSLFAutoShape) shapes.get(0)).getHyperlink();
+        assertEquals(HyperlinkType.URL, url.getType());
+        assertEquals("https://poi.apache.org/";, url.getAddress());
+
+        XSLFHyperlink toSlide = ((XSLFAutoShape) shapes.get(1)).getHyperlink();
+        assertEquals(HyperlinkType.DOCUMENT, toSlide.getType());
+        assertEquals(slidePartName, toSlide.getAddress());
+
+        XSLFHyperlink next = ((XSLFAutoShape) shapes.get(2)).getHyperlink();
+        assertEquals(HyperlinkType.DOCUMENT, next.getType());
+        assertEquals("ppaction://hlinkshowjump?jump=nextslide", 
next.getXmlObject().getAction());
+
+        XSLFPictureShape pictureCopy = (XSLFPictureShape) shapes.get(3);
+        XSLFHyperlink email = pictureCopy.getHyperlink();
+        assertEquals(HyperlinkType.EMAIL, email.getType());
+        assertEquals("mailto:[email protected]";, email.getAddress());
+        assertArrayEquals(new byte[]{1, 2, 3}, 
pictureCopy.getPictureData().getData());
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {"ppaction://media", 
"ppaction://macro?name=Module1.Show Total", "ppaction://noaction", ""})
+    void testImportContentKeepsShapeActionsWithoutRelation(String action) 
throws IOException, InvalidFormatException {
+        try (XMLSlideShow src = new XMLSlideShow(); XMLSlideShow dst = new 
XMLSlideShow()) {
+            XSLFSlide slide1 = src.createSlide();
+            XSLFAutoShape shape = slide1.createAutoShape();
+            CTHyperlink link = shape.getCNvPr().addNewHlinkClick();
+            link.setId("");
+            if (!action.isEmpty()) {
+                link.setAction(action);
+            }
+
             XSLFSlide copy = dst.createSlide().importContent(slide1);
-            List<XSLFShape> shapes = copy.getShapes();
+            assertActionWithoutRelation(copy, action);
+            try (XMLSlideShow read = 
XSLFTestDataSamples.writeOutAndReadBack(dst)) {
+                assertActionWithoutRelation(read.getSlides().get(0), action);
+            }
+        }
+    }
 
-            XSLFHyperlink url = ((XSLFAutoShape) shapes.get(0)).getHyperlink();
-            assertEquals(HyperlinkType.URL, url.getType());
-            assertEquals("https://poi.apache.org/";, url.getAddress());
+    private static void assertActionWithoutRelation(XSLFSlide slide, String 
action) throws InvalidFormatException {
+        CTHyperlink link = ((XSLFAutoShape) 
slide.getShapes().get(0)).getHyperlink().getXmlObject();
+        assertEquals("", link.getId());
+        if (action.isEmpty()) {
+            assertFalse(link.isSetAction());

Review Comment:
   always provide an error text with assertTrue and assertFalse - an overloaded 
method exists that accepts a message to output if the assertion fails



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to