Partial revert of SPR-13090

Use ServletHttpResponse.setDateHeader whenever possible and avoid using
SimpleDateFormat.
This commit is contained in:
Brian Clozel
2015-07-20 22:48:20 +02:00
parent 19fcb72d70
commit dba46c1358
6 changed files with 23 additions and 52 deletions

View File

@@ -177,7 +177,7 @@ public class DispatcherServletTests extends TestCase {
MockHttpServletResponse response = new MockHttpServletResponse();
simpleDispatcherServlet.service(request, response);
assertTrue("Not forwarded", response.getForwardedUrl() == null);
assertEquals("Wed, 01 Apr 2015 00:00:00 GMT", response.getHeader("Last-Modified"));
assertEquals("1427846400000", response.getHeader("Last-Modified"));
}
public void testUnknownRequest() throws Exception {
@@ -205,7 +205,7 @@ public class DispatcherServletTests extends TestCase {
assertTrue(request.getAttribute("test3") != null);
assertTrue(request.getAttribute("test3x") != null);
assertTrue(request.getAttribute("test3y") != null);
assertEquals("Wed, 01 Apr 2015 00:00:01 GMT", response.getHeader("Last-Modified"));
assertEquals("1427846401000", response.getHeader("Last-Modified"));
}
public void testExistingMultipartRequest() throws Exception {

View File

@@ -56,8 +56,6 @@ import org.springframework.web.servlet.HandlerMapping;
*/
public class ResourceHttpRequestHandlerTests {
private SimpleDateFormat dateFormat;
private ResourceHttpRequestHandler handler;
private MockHttpServletRequest request;
@@ -67,9 +65,6 @@ public class ResourceHttpRequestHandlerTests {
@Before
public void setUp() throws Exception {
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
List<Resource> paths = new ArrayList<>(2);
paths.add(new ClassPathResource("test/", getClass()));
paths.add(new ClassPathResource("testalternatepath/", getClass()));
@@ -136,7 +131,7 @@ public class ResourceHttpRequestHandlerTests {
assertEquals("no-cache", this.response.getHeader("Pragma"));
assertThat(this.response.getHeaderValues("Cache-Control"), Matchers.contains("no-cache", "no-store"));
assertEquals(this.response.getHeaderValue("Expires"), dateFormat.format(System.currentTimeMillis()));
assertTrue(headerAsLong("Expires") <= System.currentTimeMillis());
assertTrue(this.response.containsHeader("Last-Modified"));
assertEquals(headerAsLong("Last-Modified") / 1000, resourceLastModified("test/foo.css") / 1000);
}
@@ -477,7 +472,7 @@ public class ResourceHttpRequestHandlerTests {
private long headerAsLong(String responseHeaderName) throws Exception {
return dateFormat.parse(this.response.getHeader(responseHeaderName)).getTime();
return Long.valueOf(this.response.getHeader(responseHeaderName));
}
private long resourceLastModified(String resourceName) throws IOException {