18
18
19
19
import com .icegreen .greenmail .spring .GreenMailBean ;
20
20
import com .icegreen .greenmail .util .GreenMailUtil ;
21
- import jakarta .mail .MessagingException ;
22
21
import jakarta .mail .internet .MimeMessage ;
23
22
import org .junit .jupiter .api .Test ;
24
- import org .junit .jupiter .api .extension .ExtendWith ;
25
23
26
24
import org .springframework .beans .factory .annotation .Autowired ;
27
- import org .springframework .test .context .ContextConfiguration ;
28
- import org .springframework .test .context .junit .jupiter .SpringExtension ;
25
+ import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
29
26
import org .springframework .ws .client .core .WebServiceTemplate ;
30
27
import org .springframework .xml .transform .StringResult ;
31
28
import org .springframework .xml .transform .StringSource ;
32
29
33
30
import static org .assertj .core .api .Assertions .assertThat ;
34
31
35
- @ ExtendWith (SpringExtension .class )
36
- @ ContextConfiguration ("mail-applicationContext.xml" )
32
+ @ SpringJUnitConfig (locations = "mail-applicationContext.xml" )
37
33
public class MailIntegrationTest {
38
34
39
35
@ Autowired
@@ -43,20 +39,20 @@ public class MailIntegrationTest {
43
39
private WebServiceTemplate webServiceTemplate ;
44
40
45
41
@ Test
46
- public void testMailTransport () throws MessagingException {
47
-
48
- String content = "<root xmlns=\" http://springframework.org/spring-ws\" ><child/></root>" ;
42
+ public void testMailTransport () {
43
+ String content = """
44
+ <root xmlns="http://springframework.org/spring-ws">
45
+ <child/>
46
+ </root>""" ;
49
47
StringResult result = new StringResult ();
50
48
this .webServiceTemplate .sendSourceAndReceiveToResult (new StringSource (content ), result );
51
-
52
49
MimeMessage [] receivedMessages = this .greenMailBean .getGreenMail ().getReceivedMessages ();
53
-
54
- assertThat (receivedMessages ).hasSize (1 );
55
-
56
- assertThat (GreenMailUtil .getAddressList (receivedMessages [0 ].getFrom ()))
57
- .isEqualTo ("Spring-WS SOAP Client <client@localhost>" );
58
- assertThat (GreenMailUtil .getAddressList (receivedMessages [0 ].getAllRecipients ())).isEqualTo ("server@localhost" );
59
- assertThat (GreenMailUtil .getBody (receivedMessages [0 ])).contains (content );
50
+ assertThat (receivedMessages ).singleElement ().satisfies ((receivedMessage ) -> {
51
+ assertThat (GreenMailUtil .getAddressList (receivedMessage .getFrom ()))
52
+ .isEqualTo ("Spring-WS SOAP Client <client@localhost>" );
53
+ assertThat (GreenMailUtil .getAddressList (receivedMessage .getAllRecipients ())).isEqualTo ("server@localhost" );
54
+ assertThat (GreenMailUtil .getBody (receivedMessage )).containsIgnoringWhitespaces (content );
55
+ });
60
56
}
61
57
62
58
}
0 commit comments