11/*
2- * Copyright 2002-2024 the original author or authors.
2+ * Copyright 2002-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2626import static org .assertj .core .api .Assertions .assertThat ;
2727
2828/**
29+ * Unit tests for {@link HttpEntity}.
30+ *
2931 * @author Arjen Poutsma
3032 * @author Yanming Zhou
3133 */
@@ -35,6 +37,7 @@ class HttpEntityTests {
3537 void noHeaders () {
3638 String body = "foo" ;
3739 HttpEntity <String > entity = new HttpEntity <>(body );
40+
3841 assertThat (entity .getBody ()).isSameAs (body );
3942 assertThat (entity .getHeaders ()).isEmpty ();
4043 }
@@ -45,6 +48,7 @@ void httpHeaders() {
4548 headers .setContentType (MediaType .TEXT_PLAIN );
4649 String body = "foo" ;
4750 HttpEntity <String > entity = new HttpEntity <>(body , headers );
51+
4852 assertThat (entity .getBody ()).isEqualTo (body );
4953 assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
5054 assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -56,6 +60,7 @@ void multiValueMap() {
5660 map .set ("Content-Type" , "text/plain" );
5761 String body = "foo" ;
5862 HttpEntity <String > entity = new HttpEntity <>(body , map );
63+
5964 assertThat (entity .getBody ()).isEqualTo (body );
6065 assertThat (entity .getHeaders ().getContentType ()).isEqualTo (MediaType .TEXT_PLAIN );
6166 assertThat (entity .getHeaders ().getFirst ("Content-Type" )).isEqualTo ("text/plain" );
@@ -124,11 +129,14 @@ void requestEntity() {
124129 assertThat (requestEntity2 ).isEqualTo (requestEntity );
125130 }
126131
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 ();
132140 }
133141
134142}
0 commit comments