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

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

0.81 hits per line

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

92.86
/src/main/java/com/meterware/httpunit/WebImage.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.scripting.NamedDelegate;
23
import com.meterware.httpunit.scripting.ScriptableDelegate;
24

25
import java.net.URL;
26

27
import org.w3c.dom.Node;
28
import org.w3c.dom.html.HTMLImageElement;
29

30
/**
31
 * Represents an image in an HTML document.
32
 **/
33
public class WebImage extends FixedURLWebRequestSource {
34

35
    /** The element. */
36
    private HTMLImageElement _element;
37

38
    /** The parsed HTML. */
39
    private ParsedHTML _parsedHTML;
40

41
    /**
42
     * Instantiates a new web image.
43
     *
44
     * @param response
45
     *            the response
46
     * @param parsedHTML
47
     *            the parsed HTML
48
     * @param baseURL
49
     *            the base URL
50
     * @param element
51
     *            the element
52
     * @param sourceFrame
53
     *            the source frame
54
     * @param defaultTarget
55
     *            the default target
56
     * @param characterSet
57
     *            the character set
58
     */
59
    WebImage(WebResponse response, ParsedHTML parsedHTML, URL baseURL, HTMLImageElement element,
60
            FrameSelector sourceFrame, String defaultTarget, String characterSet) {
61
        super(response, element, baseURL, "src", sourceFrame, defaultTarget, characterSet);
1✔
62
        _element = element;
1✔
63
        _parsedHTML = parsedHTML;
1✔
64
    }
1✔
65

66
    @Override
67
    public String getName() {
68
        return _element.getName();
1✔
69
    }
70

71
    /**
72
     * Gets the source.
73
     *
74
     * @return the source
75
     */
76
    public String getSource() {
77
        return _element.getSrc();
1✔
78
    }
79

80
    /**
81
     * Gets the alt text.
82
     *
83
     * @return the alt text
84
     */
85
    public String getAltText() {
86
        return _element.getAlt();
1✔
87
    }
88

89
    /**
90
     * Gets the link.
91
     *
92
     * @return the link
93
     */
94
    public WebLink getLink() {
95
        return _parsedHTML.getFirstMatchingLink((link, parentNode) -> {
1✔
96
            for (Node parent = (Node) parentNode; parent != null; parent = parent.getParentNode()) {
1✔
97
                if (parent.equals(((WebLink) link).getElement())) {
1✔
98
                    return true;
1✔
99
                }
100
            }
101
            return false;
1✔
102
        }, _element.getParentNode());
1✔
103
    }
104

105
    /**
106
     * The Class Scriptable.
107
     */
108
    public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
109

110
        /**
111
         * Instantiates a new scriptable.
112
         */
113
        public Scriptable() {
1✔
114
            super(WebImage.this);
1✔
115
        }
1✔
116

117
        @Override
118
        public String getName() {
119
            return WebImage.this.getID().length() != 0 ? WebImage.this.getID() : WebImage.this.getName();
1✔
120
        }
121

122
        @Override
123
        public Object get(String propertyName) {
124
            if (propertyName.equalsIgnoreCase("src")) {
1✔
125
                return getSource();
1✔
126
            }
127
            if (propertyName.equalsIgnoreCase("name")) {
1✔
128
                return getName();
1✔
129
            }
130
            return super.get(propertyName);
1✔
131
        }
132

133
        @Override
134
        public void set(String propertyName, Object value) {
135
            if (propertyName.equalsIgnoreCase("src")) {
1!
136
                if (value != null) {
1!
137
                    _element.setSrc(value.toString());
1✔
138
                }
139
            } else {
140
                super.set(propertyName, value);
×
141
            }
142
        }
1✔
143
    }
144

145
    // ---------------------------------- WebRequestSource methods ------------------------------------------
146

147
    @Override
148
    public ScriptableDelegate newScriptable() {
149
        return new Scriptable();
1✔
150
    }
151

152
}
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