4343 *
4444 * @author Johannes Edmeier
4545 * @author Stephane Nicoll
46+ * @author Scott Frederick
4647 */
4748class MailHealthIndicatorTests {
4849
@@ -60,6 +61,52 @@ void setup() {
6061 this .indicator = new MailHealthIndicator (this .mailSender );
6162 }
6263
64+ @ Test
65+ void smtpOnDefaultHostAndPortIsUp () {
66+ given (this .mailSender .getHost ()).willReturn (null );
67+ given (this .mailSender .getPort ()).willReturn (-1 );
68+ given (this .mailSender .getProtocol ()).willReturn ("success" );
69+ Health health = this .indicator .health ();
70+ assertThat (health .getStatus ()).isEqualTo (Status .UP );
71+ assertThat (health .getDetails ()).doesNotContainKey ("location" );
72+ }
73+
74+ @ Test
75+ void smtpOnDefaultHostAndPortIsDown () throws MessagingException {
76+ given (this .mailSender .getHost ()).willReturn (null );
77+ given (this .mailSender .getPort ()).willReturn (-1 );
78+ willThrow (new MessagingException ("A test exception" )).given (this .mailSender ).testConnection ();
79+ Health health = this .indicator .health ();
80+ assertThat (health .getStatus ()).isEqualTo (Status .DOWN );
81+ assertThat (health .getDetails ()).doesNotContainKey ("location" );
82+ Object errorMessage = health .getDetails ().get ("error" );
83+ assertThat (errorMessage ).isNotNull ();
84+ assertThat (errorMessage .toString ().contains ("A test exception" )).isTrue ();
85+ }
86+
87+ @ Test
88+ void smtpOnDefaultHostAndCustomPortIsUp () {
89+ given (this .mailSender .getHost ()).willReturn (null );
90+ given (this .mailSender .getPort ()).willReturn (1234 );
91+ given (this .mailSender .getProtocol ()).willReturn ("success" );
92+ Health health = this .indicator .health ();
93+ assertThat (health .getStatus ()).isEqualTo (Status .UP );
94+ assertThat (health .getDetails ().get ("location" )).isEqualTo (":1234" );
95+ }
96+
97+ @ Test
98+ void smtpOnDefaultHostAndCustomPortIsDown () throws MessagingException {
99+ given (this .mailSender .getHost ()).willReturn (null );
100+ given (this .mailSender .getPort ()).willReturn (1234 );
101+ willThrow (new MessagingException ("A test exception" )).given (this .mailSender ).testConnection ();
102+ Health health = this .indicator .health ();
103+ assertThat (health .getStatus ()).isEqualTo (Status .DOWN );
104+ assertThat (health .getDetails ().get ("location" )).isEqualTo (":1234" );
105+ Object errorMessage = health .getDetails ().get ("error" );
106+ assertThat (errorMessage ).isNotNull ();
107+ assertThat (errorMessage .toString ().contains ("A test exception" )).isTrue ();
108+ }
109+
63110 @ Test
64111 void smtpOnDefaultPortIsUp () {
65112 given (this .mailSender .getPort ()).willReturn (-1 );
0 commit comments