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

17
/**
18
 * The Class HTMLOptionElementImpl.
19
 */
20
public class HTMLOptionElementImpl extends HTMLControl implements HTMLOptionElement {
1✔
21

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

25
    /** The selected. */
26
    private Boolean _selected;
27

28
    @Override
29
    ElementImpl create() {
30
        return new HTMLOptionElementImpl();
1✔
31
    }
32

33
    /**
34
     * Gets the default selected.
35
     *
36
     * @return the default selected
37
     */
38
    @Override
39
    public boolean getDefaultSelected() {
40
        return getBooleanAttribute("selected");
1✔
41
    }
42

43
    /**
44
     * Gets the index.
45
     *
46
     * @return the index
47
     */
48
    @Override
49
    public int getIndex() {
50
        return getSelect().getIndexOf(this);
1✔
51
    }
52

53
    /**
54
     * Sets the index.
55
     *
56
     * @param i
57
     *            the new index
58
     */
59
    public void setIndex(int i) {
60
    } // obsolete - required for compatibility with JDK 1.3
×
61

62
    /**
63
     * Gets the label.
64
     *
65
     * @return the label
66
     */
67
    @Override
68
    public String getLabel() {
69
        return getAttributeWithNoDefault("label");
1✔
70
    }
71

72
    /**
73
     * Gets the selected.
74
     *
75
     * @return the selected
76
     */
77
    @Override
78
    public boolean getSelected() {
79
        return _selected != null ? _selected.booleanValue() : getDefaultSelected();
1✔
80
    }
81

82
    /**
83
     * Gets the text.
84
     *
85
     * @return the text
86
     */
87
    @Override
88
    public String getText() {
89
        return asText();
1✔
90
    }
91

92
    /**
93
     * Sets the default selected.
94
     *
95
     * @param defaultSelected
96
     *            the new default selected
97
     */
98
    @Override
99
    public void setDefaultSelected(boolean defaultSelected) {
100
    }
×
101

102
    /**
103
     * Sets the label.
104
     *
105
     * @param label
106
     *            the new label
107
     */
108
    @Override
109
    public void setLabel(String label) {
110
        setAttribute("label", label);
1✔
111
    }
1✔
112

113
    /**
114
     * Sets the selected.
115
     *
116
     * @param selected
117
     *            the new selected
118
     */
119
    public void setSelected(boolean selected) {
120
        if (selected && getSelect().getType().equals(HTMLSelectElementImpl.TYPE_SELECT_ONE)) {
1✔
121
            getSelect().clearSelected();
1✔
122
        }
123
        _selected = selected ? Boolean.TRUE : Boolean.FALSE;
1✔
124
    }
1✔
125

126
    /**
127
     * Gets the select.
128
     *
129
     * @return the select
130
     */
131
    private HTMLSelectElementImpl getSelect() {
132
        Node parent = getParentNode();
1✔
133
        while (parent != null && !"select".equalsIgnoreCase(parent.getNodeName())) {
1!
134
            parent = parent.getParentNode();
×
135
        }
136
        return (HTMLSelectElementImpl) parent;
1✔
137
    }
138

139
    /**
140
     * Gets the value.
141
     *
142
     * @return the value
143
     */
144
    @Override
145
    public String getValue() {
146
        return getAttributeWithNoDefault("value");
1✔
147
    }
148

149
    /**
150
     * Sets the value.
151
     *
152
     * @param value
153
     *            the new value
154
     */
155
    @Override
156
    public void setValue(String value) {
157
        setAttribute("value", value);
1✔
158
    }
1✔
159

160
    @Override
161
    public void reset() {
162
        _selected = null;
1✔
163
    }
1✔
164

165
    /**
166
     * Adds the value if selected.
167
     *
168
     * @param processor
169
     *            the processor
170
     * @param name
171
     *            the name
172
     * @param characterSet
173
     *            the character set
174
     *
175
     * @throws IOException
176
     *             Signals that an I/O exception has occurred.
177
     */
178
    void addValueIfSelected(ParameterProcessor processor, String name, String characterSet) throws IOException {
179
        if (getSelected()) {
1✔
180
            String value = getValue();
1✔
181
            if (value == null) {
1✔
182
                value = readDisplayedValue();
1✔
183
            }
184
            processor.addParameter(name, value, characterSet);
1✔
185
        }
186
    }
1✔
187

188
    /**
189
     * Read displayed value.
190
     *
191
     * @return the string
192
     */
193
    private String readDisplayedValue() {
194
        Node nextSibling = getNextSibling();
1✔
195
        while (nextSibling != null && nextSibling.getNodeType() != Node.TEXT_NODE
1!
196
                && nextSibling.getNodeType() != Node.ELEMENT_NODE) {
×
197
            nextSibling = nextSibling.getNextSibling();
×
198
        }
199
        if (nextSibling == null || nextSibling.getNodeType() != Node.TEXT_NODE) {
1!
200
            return "";
×
201
        }
202
        return nextSibling.getNodeValue();
1✔
203
    }
204

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