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

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

80.0
/Source/JNA/waffle-tests/src/main/java/waffle/mock/http/SimpleHttpResponse.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.io.ByteArrayOutputStream;
10
import java.io.IOException;
11
import java.io.OutputStreamWriter;
12
import java.io.PrintWriter;
13
import java.nio.charset.StandardCharsets;
14
import java.util.ArrayList;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18

19
import javax.servlet.ServletOutputStream;
20
import javax.servlet.WriteListener;
21
import javax.servlet.http.HttpServletResponse;
22
import javax.servlet.http.HttpServletResponseWrapper;
23

24
import org.mockito.Mockito;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

28
/**
29
 * The Class SimpleHttpResponse.
30
 */
31
public class SimpleHttpResponse extends HttpServletResponseWrapper {
32

33
    /** The Constant LOGGER. */
34
    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleHttpResponse.class);
2✔
35

36
    /** The status. */
37
    private int status = 500;
2✔
38

39
    /** The headers. */
40
    private final Map<String, List<String>> headers = new HashMap<>();
2✔
41

42
    /** The bytes. */
43
    private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
2✔
44

45
    /** The out. */
46
    private final ServletOutputStream out = new ServletOutputStream() {
2✔
47
        @Override
48
        public void write(final int b) {
49
            SimpleHttpResponse.this.bytes.write(b);
×
50
        }
×
51

52
        @Override
53
        public boolean isReady() {
54
            return false;
×
55
        }
56

57
        @Override
58
        public void setWriteListener(final WriteListener writeListener) {
59
            // Not used
60
        }
×
61
    };
62

63
    /** The writer. */
64
    private final PrintWriter writer = new PrintWriter(new OutputStreamWriter(this.bytes, StandardCharsets.UTF_8),
2✔
65
            true);
66

67
    /**
68
     * Instantiates a new simple http response.
69
     */
70
    public SimpleHttpResponse() {
71
        super(Mockito.mock(HttpServletResponse.class));
2✔
72
    }
2✔
73

74
    /**
75
     * Gets the status.
76
     *
77
     * @return the status
78
     */
79
    @Override
80
    public int getStatus() {
81
        return this.status;
2✔
82
    }
83

84
    @Override
85
    public void addHeader(final String headerName, final String headerValue) {
86
        List<String> current = this.headers.get(headerName);
2✔
87
        if (current == null) {
2✔
88
            current = new ArrayList<>();
2✔
89
        }
90
        current.add(headerValue);
2✔
91
        this.headers.put(headerName, current);
2✔
92
    }
2✔
93

94
    @Override
95
    public void setHeader(final String headerName, final String headerValue) {
96
        List<String> current = this.headers.get(headerName);
2✔
97
        if (current == null) {
2!
98
            current = new ArrayList<>();
2✔
99
        } else {
100
            current.clear();
×
101
        }
102
        current.add(headerValue);
2✔
103
        this.headers.put(headerName, current);
2✔
104
    }
2✔
105

106
    @Override
107
    public void setStatus(final int value) {
108
        this.status = value;
2✔
109
    }
2✔
110

111
    /**
112
     * Gets the status string.
113
     *
114
     * @return the status string
115
     */
116
    public String getStatusString() {
117
        if (this.status == 401) {
2!
118
            return "Unauthorized";
2✔
119
        }
120
        return "Unknown";
×
121
    }
122

123
    @Override
124
    public void flushBuffer() {
125
        SimpleHttpResponse.LOGGER.info("{}: {}", Integer.valueOf(this.status), this.getStatusString());
2✔
126
        for (final Map.Entry<String, List<String>> header : this.headers.entrySet()) {
2✔
127
            for (final String headerValue : header.getValue()) {
2✔
128
                SimpleHttpResponse.LOGGER.info("{}: {}", header, headerValue);
2✔
129
            }
2✔
130
        }
2✔
131
    }
2✔
132

133
    /**
134
     * Use this for testing the number of headers.
135
     *
136
     * @return int header name size.
137
     */
138
    public int getHeaderNamesSize() {
139
        return this.headers.size();
2✔
140
    }
141

142
    /**
143
     * Gets the header values.
144
     *
145
     * @param headerName
146
     *            the header name
147
     *
148
     * @return the header values
149
     */
150
    public String[] getHeaderValues(final String headerName) {
151
        final List<String> headerValues = this.headers.get(headerName);
2✔
152
        return headerValues == null ? null : headerValues.toArray(new String[0]);
2!
153
    }
154

155
    /**
156
     * Gets the header.
157
     *
158
     * @param headerName
159
     *            the header name
160
     *
161
     * @return the header
162
     */
163
    @Override
164
    public String getHeader(final String headerName) {
165
        final List<String> headerValues = this.headers.get(headerName);
2✔
166
        return headerValues == null ? null : String.join(", ", headerValues);
2!
167
    }
168

169
    @Override
170
    public void sendError(final int rc, final String message) {
171
        this.status = rc;
×
172
    }
×
173

174
    @Override
175
    public void sendError(final int rc) {
176
        this.status = rc;
2✔
177
    }
2✔
178

179
    @Override
180
    public PrintWriter getWriter() {
181
        return this.writer;
2✔
182
    }
183

184
    @Override
185
    public ServletOutputStream getOutputStream() throws IOException {
186
        return this.out;
×
187
    }
188

189
    /**
190
     * Gets the output text.
191
     *
192
     * @return the output text
193
     */
194
    public String getOutputText() {
195
        this.writer.flush();
2✔
196
        return this.bytes.toString(StandardCharsets.UTF_8);
2✔
197
    }
198
}
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