• 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

77.78
/src/main/java/com/meterware/httpunit/dom/HTMLCollectionImpl.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.dom;
21

22
import org.mozilla.javascript.Scriptable;
23
import org.mozilla.javascript.ScriptableObject;
24
import org.w3c.dom.Node;
25
import org.w3c.dom.NodeList;
26
import org.w3c.dom.html.HTMLCollection;
27
import org.w3c.dom.html.HTMLElement;
28

29
/**
30
 * The Class HTMLCollectionImpl.
31
 */
32
public class HTMLCollectionImpl extends ScriptableObject implements HTMLCollection {
1✔
33

34
    /** The Constant serialVersionUID. */
35
    private static final long serialVersionUID = 1L;
36

37
    /** The list. */
38
    private NodeList _list;
39

40
    /**
41
     * Creates the HTML collection impl.
42
     *
43
     * @param list
44
     *            the list
45
     *
46
     * @return the HTML collection impl
47
     */
48
    public static HTMLCollectionImpl createHTMLCollectionImpl(NodeList list) {
49
        HTMLCollectionImpl htmlCollection = new HTMLCollectionImpl();
1✔
50
        htmlCollection.initialize(list);
1✔
51
        return htmlCollection;
1✔
52
    }
53

54
    /**
55
     * Initialize.
56
     *
57
     * @param list
58
     *            the list
59
     */
60
    private void initialize(NodeList list) {
61
        _list = list;
1✔
62
    }
1✔
63

64
    // ------------------------------------------ HTMLCollection methods
65
    // --------------------------------------------------
66

67
    /**
68
     * Gets the length.
69
     *
70
     * @return the length
71
     */
72
    @Override
73
    public int getLength() {
74
        return _list.getLength();
1✔
75
    }
76

77
    /**
78
     * Item.
79
     *
80
     * @param index
81
     *            the index
82
     *
83
     * @return the node
84
     */
85
    @Override
86
    public Node item(int index) {
87
        return _list.item(index);
1✔
88
    }
89

90
    /**
91
     * Named item.
92
     *
93
     * @param name
94
     *            the name
95
     *
96
     * @return the node
97
     */
98
    @Override
99
    public Node namedItem(String name) {
100
        if (name == null) {
1!
101
            return null;
×
102
        }
103

104
        Node nodeByName = null;
1✔
105
        for (int i = 0; null == nodeByName && i < getLength(); i++) {
1!
106
            Node node = item(i);
1✔
107
            if (!(node instanceof HTMLElementImpl)) {
1!
108
                continue;
×
109
            }
110
            if (name.equalsIgnoreCase(((HTMLElement) node).getId())) {
1✔
111
                return node;
1✔
112
            }
113
            if (name.equalsIgnoreCase(((HTMLElementImpl) node).getAttributeWithNoDefault("name"))) {
1✔
114
                nodeByName = node;
1✔
115
            }
116
        }
117
        return nodeByName;
1✔
118
    }
119

120
    // ------------------------------------------ ScriptableObject methods
121
    // --------------------------------------------------
122

123
    @Override
124
    public String getClassName() {
125
        return getClass().getName();
×
126
    }
127

128
    @Override
129
    public Object get(String propertyName, Scriptable scriptable) {
130
        Object result = super.get(propertyName, scriptable);
1✔
131
        if (result != NOT_FOUND) {
1!
132
            return result;
×
133
        }
134

135
        Object namedProperty = ScriptingSupport.getNamedProperty(this, propertyName, scriptable);
1✔
136
        if (namedProperty != NOT_FOUND) {
1✔
137
            return namedProperty;
1✔
138
        }
139

140
        Node namedItem = namedItem(propertyName);
1✔
141
        return namedItem == null ? NOT_FOUND : namedItem;
1!
142
    }
143

144
    @Override
145
    public Object get(int index, Scriptable start) {
146
        if (index < 0 || index >= _list.getLength()) {
1!
147
            return NOT_FOUND;
×
148
        }
149
        return item(index);
1✔
150
    }
151
}
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