|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 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.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.web.servlet.error;
|
18 | 18 |
|
| 19 | +import java.time.Clock; |
| 20 | +import java.util.Map; |
| 21 | + |
19 | 22 | import org.junit.jupiter.api.Test;
|
20 | 23 | import org.junit.jupiter.api.extension.ExtendWith;
|
21 | 24 |
|
@@ -62,6 +65,22 @@ void renderContainsViewWithExceptionDetails() throws Exception {
|
62 | 65 | });
|
63 | 66 | }
|
64 | 67 |
|
| 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 | + |
65 | 84 | @Test
|
66 | 85 | void renderWhenAlreadyCommittedLogsMessage(CapturedOutput output) {
|
67 | 86 | this.contextRunner.run((context) -> {
|
|
0 commit comments