1
1
/*
2
- * Copyright 2002-2011 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
24
24
import java .io .UnsupportedEncodingException ;
25
25
import java .io .Writer ;
26
26
import java .util .ArrayList ;
27
+ import java .util .Collection ;
27
28
import java .util .Collections ;
28
29
import java .util .List ;
29
30
import java .util .Locale ;
30
31
import java .util .Map ;
31
- import java .util .Set ;
32
32
import javax .servlet .ServletOutputStream ;
33
33
import javax .servlet .http .Cookie ;
34
34
import javax .servlet .http .HttpServletResponse ;
@@ -51,9 +51,10 @@ public class MockHttpServletResponse implements HttpServletResponse {
51
51
private static final String CHARSET_PREFIX = "charset=" ;
52
52
53
53
private static final String CONTENT_TYPE_HEADER = "Content-Type" ;
54
-
54
+
55
55
private static final String CONTENT_LENGTH_HEADER = "Content-Length" ;
56
56
57
+
57
58
//---------------------------------------------------------------------
58
59
// ServletResponse properties
59
60
//---------------------------------------------------------------------
@@ -63,7 +64,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
63
64
private boolean writerAccessAllowed = true ;
64
65
65
66
private String characterEncoding = WebUtils .DEFAULT_CHARACTER_ENCODING ;
66
-
67
+
67
68
private boolean charset = false ;
68
69
69
70
private final ByteArrayOutputStream content = new ByteArrayOutputStream ();
@@ -108,7 +109,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
108
109
109
110
/**
110
111
* Set whether {@link #getOutputStream()} access is allowed.
111
- * <p>Default is < code> true</code> .
112
+ * <p>Default is {@ code true} .
112
113
*/
113
114
public void setOutputStreamAccessAllowed (boolean outputStreamAccessAllowed ) {
114
115
this .outputStreamAccessAllowed = outputStreamAccessAllowed ;
@@ -123,7 +124,7 @@ public boolean isOutputStreamAccessAllowed() {
123
124
124
125
/**
125
126
* Set whether {@link #getWriter()} access is allowed.
126
- * <p>Default is < code> true</code> .
127
+ * <p>Default is {@ code true} .
127
128
*/
128
129
public void setWriterAccessAllowed (boolean writerAccessAllowed ) {
129
130
this .writerAccessAllowed = writerAccessAllowed ;
@@ -141,17 +142,17 @@ public void setCharacterEncoding(String characterEncoding) {
141
142
this .charset = true ;
142
143
updateContentTypeHeader ();
143
144
}
144
-
145
+
145
146
private void updateContentTypeHeader () {
146
147
if (this .contentType != null ) {
147
148
StringBuilder sb = new StringBuilder (this .contentType );
148
- if (this .contentType .toLowerCase ().indexOf (CHARSET_PREFIX ) == - 1 && this .charset ) {
149
+ if (! this .contentType .toLowerCase ().contains (CHARSET_PREFIX ) && this .charset ) {
149
150
sb .append (";" ).append (CHARSET_PREFIX ).append (this .characterEncoding );
150
151
}
151
152
doAddHeaderValue (CONTENT_TYPE_HEADER , sb .toString (), true );
152
153
}
153
154
}
154
-
155
+
155
156
public String getCharacterEncoding () {
156
157
return this .characterEncoding ;
157
158
}
@@ -297,20 +298,20 @@ public boolean containsHeader(String name) {
297
298
/**
298
299
* Return the names of all specified headers as a Set of Strings.
299
300
* <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
300
- * @return the < code> Set</code> of header name < code> Strings</code> , or an empty < code> Set</code> if none
301
+ * @return the {@ code Set} of header name {@ code Strings} , or an empty {@ code Set} if none
301
302
*/
302
- public Set <String > getHeaderNames () {
303
+ public Collection <String > getHeaderNames () {
303
304
return this .headers .keySet ();
304
305
}
305
306
306
307
/**
307
308
* Return the primary value for the given header as a String, if any.
308
309
* Will return the first value in case of multiple values.
309
- * <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
310
+ * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
310
311
* As of Spring 3.1, it returns a stringified value for Servlet 3.0 compatibility.
311
312
* Consider using {@link #getHeaderValue(String)} for raw Object access.
312
313
* @param name the name of the header
313
- * @return the associated header value, or < code> null<code> if none
314
+ * @return the associated header value, or {@ code null} if none
314
315
*/
315
316
public String getHeader (String name ) {
316
317
HeaderValueHolder header = HeaderValueHolder .getByName (this .headers , name );
@@ -319,7 +320,7 @@ public String getHeader(String name) {
319
320
320
321
/**
321
322
* Return all values for the given header as a List of Strings.
322
- * <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
323
+ * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
323
324
* As of Spring 3.1, it returns a List of stringified values for Servlet 3.0 compatibility.
324
325
* Consider using {@link #getHeaderValues(String)} for raw Object access.
325
326
* @param name the name of the header
@@ -339,7 +340,7 @@ public List<String> getHeaders(String name) {
339
340
* Return the primary value for the given header, if any.
340
341
* <p>Will return the first value in case of multiple values.
341
342
* @param name the name of the header
342
- * @return the associated header value, or < code> null<code> if none
343
+ * @return the associated header value, or {@ code null} if none
343
344
*/
344
345
public Object getHeaderValue (String name ) {
345
346
HeaderValueHolder header = HeaderValueHolder .getByName (this .headers , name );
@@ -374,7 +375,7 @@ public String encodeURL(String url) {
374
375
* returning the given URL String as-is.
375
376
* <p>Can be overridden in subclasses, appending a session id or the like
376
377
* in a redirect-specific fashion. For general URL encoding rules,
377
- * override the common {@link #encodeURL} method instead, appyling
378
+ * override the common {@link #encodeURL} method instead, applying
378
379
* to redirect URLs as well as to general URLs.
379
380
*/
380
381
public String encodeRedirectURL (String url ) {
@@ -456,7 +457,7 @@ private void addHeaderValue(String name, Object value) {
456
457
}
457
458
doAddHeaderValue (name , value , false );
458
459
}
459
-
460
+
460
461
private boolean setSpecialHeader (String name , Object value ) {
461
462
if (CONTENT_TYPE_HEADER .equalsIgnoreCase (name )) {
462
463
setContentType ((String ) value );
0 commit comments