• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/src/main/java/com/meterware/pseudoserver/HttpUserAgentTest.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.pseudoserver;
21

22
import static org.junit.jupiter.api.Assertions.assertEquals;
23
import static org.junit.jupiter.api.Assertions.fail;
24

25
import java.io.IOException;
26
import java.util.Enumeration;
27
import java.util.StringTokenizer;
28
import java.util.Vector;
29

30
import org.junit.jupiter.api.extension.RegisterExtension;
31

32
/**
33
 * A base class for test cases that use the pseudo server.
34
 **/
35
public class HttpUserAgentTest {
1✔
36

37
    @RegisterExtension
38
    public static final PseudoServerTestSupport testSupport = new PseudoServerTestSupport();
1✔
39

40
    protected void defineResource(String resourceName, PseudoServlet servlet) {
41
        testSupport.defineResource(resourceName, servlet);
1✔
42
    }
1✔
43

44
    protected void defineResource(String resourceName, String value) {
45
        testSupport.defineResource(resourceName, value);
1✔
46
    }
1✔
47

48
    protected void defineResource(String resourceName, byte[] value, String contentType) {
49
        testSupport.defineResource(resourceName, value, contentType);
1✔
50
    }
1✔
51

52
    protected void defineResource(String resourceName, String value, int statusCode) {
53
        testSupport.defineResource(resourceName, value, statusCode);
1✔
54
    }
1✔
55

56
    protected void defineResource(String resourceName, String value, String contentType) {
57
        testSupport.defineResource(resourceName, value, contentType);
1✔
58
    }
1✔
59

60
    protected void addResourceHeader(String resourceName, String header) {
61
        testSupport.addResourceHeader(resourceName, header);
1✔
62
    }
1✔
63

64
    protected void setResourceCharSet(String resourceName, String setName, boolean reportCharSet) {
65
        testSupport.setResourceCharSet(resourceName, setName, reportCharSet);
1✔
66
    }
1✔
67

68
    /**
69
     * define a Web Page with the given page name and boy adding the html and body tags with pageName as the title of
70
     * the page use the given xml names space if it is not null
71
     *
72
     * @param xmlns
73
     * @param pageName
74
     * @param body
75
     */
76
    protected void defineWebPage(String xmlns, String pageName, String body) {
77
        testSupport.defineWebPage(xmlns, pageName, body);
1✔
78
    }
1✔
79

80
    /**
81
     * define a Web Page with the given page name and boy adding the html and body tags with pageName as the title of
82
     * the page
83
     *
84
     * @param pageName
85
     * @param body
86
     */
87
    protected void defineWebPage(String pageName, String body) {
88
        testSupport.defineWebPage(pageName, body);
1✔
89
    }
1✔
90

91
    protected void mapToClasspath(String directory) {
92
        testSupport.mapToClasspath(directory);
1✔
93
    }
1✔
94

95
    protected PseudoServer getServer() {
96
        return testSupport.getServer();
×
97
    }
98

99
    protected void setServerDebug(boolean enabled) {
100
        testSupport.setServerDebug(enabled);
×
101
    }
×
102

103
    protected String getHostPath() {
104
        return testSupport.getHostPath();
1✔
105
    }
106

107
    protected int getHostPort() throws IOException {
108
        return testSupport.getHostPort();
1✔
109
    }
110

111
    protected void assertEqualQueries(String query1, String query2) {
112
        assertEquals(new QuerySpec(query1), new QuerySpec(query2));
1✔
113
    }
1✔
114

115
    protected void assertImplement(String comment, Object[] objects, Class expectedClass) {
116
        if (objects.length == 0) {
1!
117
            fail("No " + comment + " found.");
×
118
        }
119
        for (Object object : objects) {
1✔
120
            assertImplements(comment, object, expectedClass);
1✔
121
        }
122
    }
1✔
123

124
    protected void assertImplements(String comment, Object object, Class expectedClass) {
125
        if (object == null) {
1!
126
            fail(comment + " should be of class " + expectedClass.getName() + " but is null");
×
127
        } else if (!expectedClass.isInstance(object)) {
1!
128
            fail(comment + " should be of class " + expectedClass.getName() + " but is " + object.getClass().getName());
×
129
        }
130
    }
1✔
131

132
    protected void assertMatchingSet(String comment, Object[] expected, Enumeration found) {
133
        Vector foundItems = new Vector<>();
1✔
134
        while (found.hasMoreElements()) {
1✔
135
            foundItems.addElement(found.nextElement());
1✔
136
        }
137

138
        assertMatchingSet(comment, expected, foundItems);
1✔
139
    }
1✔
140

141
    private void assertMatchingSet(String comment, Object[] expected, Vector foundItems) {
142
        Vector expectedItems = new Vector<>();
1✔
143
        for (Object element : expected) {
1✔
144
            expectedItems.addElement(element);
1✔
145
        }
146
        for (Object element : expected) {
1✔
147
            if (!foundItems.contains(element)) {
1!
148
                fail(comment + ": expected " + asText(expected) + " but missing " + element);
×
149
            } else {
150
                foundItems.removeElement(element);
1✔
151
            }
152
        }
153

154
        if (!foundItems.isEmpty()) {
1!
155
            fail(comment + ": expected " + asText(expected) + " but found superfluous" + foundItems.firstElement());
×
156
        }
157
    }
1✔
158

159
    public static void assertMatchingSet(String comment, Object[] expected, Object[] found) {
160
        Vector foundItems = new Vector<>();
1✔
161
        for (Object element : found) {
1✔
162
            foundItems.addElement(element);
1✔
163
        }
164

165
        Vector expectedItems = new Vector<>();
1✔
166

167
        for (Object element : expected) {
1✔
168
            expectedItems.addElement(element);
1✔
169
        }
170

171
        for (Object element : expected) {
1✔
172
            if (!foundItems.contains(element)) {
1!
173
                fail(comment + ": expected " + asText(expected) + " but found " + asText(found));
×
174
            } else {
175
                foundItems.removeElement(element);
1✔
176
            }
177
        }
178

179
        for (Object element : found) {
1✔
180
            if (!expectedItems.contains(element)) {
1!
181
                fail(comment + ": expected " + asText(expected) + " but found " + asText(found));
×
182
            } else {
183
                expectedItems.removeElement(element);
1✔
184
            }
185
        }
186

187
        if (!foundItems.isEmpty()) {
1!
188
            fail(comment + ": expected " + asText(expected) + " but found " + asText(found));
×
189
        }
190
    }
1✔
191

192
    public static String asText(Object[] args) {
193
        StringBuilder sb = new StringBuilder("{");
×
194
        for (int i = 0; i < args.length; i++) {
×
195
            if (i != 0) {
×
196
                sb.append(",");
×
197
            }
198
            sb.append('"').append(args[i]).append('"');
×
199
        }
200
        sb.append("}");
×
201
        return sb.toString();
×
202
    }
203

204
    protected String asBytes(String s) {
205
        StringBuilder sb = new StringBuilder();
×
206
        char[] chars = s.toCharArray();
×
207
        for (char element : chars) {
×
208
            sb.append(Integer.toHexString(element)).append(" ");
×
209
        }
210
        return sb.toString();
×
211
    }
212

213
    static class QuerySpec {
214
        QuerySpec(String urlString) {
1✔
215
            if (urlString.indexOf('?') < 0) {
1!
216
                _path = urlString;
×
217
            } else {
218
                _path = urlString.substring(0, urlString.indexOf('?'));
1✔
219
            }
220
            _fullString = urlString;
1✔
221

222
            StringTokenizer st = new StringTokenizer(urlString.substring(urlString.indexOf('?') + 1), "&");
1✔
223
            while (st.hasMoreTokens()) {
1✔
224
                _parameters.addElement(st.nextToken());
1✔
225
            }
226
        }
1✔
227

228
        @Override
229
        public String toString() {
230
            return _fullString;
×
231
        }
232

233
        @Override
234
        public boolean equals(Object o) {
235
            return getClass().equals(o.getClass()) && equals((QuerySpec) o);
1!
236
        }
237

238
        @Override
239
        public int hashCode() {
240
            return _path.hashCode() ^ _parameters.size();
×
241
        }
242

243
        private String _path;
244
        private String _fullString;
245
        private Vector _parameters = new Vector<>();
1✔
246

247
        private boolean equals(QuerySpec o) {
248
            if (!_path.equals(o._path) || _parameters.size() != o._parameters.size()) {
1!
249
                return false;
×
250
            }
251
            for (Enumeration e = o._parameters.elements(); e.hasMoreElements();) {
1✔
252
                if (!_parameters.contains(e.nextElement())) {
1!
253
                    return false;
×
254
                }
255
            }
256
            return true;
1✔
257
        }
258
    }
259
}
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