diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/MailServer.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/MailServer.java index 972027da1c..a553f39822 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/MailServer.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/util/MailServer.java @@ -3,6 +3,8 @@ package org.keycloak.testsuite.util; import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.ServerSetup; import java.io.IOException; +import java.lang.Thread.UncaughtExceptionHandler; +import java.net.SocketException; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; @@ -42,7 +44,7 @@ public class MailServer { log.info("-------------------------------------------------------"); } } - } catch (IOException | InterruptedException | MessagingException ex) { + } catch (IOException | MessagingException ex) { throw new RuntimeException(ex); } } @@ -53,18 +55,29 @@ public class MailServer { greenMail = new GreenMail(setup); greenMail.start(); - log.info("--Started mail server (" + HOST + ":" + PORT + ")--"); + log.info("Started mail server (" + HOST + ":" + PORT + ")"); } public static void stop() { if (greenMail != null) { - log.info("--Stopping mail server (localhost:3025)--"); + log.info("Stopping mail server (localhost:3025)"); + // Suppress error from GreenMail on shutdown + Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + if (!(e.getCause() instanceof SocketException && e.getStackTrace()[0].getClassName() + .equals("com.icegreen.greenmail.smtp.SmtpHandler"))) { + log.error("Exception in thread \"" + t.getName() + "\" "); + log.error(e.getMessage(), e); + } + } + }); greenMail.stop(); } } public static void createEmailAccount(String email, String password) { - log.debug("--Creating email account " + email + "--"); + log.debug("Creating email account " + email); greenMail.setUser(email, password); }