• 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

87.21
/src/main/java/com/meterware/httpunit/dom/HTMLSelectElementImpl.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 com.meterware.httpunit.protocol.ParameterProcessor;
23

24
import java.io.IOException;
25

26
import org.w3c.dom.DOMException;
27
import org.w3c.dom.html.HTMLCollection;
28
import org.w3c.dom.html.HTMLElement;
29
import org.w3c.dom.html.HTMLOptionElement;
30
import org.w3c.dom.html.HTMLSelectElement;
31

32
public class HTMLSelectElementImpl extends HTMLControl implements HTMLSelectElement {
1✔
33

34
    private static final long serialVersionUID = 1L;
35
    public static final String TYPE_SELECT_ONE = "select-one";
36
    public static final String TYPE_SELECT_MULTIPLE = "select-multiple";
37

38
    @Override
39
    ElementImpl create() {
40
        return new HTMLSelectElementImpl();
1✔
41
    }
42

43
    @Override
44
    public void add(HTMLElement element, HTMLElement before) throws DOMException {
45
    }
×
46

47
    /**
48
     * simulate blur
49
     */
50
    @Override
51
    public void blur() {
52
        handleEvent("onblur");
×
53
    }
×
54

55
    /**
56
     * simulate focus;
57
     */
58
    @Override
59
    public void focus() {
60
        handleEvent("onfocus");
×
61
    }
×
62

63
    @Override
64
    public String getType() {
65
        return isMultiSelect() ? TYPE_SELECT_MULTIPLE : TYPE_SELECT_ONE;
1✔
66
    }
67

68
    private boolean isMultiSelect() {
69
        return getMultiple() && getSize() > 1;
1✔
70
    }
71

72
    @Override
73
    public int getLength() {
74
        return getOptions().getLength();
1✔
75
    }
76

77
    @Override
78
    public boolean getMultiple() {
79
        return getBooleanAttribute("multiple");
1✔
80
    }
81

82
    @Override
83
    public HTMLCollection getOptions() {
84
        return HTMLCollectionImpl
1✔
85
                .createHTMLCollectionImpl(getElementsByTagName(getHtmlDocument().toNodeCase("option")));
1✔
86
    }
87

88
    @Override
89
    public int getSelectedIndex() {
90
        HTMLCollection options = getOptions();
1✔
91
        for (int i = 0; i < options.getLength(); i++) {
1✔
92
            if (((HTMLOptionElement) options.item(i)).getSelected()) {
1✔
93
                return i;
1✔
94
            }
95
        }
96
        return isMultiSelect() ? -1 : 0;
1✔
97
    }
98

99
    @Override
100
    public String getValue() {
101
        HTMLCollection options = getOptions();
1✔
102
        for (int i = 0; i < options.getLength(); i++) {
1✔
103
            HTMLOptionElement optionElement = (HTMLOptionElement) options.item(i);
1✔
104
            if (optionElement.getSelected()) {
1✔
105
                return optionElement.getValue();
1✔
106
            }
107
        }
108
        return isMultiSelect() || options.getLength() == 0 ? null : ((HTMLOptionElement) options.item(0)).getValue();
1!
109
    }
110

111
    @Override
112
    public int getSize() {
113
        return getIntegerAttribute("size");
1✔
114
    }
115

116
    @Override
117
    public void remove(int index) {
118
    }
×
119

120
    @Override
121
    public void setMultiple(boolean multiple) {
122
        setAttribute("multiple", multiple);
1✔
123
    }
1✔
124

125
    @Override
126
    public void setSelectedIndex(int selectedIndex) {
127
        HTMLCollection options = getOptions();
1✔
128
        for (int i = 0; i < options.getLength(); i++) {
1✔
129
            HTMLOptionElementImpl optionElement = (HTMLOptionElementImpl) options.item(i);
1✔
130
            optionElement.setSelected(i == selectedIndex);
1✔
131
        }
132
    }
1✔
133

134
    @Override
135
    public void setSize(int size) {
136
        setAttribute("size", size);
1✔
137
    }
1✔
138

139
    int getIndexOf(HTMLOptionElementImpl option) {
140
        HTMLCollection options = getOptions();
1✔
141
        for (int i = 0; i < options.getLength(); i++) {
1!
142
            if (options.item(i) == option) {
1✔
143
                return i;
1✔
144
            }
145
        }
146
        throw new IllegalStateException("option is not part of this select");
×
147
    }
148

149
    void clearSelected() {
150
        setSelectedIndex(-1);
1✔
151
    }
1✔
152

153
    @Override
154
    void addValues(ParameterProcessor processor, String characterSet) throws IOException {
155
        HTMLCollection options = getOptions();
1✔
156
        String name = getName();
1✔
157
        for (int i = 0; i < options.getLength(); i++) {
1✔
158
            ((HTMLOptionElementImpl) options.item(i)).addValueIfSelected(processor, name, characterSet);
1✔
159
        }
160
    }
1✔
161

162
    @Override
163
    public void setValue(String value) {
164
        setAttribute("value", value);
×
165
    }
×
166

167
    @Override
168
    public void reset() {
169
        HTMLCollection options = getOptions();
1✔
170
        for (int i = 0; i < options.getLength(); i++) {
1✔
171
            HTMLControl optionElement = (HTMLControl) options.item(i);
1✔
172
            optionElement.reset();
1✔
173
        }
174
    }
1✔
175
}
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