• 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

83.33
/src/main/java/com/meterware/httpunit/UncheckedParameterHolder.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.protocol.ParameterProcessor;
23
import com.meterware.httpunit.protocol.UploadFileSpec;
24

25
import java.io.IOException;
26
import java.util.Enumeration;
27
import java.util.Hashtable;
28

29
/**
30
 * The Class UncheckedParameterHolder.
31
 */
32
final class UncheckedParameterHolder extends ParameterHolder implements ParameterProcessor {
33

34
    /** The Constant NO_VALUES. */
35
    private static final String[] NO_VALUES = {};
1✔
36

37
    /** The character set. */
38
    private final String _characterSet;
39

40
    /** The parameters. */
41
    private Hashtable _parameters = new Hashtable<>();
1✔
42

43
    /** The submit as mime. */
44
    private boolean _submitAsMime;
45

46
    /**
47
     * Instantiates a new unchecked parameter holder.
48
     */
49
    UncheckedParameterHolder() {
1✔
50
        _characterSet = HttpUnitOptions.getDefaultCharacterSet();
1✔
51
    }
1✔
52

53
    /**
54
     * Instantiates a new unchecked parameter holder.
55
     *
56
     * @param source
57
     *            the source
58
     */
59
    UncheckedParameterHolder(WebRequestSource source) {
1✔
60
        _characterSet = source.getCharacterSet();
1✔
61
        _submitAsMime = source.isSubmitAsMime();
1✔
62

63
        try {
64
            source.recordPredefinedParameters(this);
1✔
65
            source.recordParameters(this);
1✔
66
        } catch (IOException e) {
×
67
            throw new RuntimeException("This should never happen");
×
68
        }
1✔
69
    }
1✔
70

71
    // ----------------------------------- ParameterProcessor methods
72
    // -------------------------------------------------------
73

74
    @Override
75
    public void addParameter(String name, String value, String characterSet) throws IOException {
76
        Object[] values = (Object[]) _parameters.get(name);
1✔
77
        _parameters.put(name, HttpUnitUtils.withNewValue(values, value));
1✔
78
    }
1✔
79

80
    @Override
81
    public void addFile(String parameterName, UploadFileSpec fileSpec) throws IOException {
82
        Object[] values = (Object[]) _parameters.get(parameterName);
1✔
83
        _parameters.put(parameterName, HttpUnitUtils.withNewValue(values, fileSpec));
1✔
84
    }
1✔
85

86
    // ----------------------------------- ParameterHolder methods
87
    // ----------------------------------------------------------
88

89
    /**
90
     * Specifies the position at which an image button (if any) was clicked.
91
     **/
92
    @Override
93
    void selectImageButtonPosition(SubmitButton imageButton, int x, int y) {
94
        if (imageButton.isValidImageButton()) {
1!
95
            setParameter(imageButton.positionParameterName("x"), Integer.toString(x));
1✔
96
            setParameter(imageButton.positionParameterName("y"), Integer.toString(y));
1✔
97
        }
98
    }
1✔
99

100
    /**
101
     * Does nothing, since unchecked requests treat all parameters the same.
102
     **/
103
    @Override
104
    void recordPredefinedParameters(ParameterProcessor processor) throws IOException {
105
    }
1✔
106

107
    /**
108
     * Iterates through the parameters in this holder, recording them in the supplied parameter processor.
109
     **/
110
    @Override
111
    public void recordParameters(ParameterProcessor processor) throws IOException {
112
        Enumeration e = _parameters.keys();
1✔
113

114
        while (e.hasMoreElements()) {
1✔
115
            String name = (String) e.nextElement();
1✔
116
            Object[] values = (Object[]) _parameters.get(name);
1✔
117
            for (Object value : values) {
1✔
118
                if (value instanceof String || value == null) {
1✔
119
                    processor.addParameter(name, (String) value, _characterSet);
1✔
120
                } else if (value instanceof UploadFileSpec) {
1!
121
                    processor.addFile(name, (UploadFileSpec) value);
1✔
122
                }
123
            }
124
        }
1✔
125
    }
1✔
126

127
    @Override
128
    String[] getParameterNames() {
129
        return (String[]) _parameters.keySet().toArray(new String[_parameters.size()]);
×
130
    }
131

132
    /**
133
     * Gets the parameter value.
134
     *
135
     * @param name
136
     *            the name
137
     *
138
     * @return the parameter value
139
     */
140
    String getParameterValue(String name) {
141
        String[] values = getParameterValues(name);
×
142
        return values.length == 0 ? null : values[0];
×
143
    }
144

145
    @Override
146
    String[] getParameterValues(String name) {
147
        Object[] values = (Object[]) _parameters.get(name);
1✔
148
        if (values == null) {
1!
149
            return NO_VALUES;
×
150
        }
151

152
        String[] result = new String[values.length];
1✔
153
        for (int i = 0; i < result.length; i++) {
1✔
154
            result[i] = values[i] instanceof UploadFileSpec ? ((UploadFileSpec) values[i]).getFileName()
1✔
155
                    : values[i].toString();
1✔
156
        }
157
        return result;
1✔
158
    }
159

160
    @Override
161
    void removeParameter(String name) {
162
        _parameters.remove(name);
×
163
    }
×
164

165
    @Override
166
    void setParameter(String name, String value) {
167
        _parameters.put(name, new Object[] { value });
1✔
168
    }
1✔
169

170
    @Override
171
    void setParameter(String name, String[] values) {
172
        _parameters.put(name, values);
1✔
173
    }
1✔
174

175
    @Override
176
    void setParameter(String name, UploadFileSpec[] files) {
177
        _parameters.put(name, files);
1✔
178
    }
1✔
179

180
    @Override
181
    boolean isFileParameter(String name) {
182
        return true;
1✔
183
    }
184

185
    @Override
186
    String getCharacterSet() {
187
        return _characterSet;
1✔
188
    }
189

190
    @Override
191
    boolean isSubmitAsMime() {
192
        return _submitAsMime;
1✔
193
    }
194
}
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