• 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

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

12
import java.io.IOException;
13

14
import org.w3c.dom.DOMException;
15
import org.w3c.dom.html.HTMLCollection;
16
import org.w3c.dom.html.HTMLElement;
17
import org.w3c.dom.html.HTMLOptionElement;
18
import org.w3c.dom.html.HTMLSelectElement;
19

20
/**
21
 * The Class HTMLSelectElementImpl.
22
 */
23
public class HTMLSelectElementImpl extends HTMLControl implements HTMLSelectElement {
1✔
24

25
    /** The Constant serialVersionUID. */
26
    private static final long serialVersionUID = 1L;
27

28
    /** The Constant TYPE_SELECT_ONE. */
29
    public static final String TYPE_SELECT_ONE = "select-one";
30

31
    /** The Constant TYPE_SELECT_MULTIPLE. */
32
    public static final String TYPE_SELECT_MULTIPLE = "select-multiple";
33

34
    @Override
35
    ElementImpl create() {
36
        return new HTMLSelectElementImpl();
1✔
37
    }
38

39
    /**
40
     * Adds the.
41
     *
42
     * @param element
43
     *            the element
44
     * @param before
45
     *            the before
46
     *
47
     * @throws DOMException
48
     *             the DOM exception
49
     */
50
    @Override
51
    public void add(HTMLElement element, HTMLElement before) throws DOMException {
52
    }
×
53

54
    /**
55
     * simulate blur.
56
     */
57
    @Override
58
    public void blur() {
59
        handleEvent("onblur");
×
60
    }
×
61

62
    /**
63
     * simulate focus;.
64
     */
65
    @Override
66
    public void focus() {
67
        handleEvent("onfocus");
×
68
    }
×
69

70
    @Override
71
    public String getType() {
72
        return isMultiSelect() ? TYPE_SELECT_MULTIPLE : TYPE_SELECT_ONE;
1✔
73
    }
74

75
    /**
76
     * Checks if is multi select.
77
     *
78
     * @return true, if is multi select
79
     */
80
    private boolean isMultiSelect() {
81
        return getMultiple() && getSize() > 1;
1✔
82
    }
83

84
    /**
85
     * Gets the length.
86
     *
87
     * @return the length
88
     */
89
    @Override
90
    public int getLength() {
91
        return getOptions().getLength();
1✔
92
    }
93

94
    /**
95
     * Gets the multiple.
96
     *
97
     * @return the multiple
98
     */
99
    @Override
100
    public boolean getMultiple() {
101
        return getBooleanAttribute("multiple");
1✔
102
    }
103

104
    /**
105
     * Gets the options.
106
     *
107
     * @return the options
108
     */
109
    @Override
110
    public HTMLCollection getOptions() {
111
        return HTMLCollectionImpl
1✔
112
                .createHTMLCollectionImpl(getElementsByTagName(getHtmlDocument().toNodeCase("option")));
1✔
113
    }
114

115
    /**
116
     * Gets the selected index.
117
     *
118
     * @return the selected index
119
     */
120
    @Override
121
    public int getSelectedIndex() {
122
        HTMLCollection options = getOptions();
1✔
123
        for (int i = 0; i < options.getLength(); i++) {
1✔
124
            if (((HTMLOptionElement) options.item(i)).getSelected()) {
1✔
125
                return i;
1✔
126
            }
127
        }
128
        return isMultiSelect() ? -1 : 0;
1✔
129
    }
130

131
    /**
132
     * Gets the value.
133
     *
134
     * @return the value
135
     */
136
    @Override
137
    public String getValue() {
138
        HTMLCollection options = getOptions();
1✔
139
        for (int i = 0; i < options.getLength(); i++) {
1✔
140
            HTMLOptionElement optionElement = (HTMLOptionElement) options.item(i);
1✔
141
            if (optionElement.getSelected()) {
1✔
142
                return optionElement.getValue();
1✔
143
            }
144
        }
145
        return isMultiSelect() || options.getLength() == 0 ? null : ((HTMLOptionElement) options.item(0)).getValue();
1!
146
    }
147

148
    /**
149
     * Gets the size.
150
     *
151
     * @return the size
152
     */
153
    @Override
154
    public int getSize() {
155
        return getIntegerAttribute("size");
1✔
156
    }
157

158
    /**
159
     * Removes the.
160
     *
161
     * @param index
162
     *            the index
163
     */
164
    @Override
165
    public void remove(int index) {
166
    }
×
167

168
    /**
169
     * Sets the multiple.
170
     *
171
     * @param multiple
172
     *            the new multiple
173
     */
174
    @Override
175
    public void setMultiple(boolean multiple) {
176
        setAttribute("multiple", multiple);
1✔
177
    }
1✔
178

179
    /**
180
     * Sets the selected index.
181
     *
182
     * @param selectedIndex
183
     *            the new selected index
184
     */
185
    @Override
186
    public void setSelectedIndex(int selectedIndex) {
187
        HTMLCollection options = getOptions();
1✔
188
        for (int i = 0; i < options.getLength(); i++) {
1✔
189
            HTMLOptionElementImpl optionElement = (HTMLOptionElementImpl) options.item(i);
1✔
190
            optionElement.setSelected(i == selectedIndex);
1✔
191
        }
192
    }
1✔
193

194
    /**
195
     * Sets the size.
196
     *
197
     * @param size
198
     *            the new size
199
     */
200
    @Override
201
    public void setSize(int size) {
202
        setAttribute("size", size);
1✔
203
    }
1✔
204

205
    /**
206
     * Gets the index of.
207
     *
208
     * @param option
209
     *            the option
210
     *
211
     * @return the index of
212
     */
213
    int getIndexOf(HTMLOptionElementImpl option) {
214
        HTMLCollection options = getOptions();
1✔
215
        for (int i = 0; i < options.getLength(); i++) {
1!
216
            if (options.item(i) == option) {
1✔
217
                return i;
1✔
218
            }
219
        }
220
        throw new IllegalStateException("option is not part of this select");
×
221
    }
222

223
    /**
224
     * Clear selected.
225
     */
226
    void clearSelected() {
227
        setSelectedIndex(-1);
1✔
228
    }
1✔
229

230
    @Override
231
    void addValues(ParameterProcessor processor, String characterSet) throws IOException {
232
        HTMLCollection options = getOptions();
1✔
233
        String name = getName();
1✔
234
        for (int i = 0; i < options.getLength(); i++) {
1✔
235
            ((HTMLOptionElementImpl) options.item(i)).addValueIfSelected(processor, name, characterSet);
1✔
236
        }
237
    }
1✔
238

239
    /**
240
     * Sets the value.
241
     *
242
     * @param value
243
     *            the new value
244
     */
245
    @Override
246
    public void setValue(String value) {
247
        setAttribute("value", value);
×
248
    }
×
249

250
    @Override
251
    public void reset() {
252
        HTMLCollection options = getOptions();
1✔
253
        for (int i = 0; i < options.getLength(); i++) {
1✔
254
            HTMLControl optionElement = (HTMLControl) options.item(i);
1✔
255
            optionElement.reset();
1✔
256
        }
257
    }
1✔
258
}
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