• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

Waffle / waffle / 6516

11 Mar 2026 12:15AM UTC coverage: 46.217%. Remained the same
6516

push

github

web-flow
Update dependency org.eclipse.jdt:ecj to v3.45.0

276 of 734 branches covered (37.6%)

Branch coverage included in aggregate %.

1019 of 2068 relevant lines covered (49.27%)

1.0 hits per line

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

58.46
/Source/JNA/waffle-tests/src/main/java/waffle/mock/http/SimpleHttpRequest.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2010-2026 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
6
 */
7
package waffle.mock.http;
8

9
import java.security.Principal;
10
import java.util.Collections;
11
import java.util.Enumeration;
12
import java.util.HashMap;
13
import java.util.TreeMap;
14
import java.util.Map;
15

16
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletRequestWrapper;
18
import javax.servlet.http.HttpSession;
19

20
import org.mockito.Mockito;
21

22
/**
23
 * The Class SimpleHttpRequest.
24
 */
25
public class SimpleHttpRequest extends HttpServletRequestWrapper {
26

27
    /** The remote port s. */
28
    private static int remotePortS = 0;
2✔
29

30
    /** The request uri. */
31
    private String requestURI;
32

33
    /** The query string. */
34
    private String queryString;
35

36
    /** The remote user. */
37
    private String remoteUser;
38

39
    /** The method. */
40
    private String method = "GET";
2✔
41

42
    /** The remote host. */
43
    private String remoteHost;
44

45
    /** The remote addr. */
46
    private String remoteAddr;
47

48
    /** The remote port. */
49
    private int remotePort = -1;
2✔
50

51
    /** The headers. */
52
    private final Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
2✔
53

54
    /** The parameters. */
55
    private final Map<String, String> parameters = new HashMap<>();
2✔
56

57
    /** The content. */
58
    private byte[] content;
59

60
    /** The session. */
61
    private HttpSession session = new SimpleHttpSession();
2✔
62

63
    /** The principal. */
64
    private Principal principal;
65

66
    /**
67
     * Instantiates a new simple http request.
68
     */
69
    public SimpleHttpRequest() {
70
        super(Mockito.mock(HttpServletRequest.class));
2✔
71
        this.remotePort = SimpleHttpRequest.nextRemotePort();
2✔
72
    }
2✔
73

74
    /**
75
     * Next remote port.
76
     *
77
     * @return the int
78
     */
79
    public static synchronized int nextRemotePort() {
80
        return ++SimpleHttpRequest.remotePortS;
2✔
81
    }
82

83
    /**
84
     * Reset remote port.
85
     */
86
    public static synchronized void resetRemotePort() {
87
        SimpleHttpRequest.remotePortS = 0;
2✔
88
    }
2✔
89

90
    /**
91
     * Adds the header.
92
     *
93
     * @param headerName
94
     *            the header name
95
     * @param headerValue
96
     *            the header value
97
     */
98
    public void addHeader(final String headerName, final String headerValue) {
99
        this.headers.put(headerName, headerValue);
2✔
100
    }
2✔
101

102
    @Override
103
    public String getHeader(final String headerName) {
104
        return this.headers.get(headerName);
2✔
105
    }
106

107
    @Override
108
    public Enumeration<String> getHeaderNames() {
109
        return Collections.enumeration(this.headers.keySet());
2✔
110
    }
111

112
    @Override
113
    public String getMethod() {
114
        return this.method;
2✔
115
    }
116

117
    @Override
118
    public int getContentLength() {
119
        return this.content == null ? -1 : this.content.length;
2✔
120
    }
121

122
    @Override
123
    public int getRemotePort() {
124
        return this.remotePort;
2✔
125
    }
126

127
    /**
128
     * Sets the method.
129
     *
130
     * @param methodName
131
     *            the new method
132
     */
133
    public void setMethod(final String methodName) {
134
        this.method = methodName;
2✔
135
    }
2✔
136

137
    /**
138
     * Sets the content length.
139
     *
140
     * @param length
141
     *            the new content length
142
     */
143
    public void setContentLength(final int length) {
144
        this.content = new byte[length];
2✔
145
    }
2✔
146

147
    /**
148
     * Sets the remote user.
149
     *
150
     * @param username
151
     *            the new remote user
152
     */
153
    public void setRemoteUser(final String username) {
154
        this.remoteUser = username;
×
155
    }
×
156

157
    @Override
158
    public String getRemoteUser() {
159
        return this.remoteUser;
×
160
    }
161

162
    @Override
163
    public HttpSession getSession() {
164
        return this.session;
×
165
    }
166

167
    @Override
168
    public HttpSession getSession(final boolean create) {
169
        if (this.session == null && create) {
2!
170
            this.session = new SimpleHttpSession();
×
171
        }
172
        return this.session;
2✔
173
    }
174

175
    @Override
176
    public String getQueryString() {
177
        return this.queryString;
×
178
    }
179

180
    /**
181
     * Sets the query string.
182
     *
183
     * @param query
184
     *            the new query string
185
     */
186
    public void setQueryString(final String query) {
187
        this.queryString = query;
×
188
        if (this.queryString != null) {
×
189
            for (final String eachParameter : this.queryString.split("&", -1)) {
×
190
                final String[] pair = eachParameter.split("=", -1);
×
191
                final String value = pair.length == 2 ? pair[1] : "";
×
192
                this.addParameter(pair[0], value);
×
193
            }
194
        }
195
    }
×
196

197
    /**
198
     * Sets the request uri.
199
     *
200
     * @param uri
201
     *            the new request uri
202
     */
203
    public void setRequestURI(final String uri) {
204
        this.requestURI = uri;
×
205
    }
×
206

207
    @Override
208
    public String getRequestURI() {
209
        return this.requestURI;
2✔
210
    }
211

212
    @Override
213
    public String getParameter(final String parameterName) {
214
        return this.parameters.get(parameterName);
×
215
    }
216

217
    /**
218
     * Adds the parameter.
219
     *
220
     * @param parameterName
221
     *            the parameter name
222
     * @param parameterValue
223
     *            the parameter value
224
     */
225
    public void addParameter(final String parameterName, final String parameterValue) {
226
        this.parameters.put(parameterName, parameterValue);
×
227
    }
×
228

229
    @Override
230
    public String getRemoteHost() {
231
        return this.remoteHost;
2✔
232
    }
233

234
    /**
235
     * Sets the remote host.
236
     *
237
     * @param value
238
     *            the new remote host
239
     */
240
    public void setRemoteHost(final String value) {
241
        this.remoteHost = value;
2✔
242
    }
2✔
243

244
    @Override
245
    public String getRemoteAddr() {
246
        return this.remoteAddr;
2✔
247
    }
248

249
    /**
250
     * Sets the remote addr.
251
     *
252
     * @param value
253
     *            the new remote addr
254
     */
255
    public void setRemoteAddr(final String value) {
256
        this.remoteAddr = value;
2✔
257
    }
2✔
258

259
    @Override
260
    public Principal getUserPrincipal() {
261
        return this.principal;
2✔
262
    }
263

264
    /**
265
     * Sets the user principal.
266
     *
267
     * @param value
268
     *            the new user principal
269
     */
270
    public void setUserPrincipal(final Principal value) {
271
        this.principal = value;
2✔
272
    }
2✔
273
}
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