Skip to content

Commit 9cc0cbe

Browse files
committed
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.
1 parent cca50fc commit 9cc0cbe

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
import org.apache.commons.logging.Log;
5959
import org.junit.After;
6060
import org.junit.Before;
61-
import org.junit.Ignore;
62-
import org.junit.Rule;
61+
import org.junit.ClassRule;
6362
import org.junit.Test;
6463
import org.junit.runner.RunWith;
6564
import org.mockito.Mockito;
@@ -102,19 +101,20 @@
102101
@DirtiesContext
103102
public class ImapMailReceiverTests {
104103

105-
private final ImapServer imapIdleServer = TestMailServer.imap(0);
104+
@ClassRule
105+
public static final LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
106106

107-
@Rule
108-
public final LongRunningIntegrationTest longRunningIntegrationTest = new LongRunningIntegrationTest();
109-
110-
private final AtomicInteger failed = new AtomicInteger(0);
107+
private AtomicInteger failed;
111108

109+
private ImapServer imapIdleServer;
112110

113111
@Autowired
114112
private ApplicationContext context;
115113

116114
@Before
117115
public void setup() throws InterruptedException {
116+
failed = new AtomicInteger(0);
117+
this.imapIdleServer = TestMailServer.imap(0);
118118
int n = 0;
119119
while (n++ < 100 && (!this.imapIdleServer.isListening())) {
120120
Thread.sleep(100);
@@ -182,7 +182,6 @@ public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped) th
182182
}
183183

184184
public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped, boolean simple) throws Exception {
185-
this.imapIdleServer.resetServer();
186185
Properties mailProps = new Properties();
187186
mailProps.put("mail.debug", "true");
188187
mailProps.put("mail.imap.connectionpool.debug", "true");
@@ -458,7 +457,6 @@ public void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
458457
}
459458

460459
@Test
461-
@Ignore
462460
public void testMessageHistory() throws Exception {
463461
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
464462
adapter.setReconnectDelay(1);
@@ -480,6 +478,7 @@ public void testMessageHistory() throws Exception {
480478
DirectFieldAccessor accessor = new DirectFieldAccessor((invocation.getMock()));
481479
IMAPFolder folder = mock(IMAPFolder.class);
482480
accessor.setPropertyValue("folder", folder);
481+
given(folder.isOpen()).willReturn(true);
483482
given(folder.hasNewMessages()).willReturn(true);
484483
return null;
485484
}).given(receiver).openFolder();
@@ -712,7 +711,6 @@ public void testConnectionException() throws Exception {
712711

713712
@Test // see INT-1801
714713
public void testImapLifecycleForRaceCondition() throws Exception {
715-
716714
for (int i = 0; i < 1000; i++) {
717715
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
718716
Store store = mock(Store.class);

0 commit comments

Comments
 (0)