Skip to content

Commit d8232b3

Browse files
committed
Polish 'Allow other "timestamp" types in MVC error model'
See gh-23256
1 parent d1d9538 commit d8232b3

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.autoconfigure.web.servlet.error;
1818

1919
import java.nio.charset.StandardCharsets;
20-
import java.util.Date;
2120
import java.util.Map;
2221
import java.util.stream.Collectors;
2322

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfigurationTests.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.boot.autoconfigure.web.servlet.error;
1818

19+
import java.time.Clock;
20+
import java.util.Map;
21+
1922
import org.junit.jupiter.api.Test;
2023
import org.junit.jupiter.api.extension.ExtendWith;
2124

@@ -62,6 +65,22 @@ void renderContainsViewWithExceptionDetails() throws Exception {
6265
});
6366
}
6467

68+
@Test
69+
void renderCanUseJavaTimeTypeAsTimestamp() throws Exception { // gh-23256
70+
this.contextRunner.run((context) -> {
71+
View errorView = context.getBean("error", View.class);
72+
ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class);
73+
DispatcherServletWebRequest webRequest = createWebRequest(new IllegalStateException("Exception message"),
74+
false);
75+
Map<String, Object> attributes = errorAttributes.getErrorAttributes(webRequest, true);
76+
attributes.put("timestamp", Clock.systemUTC().instant());
77+
errorView.render(attributes, webRequest.getRequest(), webRequest.getResponse());
78+
assertThat(webRequest.getResponse().getContentType()).isEqualTo("text/html;charset=UTF-8");
79+
String responseString = ((MockHttpServletResponse) webRequest.getResponse()).getContentAsString();
80+
assertThat(responseString).contains("This application has no explicit mapping for /error");
81+
});
82+
}
83+
6584
@Test
6685
void renderWhenAlreadyCommittedLogsMessage(CapturedOutput output) {
6786
this.contextRunner.run((context) -> {

0 commit comments

Comments
 (0)