Skip to content

Commit 1b609f1

Browse files
committed
Remove use explicit or mock TaskScheduler from ImapMailReceiverTests
We do have over there already `implements TestApplicationContextAware`, so we simply can rely on the respective `BeanFactory` configuration
1 parent c9da647 commit 1b609f1

File tree

1 file changed

+0
-34
lines changed

1 file changed

+0
-34
lines changed

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.mockito.Mockito;
6767

6868
import org.springframework.beans.DirectFieldAccessor;
69-
import org.springframework.beans.factory.BeanFactory;
7069
import org.springframework.beans.factory.annotation.Autowired;
7170
import org.springframework.context.ApplicationContext;
7271
import org.springframework.core.io.ClassPathResource;
@@ -83,9 +82,6 @@
8382
import org.springframework.integration.test.util.TestUtils;
8483
import org.springframework.messaging.MessageHeaders;
8584
import org.springframework.messaging.PollableChannel;
86-
import org.springframework.scheduling.TaskScheduler;
87-
import org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler;
88-
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
8985
import org.springframework.test.annotation.DirtiesContext;
9086
import org.springframework.test.context.ContextConfiguration;
9187
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -95,7 +91,6 @@
9591
import static org.assertj.core.api.Assertions.assertThatThrownBy;
9692
import static org.mockito.ArgumentMatchers.any;
9793
import static org.mockito.ArgumentMatchers.anyString;
98-
import static org.mockito.ArgumentMatchers.eq;
9994
import static org.mockito.BDDMockito.given;
10095
import static org.mockito.BDDMockito.willAnswer;
10196
import static org.mockito.BDDMockito.willDoNothing;
@@ -173,7 +168,6 @@ void stopImapServer() {
173168
public void testIdleWithServerCustomSearch() throws Exception {
174169
ImapMailReceiver receiver =
175170
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
176-
receiver.setTaskScheduler(new SimpleAsyncTaskScheduler());
177171
receiver.setSearchTermStrategy((supportedFlags, folder) -> {
178172
try {
179173
FromTerm fromTerm = new FromTerm(new InternetAddress("bar@baz"));
@@ -190,7 +184,6 @@ public void testIdleWithServerCustomSearch() throws Exception {
190184
public void testIdleWithServerDefaultSearch() throws Exception {
191185
ImapMailReceiver receiver =
192186
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
193-
receiver.setTaskScheduler(new SimpleAsyncTaskScheduler());
194187
testIdleWithServerGuts(receiver, false);
195188
assertThat(imapSearches.searches.get(0)).contains("testSIUserFlag");
196189
}
@@ -218,7 +211,6 @@ public void testIdleWithMessageMappingSimple() throws Exception {
218211
ImapMailReceiver receiver =
219212
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
220213
receiver.setSimpleContent(true);
221-
receiver.setTaskScheduler(new SimpleAsyncTaskScheduler());
222214
receiver.setHeaderMapper(new DefaultMailHeaderMapper());
223215
testIdleWithServerGuts(receiver, true, true);
224216
}
@@ -231,8 +223,6 @@ public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped, bo
231223
receiver.setMaxFetchSize(1);
232224
receiver.setShouldDeleteMessages(false);
233225
receiver.setShouldMarkMessagesAsRead(true);
234-
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
235-
setUpScheduler(receiver, taskScheduler);
236226
receiver.setUserFlag("testSIUserFlag");
237227
receiver.setBeanFactory(TEST_INTEGRATION_CONTEXT);
238228
receiver.afterPropertiesSet();
@@ -292,7 +282,6 @@ public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped, bo
292282
assertThat(channel.receive(100)).isNull(); // no new message after second and third idle
293283

294284
adapter.stop();
295-
taskScheduler.shutdown();
296285
assertThat(imapSearches.stores.get(0)).contains("testSIUserFlag");
297286
}
298287

@@ -669,8 +658,6 @@ public void testNoInitialIdleDelayWhenRecentNotSupported() throws Exception {
669658
adapter.setReconnectDelay(10);
670659

671660
ImapMailReceiver receiver = new ImapMailReceiver("imap:foo");
672-
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
673-
setUpScheduler(receiver, taskScheduler);
674661

675662
final IMAPFolder folder = mock(IMAPFolder.class);
676663
given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER));
@@ -725,7 +712,6 @@ public void testNoInitialIdleDelayWhenRecentNotSupported() throws Exception {
725712
assertThat(channel.receive(100)).isNull();
726713
assertThat(channel.receive(10000)).isNotNull();
727714
adapter.stop();
728-
taskScheduler.shutdown();
729715
}
730716

731717
@Test
@@ -739,8 +725,6 @@ public void testInitialIdleDelayWhenRecentIsSupported() throws Exception {
739725

740726
ImapMailReceiver receiver = new ImapMailReceiver("imap:foo");
741727
receiver.setCancelIdleInterval(10);
742-
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
743-
setUpScheduler(receiver, taskScheduler);
744728
IMAPFolder folder = mock(IMAPFolder.class);
745729
given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.RECENT));
746730
given(folder.isOpen()).willReturn(false).willReturn(true);
@@ -780,7 +764,6 @@ public void testInitialIdleDelayWhenRecentIsSupported() throws Exception {
780764
assertThat(channel.receive(20000)).isNotNull();
781765
assertThat(idles.await(10, TimeUnit.SECONDS)).isTrue();
782766
adapter.stop();
783-
taskScheduler.shutdown();
784767
}
785768

786769
@Test
@@ -989,15 +972,6 @@ public void testIdleReconnects() throws Exception {
989972
adapter.stop();
990973
}
991974

992-
private void setUpScheduler(ImapMailReceiver mailReceiver, ThreadPoolTaskScheduler taskScheduler) {
993-
taskScheduler.setPoolSize(5);
994-
taskScheduler.initialize();
995-
BeanFactory bf = getBeanFactory(taskScheduler);
996-
given(bf.containsBean("taskScheduler")).willReturn(true);
997-
given(bf.getBean("taskScheduler", TaskScheduler.class)).willReturn(taskScheduler);
998-
mailReceiver.setBeanFactory(bf);
999-
}
1000-
1001975
@Test
1002976
public void receiveAndMarkAsReadDontDeleteWithThrowingWhenCopying() throws Exception {
1003977
AbstractMailReceiver receiver = new ImapMailReceiver();
@@ -1023,14 +997,6 @@ public void receiveAndMarkAsReadDontDeleteWithThrowingWhenCopying() throws Excep
1023997
verify(receiver, times(0)).deleteMessages(Mockito.any());
1024998
}
1025999

1026-
private BeanFactory getBeanFactory(TaskScheduler taskScheduler) {
1027-
BeanFactory beanFactory = mock(BeanFactory.class);
1028-
when(beanFactory.getBean(eq("taskScheduler"), any(Class.class)))
1029-
.thenReturn(taskScheduler);
1030-
when(beanFactory.containsBean("taskScheduler")).thenReturn(true);
1031-
return beanFactory;
1032-
}
1033-
10341000
private static class ImapSearchLoggingHandler extends Handler {
10351001

10361002
private final List<String> searches = new ArrayList<>();

0 commit comments

Comments
 (0)