• 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

85.57
/src/main/java/com/meterware/httpunit/RadioGroupFormControl.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;
21

22
import com.meterware.httpunit.controls.IllegalParameterValueException;
23
import com.meterware.httpunit.protocol.ParameterProcessor;
24
import com.meterware.httpunit.scripting.ScriptableDelegate;
25

26
import java.io.IOException;
27
import java.util.ArrayList;
28
import java.util.Arrays;
29
import java.util.List;
30

31
/**
32
 * Radio button control.
33
 */
34
public class RadioGroupFormControl extends FormControl {
35

36
    /** The button list. */
37
    private List _buttonList = new ArrayList<>();
1✔
38

39
    /** The buttons. */
40
    private RadioButtonFormControl[] _buttons;
41

42
    /** The allowed values. */
43
    private String[] _allowedValues;
44

45
    @Override
46
    public String getType() {
47
        return UNDEFINED_TYPE;
×
48
    }
49

50
    /**
51
     * construct Radiobuttons for a form.
52
     *
53
     * @param form
54
     *            the form
55
     */
56
    public RadioGroupFormControl(WebForm form) {
57
        super(form);
1✔
58
    }
1✔
59

60
    /**
61
     * add a radio button.
62
     *
63
     * @param control
64
     *            the control
65
     */
66
    void addRadioButton(RadioButtonFormControl control) {
67
        _buttonList.add(control);
1✔
68
        _buttons = null;
1✔
69
        _allowedValues = null;
1✔
70
    }
1✔
71

72
    /**
73
     * get the values for the buttons
74
     *
75
     * @return an array of String values
76
     */
77
    @Override
78
    public String[] getValues() {
79
        for (int i = 0; i < getButtons().length; i++) {
1!
80
            if (getButtons()[i].isChecked()) {
1✔
81
                return getButtons()[i].getValues();
1✔
82
            }
83
        }
84
        return NO_VALUE;
×
85
    }
86

87
    /**
88
     * Returns the option values defined for this radio button group.
89
     **/
90
    @Override
91
    public String[] getOptionValues() {
92
        ArrayList valueList = new ArrayList<>();
1✔
93
        FormControl[] buttons = getButtons();
1✔
94
        for (FormControl button : buttons) {
1✔
95
            valueList.addAll(Arrays.asList(button.getOptionValues()));
1✔
96
        }
97
        return (String[]) valueList.toArray(new String[valueList.size()]);
1✔
98
    }
99

100
    /**
101
     * Returns the options displayed for this radio button group.
102
     */
103
    @Override
104
    protected String[] getDisplayedOptions() {
105
        ArrayList valueList = new ArrayList<>();
1✔
106
        FormControl[] buttons = getButtons();
1✔
107
        for (FormControl button : buttons) {
1✔
108
            valueList.addAll(Arrays.asList(button.getDisplayedOptions()));
1✔
109
        }
110
        return (String[]) valueList.toArray(new String[valueList.size()]);
1✔
111
    }
112

113
    @Override
114
    Object getDelegate() {
115
        ScriptableDelegate[] delegates = new ScriptableDelegate[getButtons().length];
1✔
116
        for (int i = 0; i < delegates.length; i++) {
1✔
117
            delegates[i] = (ScriptableDelegate) getButtons()[i].getScriptingHandler();
1✔
118
        }
119
        return delegates;
1✔
120
    }
121

122
    @Override
123
    protected void addValues(ParameterProcessor processor, String characterSet) throws IOException {
124
        for (int i = 0; i < getButtons().length; i++) {
×
125
            getButtons()[i].addValues(processor, characterSet);
×
126
        }
127
    }
×
128

129
    /**
130
     * Remove any required values for this control from the list, throwing an exception if they are missing.
131
     **/
132
    @Override
133
    void claimRequiredValues(List values) {
134
        for (int i = 0; i < getButtons().length; i++) {
1✔
135
            getButtons()[i].claimRequiredValues(values);
1✔
136
        }
137
    }
1✔
138

139
    @Override
140
    protected void claimUniqueValue(List values) {
141
        int matchingButtonIndex = -1;
1✔
142
        for (int i = 0; i < getButtons().length && matchingButtonIndex < 0; i++) {
1✔
143
            if (!getButtons()[i].isReadOnly() && values.contains(getButtons()[i].getQueryValue())) {
1✔
144
                matchingButtonIndex = i;
1✔
145
            }
146
        }
147
        if (matchingButtonIndex < 0) {
1✔
148
            throw new IllegalParameterValueException(getButtons()[0].getName(), values, getAllowedValues());
1✔
149
        }
150

151
        boolean wasChecked = getButtons()[matchingButtonIndex].isChecked();
1✔
152
        for (int i = 0; i < getButtons().length; i++) {
1✔
153
            if (!getButtons()[i].isReadOnly()) {
1✔
154
                getButtons()[i].setChecked(i == matchingButtonIndex);
1✔
155
            }
156
        }
157
        values.remove(getButtons()[matchingButtonIndex].getQueryValue());
1✔
158
        if (!wasChecked) {
1✔
159
            getButtons()[matchingButtonIndex].sendOnClickEvent();
1✔
160
        }
161
    }
1✔
162

163
    @Override
164
    protected void reset() {
165
        for (int i = 0; i < getButtons().length; i++) {
×
166
            getButtons()[i].reset();
×
167
        }
168
    }
×
169

170
    /**
171
     * Gets the allowed values.
172
     *
173
     * @return the allowed values
174
     */
175
    private String[] getAllowedValues() {
176
        if (_allowedValues == null) {
1!
177
            _allowedValues = new String[getButtons().length];
1✔
178
            for (int i = 0; i < _allowedValues.length; i++) {
1✔
179
                _allowedValues[i] = getButtons()[i].getQueryValue();
1✔
180
            }
181
        }
182
        return _allowedValues;
1✔
183
    }
184

185
    /**
186
     * Gets the buttons.
187
     *
188
     * @return the buttons
189
     */
190
    private RadioButtonFormControl[] getButtons() {
191
        if (_buttons == null) {
1✔
192
            _buttons = (RadioButtonFormControl[]) _buttonList.toArray(new RadioButtonFormControl[_buttonList.size()]);
1✔
193
        }
194
        return _buttons;
1✔
195
    }
196
}
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