• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.37
/src/main/java/com/meterware/httpunit/WebLink.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit;
21

22
import com.meterware.httpunit.dom.HTMLElementImpl;
23
import com.meterware.httpunit.scripting.NamedDelegate;
24
import com.meterware.httpunit.scripting.ScriptableDelegate;
25

26
import java.io.IOException;
27
import java.net.MalformedURLException;
28
import java.net.URL;
29

30
import org.w3c.dom.Node;
31
import org.xml.sax.SAXException;
32

33
/**
34
 * This class represents a link in an HTML page. Users of this class may examine the structure of the link (as a DOM),
35
 * or create a {@link WebRequest} to simulate clicking on the link.
36
 **/
37
public class WebLink extends FixedURLWebRequestSource {
38

39
    /** Predicate to match part or all of a link's URL string. **/
40
    public static final HTMLElementPredicate MATCH_URL_STRING;
41

42
    /** Predicate to match a link's text exactly. **/
43
    public static final HTMLElementPredicate MATCH_TEXT;
44

45
    /** Predicate to match part or all of a link's contained text. **/
46
    public static final HTMLElementPredicate MATCH_CONTAINED_TEXT;
47

48
    /** Predicate to match a link's ID. **/
49
    public static final HTMLElementPredicate MATCH_ID;
50

51
    /** Predicate to match a link's name. **/
52
    public static final HTMLElementPredicate MATCH_NAME;
53

54
    /**
55
     * Returns the URL referenced by this link. This may be a relative URL. It will not include any fragment identifier.
56
     **/
57
    public String getURLString() {
58
        return getRelativeURL();
1✔
59
    }
60

61
    /**
62
     * Returns the text value of this link.
63
     **/
64
    @Override
65
    public String getText() {
66
        if (getElement().getNodeName().equalsIgnoreCase("area")) {
1✔
67
            return getAttribute("alt");
1✔
68
        }
69
        return super.getText();
1✔
70
    }
71

72
    /**
73
     * Returns the text value of this link.
74
     *
75
     * @deprecated as of 1.6, use #getText instead
76
     **/
77
    @Deprecated
78
    public String asText() {
79
        return getText();
×
80
    }
81

82
    /**
83
     * Submits a request as though the user had clicked on this link. Will also fire the 'onClick', 'onMouseDown' and
84
     * 'onMouseUp' event if defined. Returns the updated contents of the frame containing the link. Note that if the
85
     * click updates a different frame, that frame will not be returned by this method.
86
     **/
87
    public WebResponse click() throws IOException, SAXException {
88
        if (handleEvent("onclick")) {
1✔
89
            ((HTMLElementImpl) getNode()).doClickAction();
1✔
90
        }
91
        return getCurrentFrameContents();
1✔
92
    }
93

94
    /**
95
     * Simulates moving the mouse over the link. Will fire the 'onMouseOver' event if defined.
96
     **/
97
    public void mouseOver() {
98
        handleEvent("onmouseover");
1✔
99
    }
1✔
100

101
    public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
102

103
        public Scriptable() {
1✔
104
            super(WebLink.this);
1✔
105
        }
1✔
106

107
        @Override
108
        public String getName() {
109
            return WebLink.this.getID().length() != 0 ? WebLink.this.getID() : WebLink.this.getName();
1✔
110
        }
111

112
        @Override
113
        public Object get(String propertyName) {
114
            if (propertyName.equalsIgnoreCase("href")) {
1✔
115
                return getReference().toExternalForm();
1✔
116
            }
117
            return super.get(propertyName);
1✔
118
        }
119

120
        @Override
121
        public void set(String propertyName, Object value) {
122
            if (propertyName.equals("href")) {
1!
123
                setDestination((String) value);
1✔
124
            } else {
125
                super.set(propertyName, value);
×
126
            }
127
        }
1✔
128

129
        private URL getReference() {
130
            try {
131
                return getRequest().getURL();
1✔
132
            } catch (MalformedURLException e) {
×
133
                return WebLink.this.getBaseURL();
×
134
            }
135
        }
136
    }
137

138
    // ----------------------------------------- WebRequestSource methods
139
    // ---------------------------------------------------
140

141
    @Override
142
    public ScriptableDelegate newScriptable() {
143
        return new Scriptable();
1✔
144
    }
145

146
    // --------------------------------------------------- package members
147
    // --------------------------------------------------
148

149
    /**
150
     * Contructs a web link given the URL of its source page and the DOM extracted from that page.
151
     **/
152
    WebLink(WebResponse response, URL baseURL, Node node, FrameSelector sourceFrame, String defaultTarget,
153
            String characterSet) {
154
        super(response, node, baseURL, "href", sourceFrame, defaultTarget, characterSet);
1✔
155
    }
1✔
156

157
    static {
158
        MATCH_URL_STRING = (htmlElement, criteria) -> HttpUnitUtils.contains(((WebLink) htmlElement).getURLString(),
1✔
159
                (String) criteria);
160

161
        MATCH_TEXT = (htmlElement, criteria) -> HttpUnitUtils.matches(((WebLink) htmlElement).getText(),
1✔
162
                (String) criteria);
163

164
        MATCH_CONTAINED_TEXT = (htmlElement, criteria) -> HttpUnitUtils.contains(((WebLink) htmlElement).getText(),
1✔
165
                (String) criteria);
166

167
        MATCH_ID = (htmlElement, criteria) -> HttpUnitUtils.matches(((WebLink) htmlElement).getID(), (String) criteria);
1✔
168

169
        MATCH_NAME = (htmlElement, criteria) -> HttpUnitUtils.matches(((WebLink) htmlElement).getName(),
1✔
170
                (String) criteria);
171

172
    }
1✔
173

174
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc