|
1 | 1 | /* |
2 | | - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 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. |
|
27 | 27 | /** |
28 | 28 | * @author Arjen Poutsma |
29 | 29 | * @author Marcel Overdijk |
| 30 | + * @author Kazuki Shimizu |
30 | 31 | */ |
31 | 32 | public class ResponseEntityTests { |
32 | 33 |
|
@@ -161,4 +162,31 @@ public void headers() throws URISyntaxException { |
161 | 162 | assertNull(responseEntity.getBody()); |
162 | 163 | } |
163 | 164 |
|
| 165 | + @Test |
| 166 | + public void headersCopy(){ |
| 167 | + HttpHeaders customHeaders = new HttpHeaders(); |
| 168 | + customHeaders.set("X-CustomHeader", "vale"); |
| 169 | + |
| 170 | + ResponseEntity<Void> responseEntity = ResponseEntity.ok().headers(customHeaders).build(); |
| 171 | + HttpHeaders responseHeaders = responseEntity.getHeaders(); |
| 172 | + |
| 173 | + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); |
| 174 | + assertEquals(1, responseHeaders.size()); |
| 175 | + assertEquals(1, responseHeaders.get("X-CustomHeader").size()); |
| 176 | + assertEquals("vale", responseHeaders.getFirst("X-CustomHeader")); |
| 177 | + |
| 178 | + } |
| 179 | + |
| 180 | + @Test // SPR-12792 |
| 181 | + public void headersCopyWithEmptyAndNull(){ |
| 182 | + ResponseEntity<Void> responseEntityWithEmptyHeaders = |
| 183 | + ResponseEntity.ok().headers(new HttpHeaders()).build(); |
| 184 | + ResponseEntity<Void> responseEntityWithNullHeaders = |
| 185 | + ResponseEntity.ok().headers(null).build(); |
| 186 | + |
| 187 | + assertEquals(HttpStatus.OK, responseEntityWithEmptyHeaders.getStatusCode()); |
| 188 | + assertTrue(responseEntityWithEmptyHeaders.getHeaders().isEmpty()); |
| 189 | + assertEquals(responseEntityWithEmptyHeaders.toString(), responseEntityWithNullHeaders.toString()); |
| 190 | + } |
| 191 | + |
164 | 192 | } |
0 commit comments