From 9cc0cbe3bd38db29e3438fc7e875b4130e45e433 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 19 Apr 2019 11:02:37 -0400 Subject: [PATCH] Polishing for ImapMailReceiverTests https://build.spring.io/browse/INT-MASTERSPRING40-681/ * Create an `ImapServer` only in the `@Before` method. Looks like the `final` property is initialized only once for the whole test class * Change `LongRunningIntegrationTest` to the `@ClassRule` * Fix `testMessageHistory()` and re-enable it * Remove redundant `this.imapIdleServer.resetServer()` since we now have a fresh `ImapServer` instance for every test method. --- .../mail/ImapMailReceiverTests.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java index 10a9a0374e..408bd51d26 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java @@ -58,8 +58,7 @@ import javax.mail.search.FromTerm; import org.apache.commons.logging.Log; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; +import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -102,19 +101,20 @@ import com.sun.mail.imap.IMAPFolder; @DirtiesContext public class ImapMailReceiverTests { - private final ImapServer imapIdleServer = TestMailServer.imap(0); + @ClassRule + public static final LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); - @Rule - public final LongRunningIntegrationTest longRunningIntegrationTest = new LongRunningIntegrationTest(); - - private final AtomicInteger failed = new AtomicInteger(0); + private AtomicInteger failed; + private ImapServer imapIdleServer; @Autowired private ApplicationContext context; @Before public void setup() throws InterruptedException { + failed = new AtomicInteger(0); + this.imapIdleServer = TestMailServer.imap(0); int n = 0; while (n++ < 100 && (!this.imapIdleServer.isListening())) { Thread.sleep(100); @@ -182,7 +182,6 @@ public class ImapMailReceiverTests { } public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped, boolean simple) throws Exception { - this.imapIdleServer.resetServer(); Properties mailProps = new Properties(); mailProps.put("mail.debug", "true"); mailProps.put("mail.imap.connectionpool.debug", "true"); @@ -458,7 +457,6 @@ public class ImapMailReceiverTests { } @Test - @Ignore public void testMessageHistory() throws Exception { ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class); adapter.setReconnectDelay(1); @@ -480,6 +478,7 @@ public class ImapMailReceiverTests { DirectFieldAccessor accessor = new DirectFieldAccessor((invocation.getMock())); IMAPFolder folder = mock(IMAPFolder.class); accessor.setPropertyValue("folder", folder); + given(folder.isOpen()).willReturn(true); given(folder.hasNewMessages()).willReturn(true); return null; }).given(receiver).openFolder(); @@ -712,7 +711,6 @@ public class ImapMailReceiverTests { @Test // see INT-1801 public void testImapLifecycleForRaceCondition() throws Exception { - for (int i = 0; i < 1000; i++) { final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo"); Store store = mock(Store.class);