• 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

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

13
import java.io.IOException;
14
import java.util.Enumeration;
15
import java.util.Hashtable;
16

17
/**
18
 * The Class UncheckedParameterHolder.
19
 */
20
final class UncheckedParameterHolder extends ParameterHolder implements ParameterProcessor {
21

22
    /** The Constant NO_VALUES. */
23
    private static final String[] NO_VALUES = {};
1✔
24

25
    /** The character set. */
26
    private final String _characterSet;
27

28
    /** The parameters. */
29
    private Hashtable _parameters = new Hashtable<>();
1✔
30

31
    /** The submit as mime. */
32
    private boolean _submitAsMime;
33

34
    /**
35
     * Instantiates a new unchecked parameter holder.
36
     */
37
    UncheckedParameterHolder() {
1✔
38
        _characterSet = HttpUnitOptions.getDefaultCharacterSet();
1✔
39
    }
1✔
40

41
    /**
42
     * Instantiates a new unchecked parameter holder.
43
     *
44
     * @param source
45
     *            the source
46
     */
47
    UncheckedParameterHolder(WebRequestSource source) {
1✔
48
        _characterSet = source.getCharacterSet();
1✔
49
        _submitAsMime = source.isSubmitAsMime();
1✔
50

51
        try {
52
            source.recordPredefinedParameters(this);
1✔
53
            source.recordParameters(this);
1✔
54
        } catch (IOException e) {
×
55
            throw new RuntimeException("This should never happen");
×
56
        }
1✔
57
    }
1✔
58

59
    // ----------------------------------- ParameterProcessor methods
60
    // -------------------------------------------------------
61

62
    @Override
63
    public void addParameter(String name, String value, String characterSet) throws IOException {
64
        Object[] values = (Object[]) _parameters.get(name);
1✔
65
        _parameters.put(name, HttpUnitUtils.withNewValue(values, value));
1✔
66
    }
1✔
67

68
    @Override
69
    public void addFile(String parameterName, UploadFileSpec fileSpec) throws IOException {
70
        Object[] values = (Object[]) _parameters.get(parameterName);
1✔
71
        _parameters.put(parameterName, HttpUnitUtils.withNewValue(values, fileSpec));
1✔
72
    }
1✔
73

74
    // ----------------------------------- ParameterHolder methods
75
    // ----------------------------------------------------------
76

77
    /**
78
     * Specifies the position at which an image button (if any) was clicked.
79
     **/
80
    @Override
81
    void selectImageButtonPosition(SubmitButton imageButton, int x, int y) {
82
        if (imageButton.isValidImageButton()) {
1!
83
            setParameter(imageButton.positionParameterName("x"), Integer.toString(x));
1✔
84
            setParameter(imageButton.positionParameterName("y"), Integer.toString(y));
1✔
85
        }
86
    }
1✔
87

88
    /**
89
     * Does nothing, since unchecked requests treat all parameters the same.
90
     **/
91
    @Override
92
    void recordPredefinedParameters(ParameterProcessor processor) throws IOException {
93
    }
1✔
94

95
    /**
96
     * Iterates through the parameters in this holder, recording them in the supplied parameter processor.
97
     **/
98
    @Override
99
    public void recordParameters(ParameterProcessor processor) throws IOException {
100
        Enumeration e = _parameters.keys();
1✔
101

102
        while (e.hasMoreElements()) {
1✔
103
            String name = (String) e.nextElement();
1✔
104
            Object[] values = (Object[]) _parameters.get(name);
1✔
105
            for (Object value : values) {
1✔
106
                if (value instanceof String || value == null) {
1✔
107
                    processor.addParameter(name, (String) value, _characterSet);
1✔
108
                } else if (value instanceof UploadFileSpec) {
1!
109
                    processor.addFile(name, (UploadFileSpec) value);
1✔
110
                }
111
            }
112
        }
1✔
113
    }
1✔
114

115
    @Override
116
    String[] getParameterNames() {
117
        return (String[]) _parameters.keySet().toArray(new String[_parameters.size()]);
×
118
    }
119

120
    /**
121
     * Gets the parameter value.
122
     *
123
     * @param name
124
     *            the name
125
     *
126
     * @return the parameter value
127
     */
128
    String getParameterValue(String name) {
129
        String[] values = getParameterValues(name);
×
130
        return values.length == 0 ? null : values[0];
×
131
    }
132

133
    @Override
134
    String[] getParameterValues(String name) {
135
        Object[] values = (Object[]) _parameters.get(name);
1✔
136
        if (values == null) {
1!
137
            return NO_VALUES;
×
138
        }
139

140
        String[] result = new String[values.length];
1✔
141
        for (int i = 0; i < result.length; i++) {
1✔
142
            result[i] = values[i] instanceof UploadFileSpec ? ((UploadFileSpec) values[i]).getFileName()
1✔
143
                    : values[i].toString();
1✔
144
        }
145
        return result;
1✔
146
    }
147

148
    @Override
149
    void removeParameter(String name) {
150
        _parameters.remove(name);
×
151
    }
×
152

153
    @Override
154
    void setParameter(String name, String value) {
155
        _parameters.put(name, new Object[] { value });
1✔
156
    }
1✔
157

158
    @Override
159
    void setParameter(String name, String[] values) {
160
        _parameters.put(name, values);
1✔
161
    }
1✔
162

163
    @Override
164
    void setParameter(String name, UploadFileSpec[] files) {
165
        _parameters.put(name, files);
1✔
166
    }
1✔
167

168
    @Override
169
    boolean isFileParameter(String name) {
170
        return true;
1✔
171
    }
172

173
    @Override
174
    String getCharacterSet() {
175
        return _characterSet;
1✔
176
    }
177

178
    @Override
179
    boolean isSubmitAsMime() {
180
        return _submitAsMime;
1✔
181
    }
182
}
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