1717package org .springframework .integration .core ;
1818
1919import static org .assertj .core .api .Assertions .assertThat ;
20+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
2021
2122import java .util .Properties ;
2223
23- import org .junit .Test ;
24+ import org .junit .jupiter . api . Test ;
2425
2526import org .springframework .integration .history .MessageHistory ;
2627import org .springframework .integration .message .AdviceMessage ;
3435/**
3536 * @author Mark Fisher
3637 * @author Artem Bilan
38+ *
3739 * @since 2.0
3840 */
3941public class MessageHistoryTests {
4042
4143 @ Test
4244 public void addComponents () {
43- GenericMessage <String > original = new GenericMessage <String >("foo" );
45+ GenericMessage <String > original = new GenericMessage <>("foo" );
4446 assertThat (MessageHistory .read (original )).isNull ();
4547 Message <String > result1 = MessageHistory .write (original , new TestComponent (1 ));
4648 MessageHistory history1 = MessageHistory .read (result1 );
@@ -52,11 +54,12 @@ public void addComponents() {
5254 assertThat (history2 .toString ()).isEqualTo ("testComponent-1,testComponent-2" );
5355 }
5456
55- @ Test ( expected = UnsupportedOperationException . class )
57+ @ Test
5658 public void verifyImmutability () {
5759 Message <?> message = MessageHistory .write (MessageBuilder .withPayload ("test" ).build (), new TestComponent (1 ));
5860 MessageHistory history = MessageHistory .read (message );
59- history .add (new Properties ());
61+ assertThatExceptionOfType (UnsupportedOperationException .class )
62+ .isThrownBy (() -> history .add (new Properties ()));
6063 }
6164
6265 @ Test
@@ -78,13 +81,15 @@ public void testCorrectMutableMessageAfterWrite() {
7881
7982 @ Test
8083 public void testCorrectErrorMessageAfterWrite () {
84+ Message <?> originalMessage = new GenericMessage <>("test" );
8185 RuntimeException payload = new RuntimeException ();
82- ErrorMessage original = new ErrorMessage (payload );
86+ ErrorMessage original = new ErrorMessage (payload , originalMessage );
8387 assertThat (MessageHistory .read (original )).isNull ();
8488 Message <Throwable > result1 = MessageHistory .write (original , new TestComponent (1 ));
8589 assertThat (result1 ).isInstanceOf (ErrorMessage .class );
8690 assertThat (result1 ).isNotSameAs (original );
8791 assertThat (result1 .getPayload ()).isSameAs (original .getPayload ());
92+ assertThat (result1 ).extracting ("originalMessage" ).isSameAs (originalMessage );
8893 MessageHistory history1 = MessageHistory .read (result1 );
8994 assertThat (history1 ).isNotNull ();
9095 assertThat (history1 .toString ()).isEqualTo ("testComponent-1" );
@@ -93,6 +98,7 @@ public void testCorrectErrorMessageAfterWrite() {
9398 assertThat (result2 ).isNotSameAs (original );
9499 assertThat (result2 ).isNotSameAs (result1 );
95100 assertThat (result2 .getPayload ()).isSameAs (original .getPayload ());
101+ assertThat (result1 ).extracting ("originalMessage" ).isSameAs (originalMessage );
96102 MessageHistory history2 = MessageHistory .read (result2 );
97103 assertThat (history2 ).isNotNull ();
98104 assertThat (history2 .toString ()).isEqualTo ("testComponent-1,testComponent-2" );
@@ -140,6 +146,7 @@ public String getComponentName() {
140146 public String getComponentType () {
141147 return "type-" + this .id ;
142148 }
149+
143150 }
144151
145152}
0 commit comments