23
23
import static org .assertj .core .api .Assertions .assertThat ;
24
24
25
25
/**
26
+ * Unit tests for {@link HttpEntity}.
27
+ *
26
28
* @author Arjen Poutsma
29
+ * @author Yanming Zhou
27
30
*/
28
31
class HttpEntityTests {
29
32
30
33
@ Test
31
34
void noHeaders () {
32
35
String body = "foo" ;
33
36
HttpEntity <String > entity = new HttpEntity <>(body );
37
+
34
38
assertThat (entity .getBody ()).isSameAs (body );
35
39
assertThat (entity .getHeaders ().isEmpty ()).as ("isEmpty" ).isTrue ();
36
40
}
@@ -41,6 +45,7 @@ void httpHeaders() {
41
45
headers .setContentType (MediaType .TEXT_PLAIN );
42
46
String body = "foo" ;
43
47
HttpEntity <String > entity = new HttpEntity <>(body , headers );
48
+
44
49
assertThat (entity .getBody ()).isEqualTo (body );
45
50
assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
46
51
assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -52,6 +57,7 @@ void multiValueMap() {
52
57
headers .set ("Content-Type" , "text/plain" );
53
58
String body = "foo" ;
54
59
HttpEntity <String > entity = new HttpEntity <>(body , headers );
60
+
55
61
assertThat (entity .getBody ()).isEqualTo (body );
56
62
assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
57
63
assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -120,4 +126,14 @@ void requestEntity() {
120
126
assertThat (requestEntity2 ).isEqualTo (requestEntity );
121
127
}
122
128
129
+ @ Test // gh-34806
130
+ void mutateEmptyInstanceHeaders () {
131
+ HttpHeaders headers = new HttpHeaders (HttpEntity .EMPTY .getHeaders ());
132
+ headers .add ("Authorization" , "Bearer some-token" );
133
+
134
+ assertThat (HttpEntity .EMPTY .getHeaders ())
135
+ .as ("Headers of HttpEntity.EMPTY should remain empty" )
136
+ .isEmpty ();
137
+ }
138
+
123
139
}
0 commit comments