• 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

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

10
import org.mozilla.javascript.Scriptable;
11
import org.mozilla.javascript.ScriptableObject;
12
import org.w3c.dom.Node;
13
import org.w3c.dom.NodeList;
14
import org.w3c.dom.html.HTMLCollection;
15
import org.w3c.dom.html.HTMLElement;
16

17
/**
18
 * The Class HTMLCollectionImpl.
19
 */
20
public class HTMLCollectionImpl extends ScriptableObject implements HTMLCollection {
1✔
21

22
    /** The Constant serialVersionUID. */
23
    private static final long serialVersionUID = 1L;
24

25
    /** The list. */
26
    private NodeList _list;
27

28
    /**
29
     * Creates the HTML collection impl.
30
     *
31
     * @param list
32
     *            the list
33
     *
34
     * @return the HTML collection impl
35
     */
36
    public static HTMLCollectionImpl createHTMLCollectionImpl(NodeList list) {
37
        HTMLCollectionImpl htmlCollection = new HTMLCollectionImpl();
1✔
38
        htmlCollection.initialize(list);
1✔
39
        return htmlCollection;
1✔
40
    }
41

42
    /**
43
     * Initialize.
44
     *
45
     * @param list
46
     *            the list
47
     */
48
    private void initialize(NodeList list) {
49
        _list = list;
1✔
50
    }
1✔
51

52
    // ------------------------------------------ HTMLCollection methods
53
    // --------------------------------------------------
54

55
    /**
56
     * Gets the length.
57
     *
58
     * @return the length
59
     */
60
    @Override
61
    public int getLength() {
62
        return _list.getLength();
1✔
63
    }
64

65
    /**
66
     * Item.
67
     *
68
     * @param index
69
     *            the index
70
     *
71
     * @return the node
72
     */
73
    @Override
74
    public Node item(int index) {
75
        return _list.item(index);
1✔
76
    }
77

78
    /**
79
     * Named item.
80
     *
81
     * @param name
82
     *            the name
83
     *
84
     * @return the node
85
     */
86
    @Override
87
    public Node namedItem(String name) {
88
        if (name == null) {
1!
89
            return null;
×
90
        }
91

92
        Node nodeByName = null;
1✔
93
        for (int i = 0; null == nodeByName && i < getLength(); i++) {
1!
94
            Node node = item(i);
1✔
95
            if (!(node instanceof HTMLElementImpl)) {
1!
96
                continue;
×
97
            }
98
            if (name.equalsIgnoreCase(((HTMLElement) node).getId())) {
1✔
99
                return node;
1✔
100
            }
101
            if (name.equalsIgnoreCase(((HTMLElementImpl) node).getAttributeWithNoDefault("name"))) {
1✔
102
                nodeByName = node;
1✔
103
            }
104
        }
105
        return nodeByName;
1✔
106
    }
107

108
    // ------------------------------------------ ScriptableObject methods
109
    // --------------------------------------------------
110

111
    @Override
112
    public String getClassName() {
113
        return getClass().getName();
×
114
    }
115

116
    @Override
117
    public Object get(String propertyName, Scriptable scriptable) {
118
        Object result = super.get(propertyName, scriptable);
1✔
119
        if (result != NOT_FOUND) {
1!
120
            return result;
×
121
        }
122

123
        Object namedProperty = ScriptingSupport.getNamedProperty(this, propertyName, scriptable);
1✔
124
        if (namedProperty != NOT_FOUND) {
1✔
125
            return namedProperty;
1✔
126
        }
127

128
        Node namedItem = namedItem(propertyName);
1✔
129
        return namedItem == null ? NOT_FOUND : namedItem;
1!
130
    }
131

132
    @Override
133
    public Object get(int index, Scriptable start) {
134
        if (index < 0 || index >= _list.getLength()) {
1!
135
            return NOT_FOUND;
×
136
        }
137
        return item(index);
1✔
138
    }
139
}
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