1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 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.
26
26
import static org .assertj .core .api .Assertions .assertThat ;
27
27
28
28
/**
29
+ * Unit tests for {@link HttpEntity}.
30
+ *
29
31
* @author Arjen Poutsma
30
32
* @author Yanming Zhou
31
33
*/
@@ -35,6 +37,7 @@ class HttpEntityTests {
35
37
void noHeaders () {
36
38
String body = "foo" ;
37
39
HttpEntity <String > entity = new HttpEntity <>(body );
40
+
38
41
assertThat (entity .getBody ()).isSameAs (body );
39
42
assertThat (entity .getHeaders ()).isEmpty ();
40
43
}
@@ -45,6 +48,7 @@ void httpHeaders() {
45
48
headers .setContentType (MediaType .TEXT_PLAIN );
46
49
String body = "foo" ;
47
50
HttpEntity <String > entity = new HttpEntity <>(body , headers );
51
+
48
52
assertThat (entity .getBody ()).isEqualTo (body );
49
53
assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
50
54
assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -56,6 +60,7 @@ void multiValueMap() {
56
60
map .set ("Content-Type" , "text/plain" );
57
61
String body = "foo" ;
58
62
HttpEntity <String > entity = new HttpEntity <>(body , map );
63
+
59
64
assertThat (entity .getBody ()).isEqualTo (body );
60
65
assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
61
66
assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -124,11 +129,14 @@ void requestEntity() {
124
129
assertThat (requestEntity2 ).isEqualTo (requestEntity );
125
130
}
126
131
127
- @ Test
128
- void emptyHttpEntityShouldBeImmutable () {
129
- HttpHeaders newHeaders = new HttpHeaders (HttpEntity .EMPTY .getHeaders ());
130
- newHeaders .add ("Authorization" , "Bearer some-token" );
131
- assertThat (HttpEntity .EMPTY .getHeaders ().headerNames ()).isEmpty ();
132
+ @ Test // gh-34806
133
+ void mutateEmptyInstanceHeaders () {
134
+ HttpHeaders headers = new HttpHeaders (HttpEntity .EMPTY .getHeaders ());
135
+ headers .add ("Authorization" , "Bearer some-token" );
136
+
137
+ assertThat (HttpEntity .EMPTY .getHeaders ())
138
+ .as ("Headers of HttpEntity.EMPTY should remain empty" )
139
+ .isEmpty ();
132
140
}
133
141
134
142
}
0 commit comments