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

Waffle / waffle / 6364

01 Feb 2026 02:07AM UTC coverage: 46.217%. Remained the same
6364

push

github

web-flow
Merge pull request #3206 from Waffle/renovate/checkstyle.version

Update dependency com.puppycrawl.tools:checkstyle to v13.1.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.Map;
14

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

19
import org.mockito.Mockito;
20

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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