source: josm/trunk/test/unit/org/openstreetmap/josm/gui/help/HyperlinkHandlerTest.java@ 17536

Last change on this file since 17536 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.help;
3
4import static org.junit.jupiter.api.Assertions.assertNotNull;
5
6import java.io.StringReader;
7
8import javax.swing.event.HyperlinkEvent;
9import javax.swing.text.Element;
10import javax.swing.text.html.HTMLDocument;
11import javax.swing.text.html.HTMLEditorKit;
12
13import org.junit.jupiter.api.extension.RegisterExtension;
14import org.junit.jupiter.api.Test;
15import org.openstreetmap.josm.gui.widgets.JosmEditorPane;
16import org.openstreetmap.josm.testutils.JOSMTestRules;
17
18import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19
20/**
21 * Unit tests of {@link HyperlinkHandler} class.
22 */
23class 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}
Note: See TracBrowser for help on using the repository browser.