17
17
package org .springframework .integration .core ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
20
21
21
22
import java .util .Properties ;
22
23
23
- import org .junit .Test ;
24
+ import org .junit .jupiter . api . Test ;
24
25
25
26
import org .springframework .integration .history .MessageHistory ;
26
27
import org .springframework .integration .message .AdviceMessage ;
34
35
/**
35
36
* @author Mark Fisher
36
37
* @author Artem Bilan
38
+ *
37
39
* @since 2.0
38
40
*/
39
41
public class MessageHistoryTests {
40
42
41
43
@ Test
42
44
public void addComponents () {
43
- GenericMessage <String > original = new GenericMessage <String >("foo" );
45
+ GenericMessage <String > original = new GenericMessage <>("foo" );
44
46
assertThat (MessageHistory .read (original )).isNull ();
45
47
Message <String > result1 = MessageHistory .write (original , new TestComponent (1 ));
46
48
MessageHistory history1 = MessageHistory .read (result1 );
@@ -52,11 +54,12 @@ public void addComponents() {
52
54
assertThat (history2 .toString ()).isEqualTo ("testComponent-1,testComponent-2" );
53
55
}
54
56
55
- @ Test ( expected = UnsupportedOperationException . class )
57
+ @ Test
56
58
public void verifyImmutability () {
57
59
Message <?> message = MessageHistory .write (MessageBuilder .withPayload ("test" ).build (), new TestComponent (1 ));
58
60
MessageHistory history = MessageHistory .read (message );
59
- history .add (new Properties ());
61
+ assertThatExceptionOfType (UnsupportedOperationException .class )
62
+ .isThrownBy (() -> history .add (new Properties ()));
60
63
}
61
64
62
65
@ Test
@@ -78,13 +81,15 @@ public void testCorrectMutableMessageAfterWrite() {
78
81
79
82
@ Test
80
83
public void testCorrectErrorMessageAfterWrite () {
84
+ Message <?> originalMessage = new GenericMessage <>("test" );
81
85
RuntimeException payload = new RuntimeException ();
82
- ErrorMessage original = new ErrorMessage (payload );
86
+ ErrorMessage original = new ErrorMessage (payload , originalMessage );
83
87
assertThat (MessageHistory .read (original )).isNull ();
84
88
Message <Throwable > result1 = MessageHistory .write (original , new TestComponent (1 ));
85
89
assertThat (result1 ).isInstanceOf (ErrorMessage .class );
86
90
assertThat (result1 ).isNotSameAs (original );
87
91
assertThat (result1 .getPayload ()).isSameAs (original .getPayload ());
92
+ assertThat (result1 ).extracting ("originalMessage" ).isSameAs (originalMessage );
88
93
MessageHistory history1 = MessageHistory .read (result1 );
89
94
assertThat (history1 ).isNotNull ();
90
95
assertThat (history1 .toString ()).isEqualTo ("testComponent-1" );
@@ -93,6 +98,7 @@ public void testCorrectErrorMessageAfterWrite() {
93
98
assertThat (result2 ).isNotSameAs (original );
94
99
assertThat (result2 ).isNotSameAs (result1 );
95
100
assertThat (result2 .getPayload ()).isSameAs (original .getPayload ());
101
+ assertThat (result1 ).extracting ("originalMessage" ).isSameAs (originalMessage );
96
102
MessageHistory history2 = MessageHistory .read (result2 );
97
103
assertThat (history2 ).isNotNull ();
98
104
assertThat (history2 .toString ()).isEqualTo ("testComponent-1,testComponent-2" );
@@ -140,6 +146,7 @@ public String getComponentName() {
140
146
public String getComponentType () {
141
147
return "type-" + this .id ;
142
148
}
149
+
143
150
}
144
151
145
152
}
0 commit comments