Skip to content

Commit 3e0ceac

Browse files
committed
Apply Junit5BestPractices in spring-integration-mail
Signed-off-by: Ma,Jiandong <jiandong.ma.cn@gmail.com>
1 parent 41e2b87 commit 3e0ceac

19 files changed

+168
-153
lines changed

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

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,6 +111,7 @@
111111
* @author Alexander Pinske
112112
* @author Dominik Simmen
113113
* @author Filip Hrisafov
114+
* @author Ma Jiandong
114115
*/
115116
@SpringJUnitConfig
116117
@ContextConfiguration(
@@ -167,7 +168,7 @@ void stopImapServer() {
167168
}
168169

169170
@Test
170-
public void testIdleWithServerCustomSearch() throws Exception {
171+
void idleWithServerCustomSearch() throws Exception {
171172
ImapMailReceiver receiver =
172173
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
173174
receiver.setSearchTermStrategy((supportedFlags, folder) -> {
@@ -183,15 +184,15 @@ public void testIdleWithServerCustomSearch() throws Exception {
183184
}
184185

185186
@Test
186-
public void testIdleWithServerDefaultSearch() throws Exception {
187+
void idleWithServerDefaultSearch() throws Exception {
187188
ImapMailReceiver receiver =
188189
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
189190
testIdleWithServerGuts(receiver, false);
190191
assertThat(imapSearches.searches.get(0)).contains("testSIUserFlag");
191192
}
192193

193194
@Test
194-
public void testIdleWithMessageMapping() throws Exception {
195+
void idleWithMessageMapping() throws Exception {
195196
ImapMailReceiver receiver =
196197
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
197198
receiver.setHeaderMapper(new DefaultMailHeaderMapper());
@@ -200,7 +201,7 @@ public void testIdleWithMessageMapping() throws Exception {
200201

201202
@Test
202203
@Disabled
203-
public void testIdleWithServerDefaultSearchSimple() throws Exception {
204+
void idleWithServerDefaultSearchSimple() throws Exception {
204205
ImapMailReceiver receiver =
205206
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
206207
receiver.setSimpleContent(true);
@@ -209,7 +210,7 @@ public void testIdleWithServerDefaultSearchSimple() throws Exception {
209210
}
210211

211212
@Test
212-
public void testIdleWithMessageMappingSimple() throws Exception {
213+
void idleWithMessageMappingSimple() throws Exception {
213214
ImapMailReceiver receiver =
214215
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
215216
receiver.setSimpleContent(true);
@@ -289,7 +290,7 @@ public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped, bo
289290
}
290291

291292
@Test
292-
public void receiveAndMarkAsReadDontDelete() throws Exception {
293+
void receiveAndMarkAsReadDontDelete() throws Exception {
293294
user.deliver(GreenMailUtil.createTextEmail("user", "sender", "subject", "body",
294295
imapIdleServer.getImap().getServerSetup()));
295296
AbstractMailReceiver receiver = new ImapMailReceiver();
@@ -342,7 +343,7 @@ private AbstractMailReceiver receiveAndMarkAsReadDontDeleteGuts(AbstractMailRece
342343
}
343344

344345
@Test
345-
public void receiveAndMarkAsReadDontDeletePassingFilter() throws Exception {
346+
void receiveAndMarkAsReadDontDeletePassingFilter() throws Exception {
346347
AbstractMailReceiver receiver = new ImapMailReceiver();
347348
Message msg1 = GreenMailUtil.newMimeMessage("test1");
348349
Message msg2 = GreenMailUtil.newMimeMessage("test2");
@@ -355,7 +356,7 @@ public void receiveAndMarkAsReadDontDeletePassingFilter() throws Exception {
355356
}
356357

357358
@Test
358-
public void receiveAndMarkAsReadDontDeleteFiltered() throws Exception {
359+
void receiveAndMarkAsReadDontDeleteFiltered() throws Exception {
359360
AbstractMailReceiver receiver = new ImapMailReceiver();
360361
Message msg1 = GreenMailUtil.newMimeMessage("test1");
361362
Message msg2 = spy(GreenMailUtil.newMimeMessage("test2"));
@@ -370,7 +371,7 @@ public void receiveAndMarkAsReadDontDeleteFiltered() throws Exception {
370371
}
371372

372373
@Test
373-
public void receiveAndDebugIsDisabledNotLogFiltered() throws Exception {
374+
void receiveAndDebugIsDisabledNotLogFiltered() throws Exception {
374375
AbstractMailReceiver receiver = new ImapMailReceiver();
375376

376377
LogAccessor logger = spy(TestUtils.getPropertyValue(receiver, "logger", LogAccessor.class));
@@ -391,7 +392,7 @@ public void receiveAndDebugIsDisabledNotLogFiltered() throws Exception {
391392
}
392393

393394
@Test
394-
public void receiveExpungedAndNotExpungedLogFiltered() throws Exception {
395+
void receiveExpungedAndNotExpungedLogFiltered() throws Exception {
395396
AbstractMailReceiver receiver = new ImapMailReceiver();
396397

397398
LogAccessor logger = spy(TestUtils.getPropertyValue(receiver, "logger", LogAccessor.class));
@@ -414,7 +415,7 @@ public void receiveExpungedAndNotExpungedLogFiltered() throws Exception {
414415
}
415416

416417
@Test
417-
public void receiveMarkAsReadAndDelete() throws Exception {
418+
void receiveMarkAsReadAndDelete() throws Exception {
418419
AbstractMailReceiver receiver = new ImapMailReceiver();
419420
((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(true);
420421
receiver.setShouldDeleteMessages(true);
@@ -453,7 +454,7 @@ public void receiveMarkAsReadAndDelete() throws Exception {
453454
}
454455

455456
@Test
456-
public void receiveAndDontMarkAsRead() throws Exception {
457+
void receiveAndDontMarkAsRead() throws Exception {
457458
AbstractMailReceiver receiver = new ImapMailReceiver();
458459
((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(false);
459460
receiver = spy(receiver);
@@ -482,7 +483,7 @@ public void receiveAndDontMarkAsRead() throws Exception {
482483
}
483484

484485
@Test
485-
public void receiveAndDontMarkAsReadButDelete() throws Exception {
486+
void receiveAndDontMarkAsReadButDelete() throws Exception {
486487
AbstractMailReceiver receiver = new ImapMailReceiver();
487488
receiver.setShouldDeleteMessages(true);
488489
((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(false);
@@ -522,7 +523,7 @@ public void receiveAndDontMarkAsReadButDelete() throws Exception {
522523
}
523524

524525
@Test
525-
public void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
526+
void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
526527
AbstractMailReceiver receiver = new ImapMailReceiver();
527528
receiver = spy(receiver);
528529
receiver.setBeanFactory(mock(BeanFactory.class));
@@ -557,7 +558,7 @@ public void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
557558
}
558559

559560
@Test
560-
public void testMessageHistory() throws Exception {
561+
void messageHistory() throws Exception {
561562
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
562563
adapter.setReconnectDelay(10);
563564

@@ -600,7 +601,7 @@ public void testMessageHistory() throws Exception {
600601
}
601602

602603
@Test
603-
public void testIdleChannelAdapterException() throws Exception {
604+
void idleChannelAdapterException() throws Exception {
604605
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
605606

606607
//ImapMailReceiver receiver = (ImapMailReceiver) TestUtils.getPropertyValue(adapter, "mailReceiver");
@@ -653,7 +654,7 @@ protected Object handleRequestMessage(org.springframework.messaging.Message<?> r
653654

654655
@SuppressWarnings("resource")
655656
@Test
656-
public void testNoInitialIdleDelayWhenRecentNotSupported() throws Exception {
657+
void noInitialIdleDelayWhenRecentNotSupported() throws Exception {
657658
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
658659

659660
QueueChannel channel = new QueueChannel();
@@ -721,7 +722,7 @@ public void testNoInitialIdleDelayWhenRecentNotSupported() throws Exception {
721722
}
722723

723724
@Test
724-
public void testInitialIdleDelayWhenRecentIsSupported() throws Exception {
725+
void initialIdleDelayWhenRecentIsSupported() throws Exception {
725726
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
726727

727728
QueueChannel channel = new QueueChannel();
@@ -776,7 +777,7 @@ public void testInitialIdleDelayWhenRecentIsSupported() throws Exception {
776777
}
777778

778779
@Test
779-
public void testConnectionException() throws Exception {
780+
void connectionException() throws Exception {
780781
ImapMailReceiver mailReceiver = new ImapMailReceiver("imap:foo");
781782
ImapIdleChannelAdapter adapter = new ImapIdleChannelAdapter(mailReceiver);
782783
final AtomicReference<Object> theEvent = new AtomicReference<>();
@@ -795,8 +796,9 @@ public void testConnectionException() throws Exception {
795796
adapter.stop();
796797
}
797798

798-
@Test // see INT-1801
799-
public void testImapLifecycleForRaceCondition() throws Exception {
799+
// see INT-1801
800+
@Test
801+
void imapLifecycleForRaceCondition() throws Exception {
800802
final AtomicInteger failed = new AtomicInteger(0);
801803
for (int i = 0; i < 100; i++) {
802804
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
@@ -838,7 +840,7 @@ public void testImapLifecycleForRaceCondition() throws Exception {
838840
}
839841

840842
@Test
841-
public void testAttachments() throws Exception {
843+
void attachments() throws Exception {
842844
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
843845
Folder folder = testAttachmentsGuts(receiver);
844846
Message[] messages = (Message[]) receiver.receive();
@@ -850,7 +852,7 @@ public void testAttachments() throws Exception {
850852
}
851853

852854
@Test
853-
public void testAttachmentsWithMappingMultiAsBytes() throws Exception {
855+
void attachmentsWithMappingMultiAsBytes() throws Exception {
854856
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
855857
receiver.setHeaderMapper(new DefaultMailHeaderMapper());
856858
testAttachmentsGuts(receiver);
@@ -865,7 +867,7 @@ public void testAttachmentsWithMappingMultiAsBytes() throws Exception {
865867
}
866868

867869
@Test
868-
public void testAttachmentsWithMapping() throws Exception {
870+
void attachmentsWithMapping() throws Exception {
869871
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
870872
receiver.setHeaderMapper(new DefaultMailHeaderMapper());
871873
receiver.setEmbeddedPartsAsBytes(false);
@@ -897,7 +899,7 @@ private Folder testAttachmentsGuts(final ImapMailReceiver receiver) throws Messa
897899
}
898900

899901
@Test
900-
public void testNullMessages() throws Exception {
902+
void nullMessages() throws Exception {
901903
Message message1 = GreenMailUtil.newMimeMessage("test1");
902904
Message message2 = GreenMailUtil.newMimeMessage("test2");
903905
final Message[] messages1 = new Message[] {null, null, message1};
@@ -944,7 +946,7 @@ public Message[] receive() throws MessagingException {
944946
}
945947

946948
@Test
947-
public void testIdleReconnects() throws Exception {
949+
void idleReconnects() throws Exception {
948950
ImapMailReceiver receiver = spy(new ImapMailReceiver("imap:foo"));
949951
receiver.setBeanFactory(mock(BeanFactory.class));
950952
receiver.afterPropertiesSet();
@@ -989,7 +991,7 @@ private void setUpScheduler(ImapMailReceiver mailReceiver, ThreadPoolTaskSchedul
989991
}
990992

991993
@Test
992-
public void receiveAndMarkAsReadDontDeleteWithThrowingWhenCopying() throws Exception {
994+
void receiveAndMarkAsReadDontDeleteWithThrowingWhenCopying() throws Exception {
993995
AbstractMailReceiver receiver = new ImapMailReceiver();
994996
MimeMessage msg1 = spy(GreenMailUtil.newMimeMessage("test1"));
995997
MimeMessage greenMailMsg2 = GreenMailUtil.newMimeMessage("test2");

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,19 +40,19 @@
4040
* @author Oleg Zhurakousky
4141
* @author Gary Russell
4242
* @author Artem Bilan
43-
*
43+
* @author Ma Jiandong
4444
*/
4545
public class ImapMailSearchTermsTests {
4646

4747
@Test
48-
public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlags() throws Exception {
48+
void validateSearchTermsWhenShouldMarkAsReadNoExistingFlags() throws Exception {
4949
String userFlag = AbstractMailReceiver.DEFAULT_SI_USER_FLAG;
5050
ImapMailReceiver receiver = new ImapMailReceiver();
5151
validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(userFlag, receiver);
5252
}
5353

5454
@Test
55-
public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsCustom() throws Exception {
55+
void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsCustom() throws Exception {
5656
String userFlag = "foo";
5757
ImapMailReceiver receiver = new ImapMailReceiver();
5858
receiver.setUserFlag(userFlag);
@@ -82,7 +82,7 @@ public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(String us
8282
}
8383

8484
@Test
85-
public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
85+
void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
8686
ImapMailReceiver receiver = new ImapMailReceiver();
8787
receiver.setShouldMarkMessagesAsRead(true);
8888
receiver.setBeanFactory(mock(BeanFactory.class));
@@ -112,7 +112,7 @@ public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Ex
112112
}
113113

114114
@Test
115-
public void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
115+
void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
116116
ImapMailReceiver receiver = new ImapMailReceiver();
117117
receiver.setShouldMarkMessagesAsRead(false);
118118
receiver.setBeanFactory(mock(BeanFactory.class));

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,14 +40,15 @@
4040
/**
4141
* @author Gary Russell
4242
* @author Artem Bilan
43+
* @author Ma Jiandong
4344
*
4445
* @since 3.0.6
4546
*
4647
*/
47-
public class MailReceiverTests {
48+
class MailReceiverTests {
4849

4950
@Test
50-
public void testStoreConnectAndFolderCloseWhenNoMessages() throws Exception {
51+
void storeConnectAndFolderCloseWhenNoMessages() throws Exception {
5152
AbstractMailReceiver receiver = new AbstractMailReceiver() {
5253

5354
@Override

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,11 +31,12 @@
3131
* @author Mark Fisher
3232
* @author Gary Russell
3333
* @author Artem Bilan
34+
* @author Ma Jiandong
3435
*/
35-
public class MailReceivingMessageSourceTests {
36+
class MailReceivingMessageSourceTests {
3637

3738
@Test
38-
public void testPolling() {
39+
void polling() {
3940
StubMailReceiver mailReceiver = new StubMailReceiver();
4041
MimeMessage message1 = Mockito.mock(MimeMessage.class);
4142
MimeMessage message2 = Mockito.mock(MimeMessage.class);

0 commit comments

Comments
 (0)