• 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/HTMLOptionElementImpl.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.Node;
27
import org.w3c.dom.html.HTMLOptionElement;
28

29
/**
30
 * The Class HTMLOptionElementImpl.
31
 */
32
public class HTMLOptionElementImpl extends HTMLControl implements HTMLOptionElement {
1✔
33

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

37
    /** The selected. */
38
    private Boolean _selected;
39

40
    @Override
41
    ElementImpl create() {
42
        return new HTMLOptionElementImpl();
1✔
43
    }
44

45
    /**
46
     * Gets the default selected.
47
     *
48
     * @return the default selected
49
     */
50
    @Override
51
    public boolean getDefaultSelected() {
52
        return getBooleanAttribute("selected");
1✔
53
    }
54

55
    /**
56
     * Gets the index.
57
     *
58
     * @return the index
59
     */
60
    @Override
61
    public int getIndex() {
62
        return getSelect().getIndexOf(this);
1✔
63
    }
64

65
    /**
66
     * Sets the index.
67
     *
68
     * @param i
69
     *            the new index
70
     */
71
    public void setIndex(int i) {
72
    } // obsolete - required for compatibility with JDK 1.3
×
73

74
    /**
75
     * Gets the label.
76
     *
77
     * @return the label
78
     */
79
    @Override
80
    public String getLabel() {
81
        return getAttributeWithNoDefault("label");
1✔
82
    }
83

84
    /**
85
     * Gets the selected.
86
     *
87
     * @return the selected
88
     */
89
    @Override
90
    public boolean getSelected() {
91
        return _selected != null ? _selected.booleanValue() : getDefaultSelected();
1✔
92
    }
93

94
    /**
95
     * Gets the text.
96
     *
97
     * @return the text
98
     */
99
    @Override
100
    public String getText() {
101
        return asText();
1✔
102
    }
103

104
    /**
105
     * Sets the default selected.
106
     *
107
     * @param defaultSelected
108
     *            the new default selected
109
     */
110
    @Override
111
    public void setDefaultSelected(boolean defaultSelected) {
112
    }
×
113

114
    /**
115
     * Sets the label.
116
     *
117
     * @param label
118
     *            the new label
119
     */
120
    @Override
121
    public void setLabel(String label) {
122
        setAttribute("label", label);
1✔
123
    }
1✔
124

125
    /**
126
     * Sets the selected.
127
     *
128
     * @param selected
129
     *            the new selected
130
     */
131
    public void setSelected(boolean selected) {
132
        if (selected && getSelect().getType().equals(HTMLSelectElementImpl.TYPE_SELECT_ONE)) {
1✔
133
            getSelect().clearSelected();
1✔
134
        }
135
        _selected = selected ? Boolean.TRUE : Boolean.FALSE;
1✔
136
    }
1✔
137

138
    /**
139
     * Gets the select.
140
     *
141
     * @return the select
142
     */
143
    private HTMLSelectElementImpl getSelect() {
144
        Node parent = getParentNode();
1✔
145
        while (parent != null && !"select".equalsIgnoreCase(parent.getNodeName())) {
1!
146
            parent = parent.getParentNode();
×
147
        }
148
        return (HTMLSelectElementImpl) parent;
1✔
149
    }
150

151
    /**
152
     * Gets the value.
153
     *
154
     * @return the value
155
     */
156
    @Override
157
    public String getValue() {
158
        return getAttributeWithNoDefault("value");
1✔
159
    }
160

161
    /**
162
     * Sets the value.
163
     *
164
     * @param value
165
     *            the new value
166
     */
167
    @Override
168
    public void setValue(String value) {
169
        setAttribute("value", value);
1✔
170
    }
1✔
171

172
    @Override
173
    public void reset() {
174
        _selected = null;
1✔
175
    }
1✔
176

177
    /**
178
     * Adds the value if selected.
179
     *
180
     * @param processor
181
     *            the processor
182
     * @param name
183
     *            the name
184
     * @param characterSet
185
     *            the character set
186
     *
187
     * @throws IOException
188
     *             Signals that an I/O exception has occurred.
189
     */
190
    void addValueIfSelected(ParameterProcessor processor, String name, String characterSet) throws IOException {
191
        if (getSelected()) {
1✔
192
            String value = getValue();
1✔
193
            if (value == null) {
1✔
194
                value = readDisplayedValue();
1✔
195
            }
196
            processor.addParameter(name, value, characterSet);
1✔
197
        }
198
    }
1✔
199

200
    /**
201
     * Read displayed value.
202
     *
203
     * @return the string
204
     */
205
    private String readDisplayedValue() {
206
        Node nextSibling = getNextSibling();
1✔
207
        while (nextSibling != null && nextSibling.getNodeType() != Node.TEXT_NODE
1!
208
                && nextSibling.getNodeType() != Node.ELEMENT_NODE) {
×
209
            nextSibling = nextSibling.getNextSibling();
×
210
        }
211
        if (nextSibling == null || nextSibling.getNodeType() != Node.TEXT_NODE) {
1!
212
            return "";
×
213
        }
214
        return nextSibling.getNodeValue();
1✔
215
    }
216

217
}
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