• 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

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
/**
33
 * The Class HTMLSelectElementImpl.
34
 */
35
public class HTMLSelectElementImpl extends HTMLControl implements HTMLSelectElement {
1✔
36

37
    /** The Constant serialVersionUID. */
38
    private static final long serialVersionUID = 1L;
39

40
    /** The Constant TYPE_SELECT_ONE. */
41
    public static final String TYPE_SELECT_ONE = "select-one";
42

43
    /** The Constant TYPE_SELECT_MULTIPLE. */
44
    public static final String TYPE_SELECT_MULTIPLE = "select-multiple";
45

46
    @Override
47
    ElementImpl create() {
48
        return new HTMLSelectElementImpl();
1✔
49
    }
50

51
    /**
52
     * Adds the.
53
     *
54
     * @param element
55
     *            the element
56
     * @param before
57
     *            the before
58
     *
59
     * @throws DOMException
60
     *             the DOM exception
61
     */
62
    @Override
63
    public void add(HTMLElement element, HTMLElement before) throws DOMException {
64
    }
×
65

66
    /**
67
     * simulate blur.
68
     */
69
    @Override
70
    public void blur() {
71
        handleEvent("onblur");
×
72
    }
×
73

74
    /**
75
     * simulate focus;.
76
     */
77
    @Override
78
    public void focus() {
79
        handleEvent("onfocus");
×
80
    }
×
81

82
    @Override
83
    public String getType() {
84
        return isMultiSelect() ? TYPE_SELECT_MULTIPLE : TYPE_SELECT_ONE;
1✔
85
    }
86

87
    /**
88
     * Checks if is multi select.
89
     *
90
     * @return true, if is multi select
91
     */
92
    private boolean isMultiSelect() {
93
        return getMultiple() && getSize() > 1;
1✔
94
    }
95

96
    /**
97
     * Gets the length.
98
     *
99
     * @return the length
100
     */
101
    @Override
102
    public int getLength() {
103
        return getOptions().getLength();
1✔
104
    }
105

106
    /**
107
     * Gets the multiple.
108
     *
109
     * @return the multiple
110
     */
111
    @Override
112
    public boolean getMultiple() {
113
        return getBooleanAttribute("multiple");
1✔
114
    }
115

116
    /**
117
     * Gets the options.
118
     *
119
     * @return the options
120
     */
121
    @Override
122
    public HTMLCollection getOptions() {
123
        return HTMLCollectionImpl
1✔
124
                .createHTMLCollectionImpl(getElementsByTagName(getHtmlDocument().toNodeCase("option")));
1✔
125
    }
126

127
    /**
128
     * Gets the selected index.
129
     *
130
     * @return the selected index
131
     */
132
    @Override
133
    public int getSelectedIndex() {
134
        HTMLCollection options = getOptions();
1✔
135
        for (int i = 0; i < options.getLength(); i++) {
1✔
136
            if (((HTMLOptionElement) options.item(i)).getSelected()) {
1✔
137
                return i;
1✔
138
            }
139
        }
140
        return isMultiSelect() ? -1 : 0;
1✔
141
    }
142

143
    /**
144
     * Gets the value.
145
     *
146
     * @return the value
147
     */
148
    @Override
149
    public String getValue() {
150
        HTMLCollection options = getOptions();
1✔
151
        for (int i = 0; i < options.getLength(); i++) {
1✔
152
            HTMLOptionElement optionElement = (HTMLOptionElement) options.item(i);
1✔
153
            if (optionElement.getSelected()) {
1✔
154
                return optionElement.getValue();
1✔
155
            }
156
        }
157
        return isMultiSelect() || options.getLength() == 0 ? null : ((HTMLOptionElement) options.item(0)).getValue();
1!
158
    }
159

160
    /**
161
     * Gets the size.
162
     *
163
     * @return the size
164
     */
165
    @Override
166
    public int getSize() {
167
        return getIntegerAttribute("size");
1✔
168
    }
169

170
    /**
171
     * Removes the.
172
     *
173
     * @param index
174
     *            the index
175
     */
176
    @Override
177
    public void remove(int index) {
178
    }
×
179

180
    /**
181
     * Sets the multiple.
182
     *
183
     * @param multiple
184
     *            the new multiple
185
     */
186
    @Override
187
    public void setMultiple(boolean multiple) {
188
        setAttribute("multiple", multiple);
1✔
189
    }
1✔
190

191
    /**
192
     * Sets the selected index.
193
     *
194
     * @param selectedIndex
195
     *            the new selected index
196
     */
197
    @Override
198
    public void setSelectedIndex(int selectedIndex) {
199
        HTMLCollection options = getOptions();
1✔
200
        for (int i = 0; i < options.getLength(); i++) {
1✔
201
            HTMLOptionElementImpl optionElement = (HTMLOptionElementImpl) options.item(i);
1✔
202
            optionElement.setSelected(i == selectedIndex);
1✔
203
        }
204
    }
1✔
205

206
    /**
207
     * Sets the size.
208
     *
209
     * @param size
210
     *            the new size
211
     */
212
    @Override
213
    public void setSize(int size) {
214
        setAttribute("size", size);
1✔
215
    }
1✔
216

217
    /**
218
     * Gets the index of.
219
     *
220
     * @param option
221
     *            the option
222
     *
223
     * @return the index of
224
     */
225
    int getIndexOf(HTMLOptionElementImpl option) {
226
        HTMLCollection options = getOptions();
1✔
227
        for (int i = 0; i < options.getLength(); i++) {
1!
228
            if (options.item(i) == option) {
1✔
229
                return i;
1✔
230
            }
231
        }
232
        throw new IllegalStateException("option is not part of this select");
×
233
    }
234

235
    /**
236
     * Clear selected.
237
     */
238
    void clearSelected() {
239
        setSelectedIndex(-1);
1✔
240
    }
1✔
241

242
    @Override
243
    void addValues(ParameterProcessor processor, String characterSet) throws IOException {
244
        HTMLCollection options = getOptions();
1✔
245
        String name = getName();
1✔
246
        for (int i = 0; i < options.getLength(); i++) {
1✔
247
            ((HTMLOptionElementImpl) options.item(i)).addValueIfSelected(processor, name, characterSet);
1✔
248
        }
249
    }
1✔
250

251
    /**
252
     * Sets the value.
253
     *
254
     * @param value
255
     *            the new value
256
     */
257
    @Override
258
    public void setValue(String value) {
259
        setAttribute("value", value);
×
260
    }
×
261

262
    @Override
263
    public void reset() {
264
        HTMLCollection options = getOptions();
1✔
265
        for (int i = 0; i < options.getLength(); i++) {
1✔
266
            HTMLControl optionElement = (HTMLControl) options.item(i);
1✔
267
            optionElement.reset();
1✔
268
        }
269
    }
1✔
270
}
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