@@ -226,16 +226,33 @@ public void setImmutableIdempotent() {
226
226
227
227
@ Test // gh-25821
228
228
void copyImmutableToMutable () {
229
- NativeMessageHeaderAccessor source = new NativeMessageHeaderAccessor ();
230
- source .addNativeHeader ("foo" , "bar" );
231
- Message <String > message = MessageBuilder .createMessage ("payload" , source .getMessageHeaders ());
229
+ NativeMessageHeaderAccessor sourceAccessor = new NativeMessageHeaderAccessor ();
230
+ sourceAccessor .addNativeHeader ("foo" , "bar" );
231
+ Message <String > source = MessageBuilder .createMessage ("payload" , sourceAccessor .getMessageHeaders ());
232
232
233
- NativeMessageHeaderAccessor target = new NativeMessageHeaderAccessor ();
234
- target .copyHeaders (message .getHeaders ());
235
- target .setLeaveMutable (true );
236
- message = MessageBuilder .createMessage (message .getPayload (), target .getMessageHeaders ());
233
+ NativeMessageHeaderAccessor targetAccessor = new NativeMessageHeaderAccessor ();
234
+ targetAccessor .copyHeaders (source .getHeaders ());
235
+ targetAccessor .setLeaveMutable (true );
236
+ Message <?> target = MessageBuilder .createMessage (source .getPayload (), targetAccessor .getMessageHeaders ());
237
237
238
- MessageHeaderAccessor accessor = MessageHeaderAccessor .getMutableAccessor (message );
238
+ MessageHeaderAccessor accessor = MessageHeaderAccessor .getMutableAccessor (target );
239
+ assertThat (accessor .isMutable ());
240
+ ((NativeMessageHeaderAccessor ) accessor ).addNativeHeader ("foo" , "baz" );
241
+ assertThat (((NativeMessageHeaderAccessor ) accessor ).getNativeHeader ("foo" )).containsExactly ("bar" , "baz" );
242
+ }
243
+
244
+ @ Test // gh-25821
245
+ void copyIfAbsentImmutableToMutable () {
246
+ NativeMessageHeaderAccessor sourceAccessor = new NativeMessageHeaderAccessor ();
247
+ sourceAccessor .addNativeHeader ("foo" , "bar" );
248
+ Message <String > source = MessageBuilder .createMessage ("payload" , sourceAccessor .getMessageHeaders ());
249
+
250
+ MessageHeaderAccessor targetAccessor = new NativeMessageHeaderAccessor ();
251
+ targetAccessor .copyHeadersIfAbsent (source .getHeaders ());
252
+ targetAccessor .setLeaveMutable (true );
253
+ Message <?> target = MessageBuilder .createMessage (source .getPayload (), targetAccessor .getMessageHeaders ());
254
+
255
+ MessageHeaderAccessor accessor = MessageHeaderAccessor .getMutableAccessor (target );
239
256
assertThat (accessor .isMutable ());
240
257
((NativeMessageHeaderAccessor ) accessor ).addNativeHeader ("foo" , "baz" );
241
258
assertThat (((NativeMessageHeaderAccessor ) accessor ).getNativeHeader ("foo" )).containsExactly ("bar" , "baz" );
0 commit comments