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

Issue: SPR-13752
(cherry picked from commit a4f5c46)
This commit is contained in:
Juergen Hoeller
2015-12-02 13:36:35 +01:00
parent fad0c9589d
commit 79ded1ca72
3 changed files with 27 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -506,11 +506,12 @@ public class MockHttpServletResponse implements HttpServletResponse {
private boolean setSpecialHeader(String name, Object value) {
if (CONTENT_TYPE_HEADER.equalsIgnoreCase(name)) {
setContentType((String) value);
setContentType(value.toString());
return true;
}
else if (CONTENT_LENGTH_HEADER.equalsIgnoreCase(name)) {
setContentLength(Integer.parseInt((String) value));
setContentLength(value instanceof Number ? ((Number) value).intValue() :
Integer.parseInt(value.toString()));
return true;
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -122,6 +122,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";
@@ -221,20 +228,14 @@ public class MockHttpServletResponseTests {
assertEquals(redirectUrl, response.getRedirectedUrl());
}
/**
* 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);