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

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

0.81 hits per line

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

66.67
/src/main/java/com/meterware/servletunit/ServletUnitWebResponse.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.servletunit;
21

22
import com.meterware.httpunit.FrameSelector;
23
import com.meterware.httpunit.WebResponse;
24

25
import java.io.ByteArrayInputStream;
26
import java.io.IOException;
27
import java.net.HttpURLConnection;
28
import java.net.URL;
29

30
import javax.servlet.http.HttpServletResponse;
31

32
/**
33
 * A response from to a request from the simulated servlet environment.
34
 **/
35
class ServletUnitWebResponse extends WebResponse {
36

37
    /**
38
     * Constructs a response object from a servlet response.
39
     *
40
     * @param client
41
     *            the client
42
     * @param frame
43
     *            the target frame on which the response will be displayed
44
     * @param url
45
     *            the url from which the response was received
46
     * @param response
47
     *            the response populated by the servlet
48
     * @param throwExceptionOnError
49
     *            the throw exception on error
50
     *
51
     * @throws IOException
52
     *             Signals that an I/O exception has occurred.
53
     */
54
    ServletUnitWebResponse(ServletUnitClient client, FrameSelector frame, URL url, HttpServletResponse response,
55
            boolean throwExceptionOnError) throws IOException {
56
        super(client, frame, url);
1✔
57
        _response = (ServletUnitHttpResponse) response;
1✔
58
        /** make sure that any IO exception for HTML received page happens here, not later. **/
59
        if (getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST || !throwExceptionOnError) {
1!
60
            defineRawInputStream(new ByteArrayInputStream(_response.getContents()));
1✔
61
            if (getContentType().startsWith("text")) {
1!
62
                loadResponseText();
1✔
63
            }
64
        }
65
    }
1✔
66

67
    /**
68
     * Constructs a response object from a servlet response.
69
     *
70
     * @param client
71
     *            the client
72
     * @param frame
73
     *            the target frame on which the response will be displayed
74
     * @param url
75
     *            the url from which the response was received
76
     * @param response
77
     *            the response populated by the servlet
78
     *
79
     * @throws IOException
80
     *             Signals that an I/O exception has occurred.
81
     */
82
    ServletUnitWebResponse(ServletUnitClient client, FrameSelector frame, URL url, HttpServletResponse response)
83
            throws IOException {
84
        this(client, frame, url, response, true);
1✔
85
    }
1✔
86

87
    /**
88
     * Returns the response code associated with this response.
89
     **/
90
    @Override
91
    public int getResponseCode() {
92
        return _response.getStatus();
1✔
93
    }
94

95
    /**
96
     * Returns the response message associated with this response.
97
     **/
98
    @Override
99
    public String getResponseMessage() {
100
        return _response.getMessage();
×
101
    }
102

103
    @Override
104
    public String[] getHeaderFieldNames() {
105
        return _response.getHeaderFieldNames();
×
106
    }
107

108
    /**
109
     * Returns the value for the specified header field. If no such field is defined, will return null.
110
     **/
111
    @Override
112
    public String getHeaderField(String fieldName) {
113
        return _response.getHeaderField(fieldName);
1✔
114
    }
115

116
    @Override
117
    public String[] getHeaderFields(String fieldName) {
118
        return _response.getHeaderFields(fieldName);
1✔
119
    }
120

121
    @Override
122
    public String toString() {
123
        return "[ _response = " + _response + "]";
×
124
    }
125

126
    // -------------------------------------------- private members ------------------------------------------------
127

128
    /** The response. */
129
    private ServletUnitHttpResponse _response;
130

131
}
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