• 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

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

10
import com.meterware.httpunit.controls.IllegalParameterValueException;
11
import com.meterware.httpunit.protocol.ParameterProcessor;
12
import com.meterware.httpunit.scripting.ScriptableDelegate;
13

14
import java.io.IOException;
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.List;
18

19
/**
20
 * Radio button control.
21
 */
22
public class RadioGroupFormControl extends FormControl {
23

24
    /** The button list. */
25
    private List _buttonList = new ArrayList<>();
1✔
26

27
    /** The buttons. */
28
    private RadioButtonFormControl[] _buttons;
29

30
    /** The allowed values. */
31
    private String[] _allowedValues;
32

33
    @Override
34
    public String getType() {
35
        return UNDEFINED_TYPE;
×
36
    }
37

38
    /**
39
     * construct Radiobuttons for a form.
40
     *
41
     * @param form
42
     *            the form
43
     */
44
    public RadioGroupFormControl(WebForm form) {
45
        super(form);
1✔
46
    }
1✔
47

48
    /**
49
     * add a radio button.
50
     *
51
     * @param control
52
     *            the control
53
     */
54
    void addRadioButton(RadioButtonFormControl control) {
55
        _buttonList.add(control);
1✔
56
        _buttons = null;
1✔
57
        _allowedValues = null;
1✔
58
    }
1✔
59

60
    /**
61
     * get the values for the buttons
62
     *
63
     * @return an array of String values
64
     */
65
    @Override
66
    public String[] getValues() {
67
        for (int i = 0; i < getButtons().length; i++) {
1!
68
            if (getButtons()[i].isChecked()) {
1✔
69
                return getButtons()[i].getValues();
1✔
70
            }
71
        }
72
        return NO_VALUE;
×
73
    }
74

75
    /**
76
     * Returns the option values defined for this radio button group.
77
     **/
78
    @Override
79
    public String[] getOptionValues() {
80
        ArrayList valueList = new ArrayList<>();
1✔
81
        FormControl[] buttons = getButtons();
1✔
82
        for (FormControl button : buttons) {
1✔
83
            valueList.addAll(Arrays.asList(button.getOptionValues()));
1✔
84
        }
85
        return (String[]) valueList.toArray(new String[valueList.size()]);
1✔
86
    }
87

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

101
    @Override
102
    Object getDelegate() {
103
        ScriptableDelegate[] delegates = new ScriptableDelegate[getButtons().length];
1✔
104
        for (int i = 0; i < delegates.length; i++) {
1✔
105
            delegates[i] = (ScriptableDelegate) getButtons()[i].getScriptingHandler();
1✔
106
        }
107
        return delegates;
1✔
108
    }
109

110
    @Override
111
    protected void addValues(ParameterProcessor processor, String characterSet) throws IOException {
112
        for (int i = 0; i < getButtons().length; i++) {
×
113
            getButtons()[i].addValues(processor, characterSet);
×
114
        }
115
    }
×
116

117
    /**
118
     * Remove any required values for this control from the list, throwing an exception if they are missing.
119
     **/
120
    @Override
121
    void claimRequiredValues(List values) {
122
        for (int i = 0; i < getButtons().length; i++) {
1✔
123
            getButtons()[i].claimRequiredValues(values);
1✔
124
        }
125
    }
1✔
126

127
    @Override
128
    protected void claimUniqueValue(List values) {
129
        int matchingButtonIndex = -1;
1✔
130
        for (int i = 0; i < getButtons().length && matchingButtonIndex < 0; i++) {
1✔
131
            if (!getButtons()[i].isReadOnly() && values.contains(getButtons()[i].getQueryValue())) {
1✔
132
                matchingButtonIndex = i;
1✔
133
            }
134
        }
135
        if (matchingButtonIndex < 0) {
1✔
136
            throw new IllegalParameterValueException(getButtons()[0].getName(), values, getAllowedValues());
1✔
137
        }
138

139
        boolean wasChecked = getButtons()[matchingButtonIndex].isChecked();
1✔
140
        for (int i = 0; i < getButtons().length; i++) {
1✔
141
            if (!getButtons()[i].isReadOnly()) {
1✔
142
                getButtons()[i].setChecked(i == matchingButtonIndex);
1✔
143
            }
144
        }
145
        values.remove(getButtons()[matchingButtonIndex].getQueryValue());
1✔
146
        if (!wasChecked) {
1✔
147
            getButtons()[matchingButtonIndex].sendOnClickEvent();
1✔
148
        }
149
    }
1✔
150

151
    @Override
152
    protected void reset() {
153
        for (int i = 0; i < getButtons().length; i++) {
×
154
            getButtons()[i].reset();
×
155
        }
156
    }
×
157

158
    /**
159
     * Gets the allowed values.
160
     *
161
     * @return the allowed values
162
     */
163
    private String[] getAllowedValues() {
164
        if (_allowedValues == null) {
1!
165
            _allowedValues = new String[getButtons().length];
1✔
166
            for (int i = 0; i < _allowedValues.length; i++) {
1✔
167
                _allowedValues[i] = getButtons()[i].getQueryValue();
1✔
168
            }
169
        }
170
        return _allowedValues;
1✔
171
    }
172

173
    /**
174
     * Gets the buttons.
175
     *
176
     * @return the buttons
177
     */
178
    private RadioButtonFormControl[] getButtons() {
179
        if (_buttons == null) {
1✔
180
            _buttons = (RadioButtonFormControl[]) _buttonList.toArray(new RadioButtonFormControl[_buttonList.size()]);
1✔
181
        }
182
        return _buttons;
1✔
183
    }
184
}
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