1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.help;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
5 |
|
---|
6 | import java.io.StringReader;
|
---|
7 |
|
---|
8 | import javax.swing.event.HyperlinkEvent;
|
---|
9 | import javax.swing.text.Element;
|
---|
10 | import javax.swing.text.html.HTMLDocument;
|
---|
11 | import javax.swing.text.html.HTMLEditorKit;
|
---|
12 |
|
---|
13 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
14 | import org.junit.jupiter.api.Test;
|
---|
15 | import org.openstreetmap.josm.gui.widgets.JosmEditorPane;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link HyperlinkHandler} class.
|
---|
22 | */
|
---|
23 | class HyperlinkHandlerTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup tests
|
---|
27 | */
|
---|
28 | @RegisterExtension
|
---|
29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
30 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/17338">#17338</a>.
|
---|
34 | * @throws Exception if an error occurs
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | void testTicket17338() throws Exception {
|
---|
38 | JosmEditorPane help = new JosmEditorPane();
|
---|
39 | HTMLEditorKit htmlKit = new HTMLEditorKit();
|
---|
40 | HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
|
---|
41 | htmlKit.read(new StringReader("<a id=\"foo\" href=\"null#WrongAnchor\">bar</a>"), htmlDoc, 0);
|
---|
42 | Element element = htmlDoc.getElement("foo");
|
---|
43 | assertNotNull(element);
|
---|
44 | help.setDocument(htmlDoc);
|
---|
45 | new HyperlinkHandler(HelpBrowserTest.newHelpBrowser(), help)
|
---|
46 | .hyperlinkUpdate(new HyperlinkEvent(this, HyperlinkEvent.EventType.ACTIVATED, null, null, element));
|
---|
47 | }
|
---|
48 | }
|
---|