2323import static org .assertj .core .api .Assertions .assertThat ;
2424
2525/**
26+ * Unit tests for {@link HttpEntity}.
27+ *
2628 * @author Arjen Poutsma
29+ * @author Yanming Zhou
2730 */
2831class HttpEntityTests {
2932
3033 @ Test
3134 void noHeaders () {
3235 String body = "foo" ;
3336 HttpEntity <String > entity = new HttpEntity <>(body );
37+
3438 assertThat (entity .getBody ()).isSameAs (body );
3539 assertThat (entity .getHeaders ().isEmpty ()).as ("isEmpty" ).isTrue ();
3640 }
@@ -41,6 +45,7 @@ void httpHeaders() {
4145 headers .setContentType (MediaType .TEXT_PLAIN );
4246 String body = "foo" ;
4347 HttpEntity <String > entity = new HttpEntity <>(body , headers );
48+
4449 assertThat (entity .getBody ()).isEqualTo (body );
4550 assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
4651 assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -52,6 +57,7 @@ void multiValueMap() {
5257 headers .set ("Content-Type" , "text/plain" );
5358 String body = "foo" ;
5459 HttpEntity <String > entity = new HttpEntity <>(body , headers );
60+
5561 assertThat (entity .getBody ()).isEqualTo (body );
5662 assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
5763 assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -120,4 +126,14 @@ void requestEntity() {
120126 assertThat (requestEntity2 ).isEqualTo (requestEntity );
121127 }
122128
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+
123139}
0 commit comments