MockHttpServletResponse.setIntHeader supports 'Content-Length' header as well

Issue: SPR-13752
This commit is contained in:
Juergen Hoeller
2015-12-02 13:36:35 +01:00
parent 4d4d2e2966
commit a4f5c46fed
3 changed files with 34 additions and 20 deletions

View File

@@ -19,7 +19,6 @@ package org.springframework.mock.web;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
@@ -92,9 +91,7 @@ public class MockHttpServletResponseTests {
assertEquals("UTF-8", response.getCharacterEncoding());
}
// SPR-12677
@Test
@Test // SPR-12677
public void contentTypeHeaderWithMoreComplexCharsetSyntax() {
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
response.setHeader("Content-Type", contentType);
@@ -141,6 +138,13 @@ public class MockHttpServletResponseTests {
assertEquals("66", response.getHeader("Content-Length"));
}
@Test
public void contentLengthIntHeader() {
response.addIntHeader("Content-Length", 66);
assertEquals(66, response.getContentLength());
assertEquals("66", response.getHeader("Content-Length"));
}
@Test
public void httpHeaderNameCasingIsPreserved() throws Exception {
final String headerName = "Header1";
@@ -269,20 +273,14 @@ public class MockHttpServletResponseTests {
response.getDateHeader("Last-Modified");
}
/**
* SPR-10414
*/
@Test
@Test // SPR-10414
public void modifyStatusAfterSendError() throws IOException {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
response.setStatus(HttpServletResponse.SC_OK);
assertEquals(response.getStatus(),HttpServletResponse.SC_NOT_FOUND);
}
/**
* SPR-10414
*/
@Test
@Test // SPR-10414
@SuppressWarnings("deprecation")
public void modifyStatusMessageAfterSendError() throws IOException {
response.sendError(HttpServletResponse.SC_NOT_FOUND);