Polish 'Allow other "timestamp" types in MVC error model'
See gh-23256
This commit is contained in:
		
							parent
							
								
									d1d953819a
								
							
						
					
					
						commit
						d8232b3c21
					
				|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2019 the original author or authors. | ||||
|  * Copyright 2012-2020 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. | ||||
|  | @ -17,7 +17,6 @@ | |||
| package org.springframework.boot.autoconfigure.web.servlet.error; | ||||
| 
 | ||||
| import java.nio.charset.StandardCharsets; | ||||
| import java.util.Date; | ||||
| import java.util.Map; | ||||
| import java.util.stream.Collectors; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /* | ||||
|  * Copyright 2012-2019 the original author or authors. | ||||
|  * Copyright 2012-2020 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. | ||||
|  | @ -16,6 +16,9 @@ | |||
| 
 | ||||
| package org.springframework.boot.autoconfigure.web.servlet.error; | ||||
| 
 | ||||
| import java.time.Clock; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import org.junit.jupiter.api.Test; | ||||
| import org.junit.jupiter.api.extension.ExtendWith; | ||||
| 
 | ||||
|  | @ -62,6 +65,22 @@ class ErrorMvcAutoConfigurationTests { | |||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	void renderCanUseJavaTimeTypeAsTimestamp() throws Exception { // gh-23256 | ||||
| 		this.contextRunner.run((context) -> { | ||||
| 			View errorView = context.getBean("error", View.class); | ||||
| 			ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class); | ||||
| 			DispatcherServletWebRequest webRequest = createWebRequest(new IllegalStateException("Exception message"), | ||||
| 					false); | ||||
| 			Map<String, Object> attributes = errorAttributes.getErrorAttributes(webRequest, true); | ||||
| 			attributes.put("timestamp", Clock.systemUTC().instant()); | ||||
| 			errorView.render(attributes, webRequest.getRequest(), webRequest.getResponse()); | ||||
| 			assertThat(webRequest.getResponse().getContentType()).isEqualTo("text/html;charset=UTF-8"); | ||||
| 			String responseString = ((MockHttpServletResponse) webRequest.getResponse()).getContentAsString(); | ||||
| 			assertThat(responseString).contains("This application has no explicit mapping for /error"); | ||||
| 		}); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test | ||||
| 	void renderWhenAlreadyCommittedLogsMessage(CapturedOutput output) { | ||||
| 		this.contextRunner.run((context) -> { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue