Skip to content

Apply Junit5BestPractices in spring-integration-mail #9946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -111,6 +111,7 @@
* @author Alexander Pinske
* @author Dominik Simmen
* @author Filip Hrisafov
* @author Ma Jiandong
*/
@SpringJUnitConfig
@ContextConfiguration(
Expand Down Expand Up @@ -167,7 +168,7 @@ void stopImapServer() {
}

@Test
public void testIdleWithServerCustomSearch() throws Exception {
void idleWithServerCustomSearch() throws Exception {
ImapMailReceiver receiver =
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
receiver.setSearchTermStrategy((supportedFlags, folder) -> {
Expand All @@ -183,15 +184,15 @@ public void testIdleWithServerCustomSearch() throws Exception {
}

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

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

@Test
@Disabled
public void testIdleWithServerDefaultSearchSimple() throws Exception {
void idleWithServerDefaultSearchSimple() throws Exception {
ImapMailReceiver receiver =
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
receiver.setSimpleContent(true);
Expand All @@ -209,7 +210,7 @@ public void testIdleWithServerDefaultSearchSimple() throws Exception {
}

@Test
public void testIdleWithMessageMappingSimple() throws Exception {
void idleWithMessageMappingSimple() throws Exception {
ImapMailReceiver receiver =
new ImapMailReceiver("imap://user:pw@localhost:" + imapIdleServer.getImap().getPort() + "/INBOX");
receiver.setSimpleContent(true);
Expand Down Expand Up @@ -289,7 +290,7 @@ public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped, bo
}

@Test
public void receiveAndMarkAsReadDontDelete() throws Exception {
void receiveAndMarkAsReadDontDelete() throws Exception {
user.deliver(GreenMailUtil.createTextEmail("user", "sender", "subject", "body",
imapIdleServer.getImap().getServerSetup()));
AbstractMailReceiver receiver = new ImapMailReceiver();
Expand Down Expand Up @@ -342,7 +343,7 @@ private AbstractMailReceiver receiveAndMarkAsReadDontDeleteGuts(AbstractMailRece
}

@Test
public void receiveAndMarkAsReadDontDeletePassingFilter() throws Exception {
void receiveAndMarkAsReadDontDeletePassingFilter() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();
Message msg1 = GreenMailUtil.newMimeMessage("test1");
Message msg2 = GreenMailUtil.newMimeMessage("test2");
Expand All @@ -355,7 +356,7 @@ public void receiveAndMarkAsReadDontDeletePassingFilter() throws Exception {
}

@Test
public void receiveAndMarkAsReadDontDeleteFiltered() throws Exception {
void receiveAndMarkAsReadDontDeleteFiltered() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();
Message msg1 = GreenMailUtil.newMimeMessage("test1");
Message msg2 = spy(GreenMailUtil.newMimeMessage("test2"));
Expand All @@ -370,7 +371,7 @@ public void receiveAndMarkAsReadDontDeleteFiltered() throws Exception {
}

@Test
public void receiveAndDebugIsDisabledNotLogFiltered() throws Exception {
void receiveAndDebugIsDisabledNotLogFiltered() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();

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

@Test
public void receiveExpungedAndNotExpungedLogFiltered() throws Exception {
void receiveExpungedAndNotExpungedLogFiltered() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();

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

@Test
public void receiveMarkAsReadAndDelete() throws Exception {
void receiveMarkAsReadAndDelete() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();
((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(true);
receiver.setShouldDeleteMessages(true);
Expand Down Expand Up @@ -453,7 +454,7 @@ public void receiveMarkAsReadAndDelete() throws Exception {
}

@Test
public void receiveAndDontMarkAsRead() throws Exception {
void receiveAndDontMarkAsRead() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();
((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(false);
receiver = spy(receiver);
Expand Down Expand Up @@ -482,7 +483,7 @@ public void receiveAndDontMarkAsRead() throws Exception {
}

@Test
public void receiveAndDontMarkAsReadButDelete() throws Exception {
void receiveAndDontMarkAsReadButDelete() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();
receiver.setShouldDeleteMessages(true);
((ImapMailReceiver) receiver).setShouldMarkMessagesAsRead(false);
Expand Down Expand Up @@ -522,7 +523,7 @@ public void receiveAndDontMarkAsReadButDelete() throws Exception {
}

@Test
public void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();
receiver = spy(receiver);
receiver.setBeanFactory(mock(BeanFactory.class));
Expand Down Expand Up @@ -557,7 +558,7 @@ public void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
}

@Test
public void testMessageHistory() throws Exception {
void messageHistory() throws Exception {
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
adapter.setReconnectDelay(10);

Expand Down Expand Up @@ -600,7 +601,7 @@ public void testMessageHistory() throws Exception {
}

@Test
public void testIdleChannelAdapterException() throws Exception {
void idleChannelAdapterException() throws Exception {
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);

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

@SuppressWarnings("resource")
@Test
public void testNoInitialIdleDelayWhenRecentNotSupported() throws Exception {
void noInitialIdleDelayWhenRecentNotSupported() throws Exception {
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);

QueueChannel channel = new QueueChannel();
Expand Down Expand Up @@ -721,7 +722,7 @@ public void testNoInitialIdleDelayWhenRecentNotSupported() throws Exception {
}

@Test
public void testInitialIdleDelayWhenRecentIsSupported() throws Exception {
void initialIdleDelayWhenRecentIsSupported() throws Exception {
ImapIdleChannelAdapter adapter = this.context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);

QueueChannel channel = new QueueChannel();
Expand Down Expand Up @@ -776,7 +777,7 @@ public void testInitialIdleDelayWhenRecentIsSupported() throws Exception {
}

@Test
public void testConnectionException() throws Exception {
void connectionException() throws Exception {
ImapMailReceiver mailReceiver = new ImapMailReceiver("imap:foo");
ImapIdleChannelAdapter adapter = new ImapIdleChannelAdapter(mailReceiver);
final AtomicReference<Object> theEvent = new AtomicReference<>();
Expand All @@ -795,8 +796,9 @@ public void testConnectionException() throws Exception {
adapter.stop();
}

@Test // see INT-1801
public void testImapLifecycleForRaceCondition() throws Exception {
// see INT-1801
@Test
void imapLifecycleForRaceCondition() throws Exception {
final AtomicInteger failed = new AtomicInteger(0);
for (int i = 0; i < 100; i++) {
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
Expand Down Expand Up @@ -838,7 +840,7 @@ public void testImapLifecycleForRaceCondition() throws Exception {
}

@Test
public void testAttachments() throws Exception {
void attachments() throws Exception {
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
Folder folder = testAttachmentsGuts(receiver);
Message[] messages = (Message[]) receiver.receive();
Expand All @@ -850,7 +852,7 @@ public void testAttachments() throws Exception {
}

@Test
public void testAttachmentsWithMappingMultiAsBytes() throws Exception {
void attachmentsWithMappingMultiAsBytes() throws Exception {
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
receiver.setHeaderMapper(new DefaultMailHeaderMapper());
testAttachmentsGuts(receiver);
Expand All @@ -865,7 +867,7 @@ public void testAttachmentsWithMappingMultiAsBytes() throws Exception {
}

@Test
public void testAttachmentsWithMapping() throws Exception {
void attachmentsWithMapping() throws Exception {
final ImapMailReceiver receiver = new ImapMailReceiver("imap://foo");
receiver.setHeaderMapper(new DefaultMailHeaderMapper());
receiver.setEmbeddedPartsAsBytes(false);
Expand Down Expand Up @@ -897,7 +899,7 @@ private Folder testAttachmentsGuts(final ImapMailReceiver receiver) throws Messa
}

@Test
public void testNullMessages() throws Exception {
void nullMessages() throws Exception {
Message message1 = GreenMailUtil.newMimeMessage("test1");
Message message2 = GreenMailUtil.newMimeMessage("test2");
final Message[] messages1 = new Message[] {null, null, message1};
Expand Down Expand Up @@ -944,7 +946,7 @@ public Message[] receive() throws MessagingException {
}

@Test
public void testIdleReconnects() throws Exception {
void idleReconnects() throws Exception {
ImapMailReceiver receiver = spy(new ImapMailReceiver("imap:foo"));
receiver.setBeanFactory(mock(BeanFactory.class));
receiver.afterPropertiesSet();
Expand Down Expand Up @@ -989,7 +991,7 @@ private void setUpScheduler(ImapMailReceiver mailReceiver, ThreadPoolTaskSchedul
}

@Test
public void receiveAndMarkAsReadDontDeleteWithThrowingWhenCopying() throws Exception {
void receiveAndMarkAsReadDontDeleteWithThrowingWhenCopying() throws Exception {
AbstractMailReceiver receiver = new ImapMailReceiver();
MimeMessage msg1 = spy(GreenMailUtil.newMimeMessage("test1"));
MimeMessage greenMailMsg2 = GreenMailUtil.newMimeMessage("test2");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,19 +40,19 @@
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*
* @author Ma Jiandong
*/
public class ImapMailSearchTermsTests {

@Test
public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlags() throws Exception {
void validateSearchTermsWhenShouldMarkAsReadNoExistingFlags() throws Exception {
String userFlag = AbstractMailReceiver.DEFAULT_SI_USER_FLAG;
ImapMailReceiver receiver = new ImapMailReceiver();
validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(userFlag, receiver);
}

@Test
public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsCustom() throws Exception {
void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsCustom() throws Exception {
String userFlag = "foo";
ImapMailReceiver receiver = new ImapMailReceiver();
receiver.setUserFlag(userFlag);
Expand Down Expand Up @@ -82,7 +82,7 @@ public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(String us
}

@Test
public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
ImapMailReceiver receiver = new ImapMailReceiver();
receiver.setShouldMarkMessagesAsRead(true);
receiver.setBeanFactory(mock(BeanFactory.class));
Expand Down Expand Up @@ -112,7 +112,7 @@ public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Ex
}

@Test
public void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
ImapMailReceiver receiver = new ImapMailReceiver();
receiver.setShouldMarkMessagesAsRead(false);
receiver.setBeanFactory(mock(BeanFactory.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,14 +40,15 @@
/**
* @author Gary Russell
* @author Artem Bilan
* @author Ma Jiandong
*
* @since 3.0.6
*
*/
public class MailReceiverTests {
class MailReceiverTests {

@Test
public void testStoreConnectAndFolderCloseWhenNoMessages() throws Exception {
void storeConnectAndFolderCloseWhenNoMessages() throws Exception {
AbstractMailReceiver receiver = new AbstractMailReceiver() {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,11 +31,12 @@
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @author Ma Jiandong
*/
public class MailReceivingMessageSourceTests {
class MailReceivingMessageSourceTests {

@Test
public void testPolling() {
void polling() {
StubMailReceiver mailReceiver = new StubMailReceiver();
MimeMessage message1 = Mockito.mock(MimeMessage.class);
MimeMessage message2 = Mockito.mock(MimeMessage.class);
Expand Down
Loading