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

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

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
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.httpunit;
9

10
import com.meterware.httpunit.scripting.NamedDelegate;
11
import com.meterware.httpunit.scripting.ScriptableDelegate;
12

13
import java.net.URL;
14

15
import org.w3c.dom.Node;
16
import org.w3c.dom.html.HTMLImageElement;
17

18
/**
19
 * Represents an image in an HTML document.
20
 **/
21
public class WebImage extends FixedURLWebRequestSource {
22

23
    /** The element. */
24
    private HTMLImageElement _element;
25

26
    /** The parsed HTML. */
27
    private ParsedHTML _parsedHTML;
28

29
    /**
30
     * Instantiates a new web image.
31
     *
32
     * @param response
33
     *            the response
34
     * @param parsedHTML
35
     *            the parsed HTML
36
     * @param baseURL
37
     *            the base URL
38
     * @param element
39
     *            the element
40
     * @param sourceFrame
41
     *            the source frame
42
     * @param defaultTarget
43
     *            the default target
44
     * @param characterSet
45
     *            the character set
46
     */
47
    WebImage(WebResponse response, ParsedHTML parsedHTML, URL baseURL, HTMLImageElement element,
48
            FrameSelector sourceFrame, String defaultTarget, String characterSet) {
49
        super(response, element, baseURL, "src", sourceFrame, defaultTarget, characterSet);
1✔
50
        _element = element;
1✔
51
        _parsedHTML = parsedHTML;
1✔
52
    }
1✔
53

54
    @Override
55
    public String getName() {
56
        return _element.getName();
1✔
57
    }
58

59
    /**
60
     * Gets the source.
61
     *
62
     * @return the source
63
     */
64
    public String getSource() {
65
        return _element.getSrc();
1✔
66
    }
67

68
    /**
69
     * Gets the alt text.
70
     *
71
     * @return the alt text
72
     */
73
    public String getAltText() {
74
        return _element.getAlt();
1✔
75
    }
76

77
    /**
78
     * Gets the link.
79
     *
80
     * @return the link
81
     */
82
    public WebLink getLink() {
83
        return _parsedHTML.getFirstMatchingLink((link, parentNode) -> {
1✔
84
            for (Node parent = (Node) parentNode; parent != null; parent = parent.getParentNode()) {
1✔
85
                if (parent.equals(((WebLink) link).getElement())) {
1✔
86
                    return true;
1✔
87
                }
88
            }
89
            return false;
1✔
90
        }, _element.getParentNode());
1✔
91
    }
92

93
    /**
94
     * The Class Scriptable.
95
     */
96
    public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
97

98
        /**
99
         * Instantiates a new scriptable.
100
         */
101
        public Scriptable() {
1✔
102
            super(WebImage.this);
1✔
103
        }
1✔
104

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

110
        @Override
111
        public Object get(String propertyName) {
112
            if (propertyName.equalsIgnoreCase("src")) {
1✔
113
                return getSource();
1✔
114
            }
115
            if (propertyName.equalsIgnoreCase("name")) {
1✔
116
                return getName();
1✔
117
            }
118
            return super.get(propertyName);
1✔
119
        }
120

121
        @Override
122
        public void set(String propertyName, Object value) {
123
            if (propertyName.equalsIgnoreCase("src")) {
1!
124
                if (value != null) {
1!
125
                    _element.setSrc(value.toString());
1✔
126
                }
127
            } else {
128
                super.set(propertyName, value);
×
129
            }
130
        }
1✔
131
    }
132

133
    // ---------------------------------- WebRequestSource methods ------------------------------------------
134

135
    @Override
136
    public ScriptableDelegate newScriptable() {
137
        return new Scriptable();
1✔
138
    }
139

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