diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java index 53288be2df8..f0d70657d73 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2023 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. @@ -22,10 +22,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; -import org.junit.After; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.core.MessageListener; @@ -33,7 +31,8 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.amqp.rabbit.junit.BrokerRunning; +import org.springframework.amqp.rabbit.junit.RabbitAvailable; +import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition; import org.springframework.amqp.rabbit.listener.BlockingQueueConsumer; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.support.converter.MessageConversionException; @@ -49,8 +48,7 @@ import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -65,15 +63,11 @@ * @since 4.0 * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@RabbitAvailable(queues = {"pollableWithEP", "withEP", "testConvertFail"}) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class ChannelTests { - @ClassRule - public static final BrokerRunning brokerIsRunning = - BrokerRunning.isRunningWithEmptyQueues("pollableWithEP", "withEP", "testConvertFail"); - @Autowired private PublishSubscribeAmqpChannel channel; @@ -98,10 +92,10 @@ public class ChannelTests { @Autowired private AmqpHeaderMapper mapperOut; - @After + @AfterEach public void tearDown() { - brokerIsRunning.deleteExchanges("si.fanout.foo", "si.fanout.channel", "si.fanout.pubSubWithEP"); - brokerIsRunning.removeTestQueues(); + RabbitAvailableCondition.getBrokerRunning().deleteExchanges("si.fanout.foo", "si.fanout.channel", "si.fanout.pubSubWithEP"); + RabbitAvailableCondition.getBrokerRunning().removeTestQueues(); } @Test diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java index a84fe2bed05..0ccf45d7d1a 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java @@ -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. @@ -18,8 +18,7 @@ import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.MessageDeliveryMode; import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer; @@ -35,8 +34,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -45,8 +43,7 @@ * @author Gary Russell * @since 2.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class AmqpChannelParserTests { diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java index 1c9c42b4e01..47fd12b186d 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java @@ -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. @@ -20,8 +20,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.amqp.core.MessageDeliveryMode; @@ -42,7 +41,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -57,7 +56,7 @@ * @since 2.1 * */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class AmqpOutboundGatewayParserTests { diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayIntegrationTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayIntegrationTests.java index fb6aa7d1845..35c5204effe 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayIntegrationTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayIntegrationTests.java @@ -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. @@ -16,19 +16,16 @@ package org.springframework.integration.amqp.config; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; -import org.springframework.amqp.rabbit.junit.BrokerRunning; +import org.springframework.amqp.rabbit.junit.RabbitAvailable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -38,14 +35,11 @@ * @author Gary Russell * @since 2.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@RabbitAvailable @DirtiesContext public class OutboundGatewayIntegrationTests { - @ClassRule - public static final BrokerRunning brokerIsRunning = BrokerRunning.isRunning(); - @Autowired private MessageChannel toRabbit; diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/AmqpMessageSourceTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/AmqpMessageSourceTests.java index 45a2144ef11..e464f4a6708 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/AmqpMessageSourceTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/AmqpMessageSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-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. @@ -25,7 +25,7 @@ import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.GetResponse; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.batch.MessageBatch; diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/ManualAckTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/ManualAckTests.java index c9fd8fb1ad8..e8839f0b466 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/ManualAckTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/ManualAckTests.java @@ -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. @@ -17,9 +17,7 @@ package org.springframework.integration.amqp.inbound; import com.rabbitmq.client.Channel; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.AcknowledgeMode; import org.springframework.amqp.core.AnonymousQueue; @@ -27,7 +25,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.amqp.rabbit.junit.BrokerRunning; +import org.springframework.amqp.rabbit.junit.RabbitAvailable; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.support.AmqpHeaders; import org.springframework.beans.factory.BeanFactory; @@ -35,7 +33,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.integration.amqp.inbound.ManualAckTests.ManualAckConfig; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.channel.QueueChannel; @@ -46,8 +43,7 @@ import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -57,14 +53,11 @@ * @since 4.0 * */ -@ContextConfiguration(classes = ManualAckConfig.class) -@RunWith(SpringJUnit4ClassRunner.class) +@RabbitAvailable +@SpringJUnitConfig @DirtiesContext public class ManualAckTests { - @Rule - public BrokerRunning brokerRunning = BrokerRunning.isRunning(); - @Autowired private MessageChannel foo; diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/JsonConverterCompatibilityTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/JsonConverterCompatibilityTests.java index f67c115bfb7..445f80a9014 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/JsonConverterCompatibilityTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/JsonConverterCompatibilityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-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. @@ -17,15 +17,15 @@ package org.springframework.integration.amqp.support; import com.rabbitmq.client.AMQP.BasicProperties; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.amqp.rabbit.junit.BrokerRunning; +import org.springframework.amqp.rabbit.junit.RabbitAvailable; +import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition; import org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.integration.json.ObjectToJsonTransformer; @@ -39,24 +39,22 @@ * @since 4.3 * */ +@RabbitAvailable(queues = {JsonConverterCompatibilityTests.JSON_TESTQ}) public class JsonConverterCompatibilityTests { - private static final String JSON_TESTQ = "si.json.tests"; - - @Rule - public BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues(JSON_TESTQ); + public static final String JSON_TESTQ = "si.json.tests"; private RabbitTemplate rabbitTemplate; - @Before + @BeforeEach public void setUp() { this.rabbitTemplate = new RabbitTemplate(new CachingConnectionFactory("localhost")); this.rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter()); } - @After + @AfterEach public void tearDown() { - this.brokerRunning.removeTestQueues(); + RabbitAvailableCondition.getBrokerRunning().removeTestQueues(); ((CachingConnectionFactory) this.rabbitTemplate.getConnectionFactory()).destroy(); } diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/MappingUtilsTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/MappingUtilsTests.java index 2e5c8a58cf1..3625350dd26 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/MappingUtilsTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/MappingUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-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. @@ -16,7 +16,7 @@ package org.springframework.integration.amqp.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.MessageDeliveryMode; import org.springframework.amqp.support.AmqpHeaders; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/AutoCreateDirectoryTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/AutoCreateDirectoryTests.java index caac6359add..575c191f431 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/AutoCreateDirectoryTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/AutoCreateDirectoryTests.java @@ -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. @@ -18,9 +18,9 @@ import java.io.File; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; @@ -44,8 +44,8 @@ public class AutoCreateDirectoryTests { private static final String OUTBOUND_PATH = BASE_PATH + File.separator + "outbound"; - @Before - @After + @BeforeEach + @AfterEach public void clearDirectories() { File baseDir = new File(BASE_PATH); File inboundDir = new File(INBOUND_PATH); @@ -92,13 +92,14 @@ public void autoCreateForOutboundEnabledByDefault() { assertThat(new File(OUTBOUND_PATH).exists()).isTrue(); } - @Test(expected = IllegalArgumentException.class) + @Test public void autoCreateForOutboundDisabled() { FileWritingMessageHandler handler = new FileWritingMessageHandler( new File(OUTBOUND_PATH)); handler.setBeanFactory(mock(BeanFactory.class)); handler.setAutoCreateDirectory(false); - handler.afterPropertiesSet(); + assertThatIllegalArgumentException() + .isThrownBy(handler::afterPropertiesSet); } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests-context.xml index f26440d9023..b03f4afef8f 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests-context.xml @@ -13,7 +13,7 @@ @@ -34,7 +34,7 @@ + directory="#{T (org.springframework.integration.file.FileInboundTransactionTests).tmpDir}/si-test2"> diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests.java index 44cea26b694..fa2a32ca274 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileInboundTransactionTests.java @@ -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. @@ -20,10 +20,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -35,8 +33,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.SubscribableChannel; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; import org.springframework.transaction.support.AbstractPlatformTransactionManager; @@ -52,13 +49,12 @@ * @since 2.2 * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class FileInboundTransactionTests { - @ClassRule - public static TemporaryFolder tmpDir = new TemporaryFolder(); + @TempDir + public static File tmpDir; @Autowired private SourcePollingChannelAdapter pseudoTx; @@ -102,14 +98,14 @@ public void testNoTx() throws Exception { latch.countDown(); }); pseudoTx.start(); - File file = new File(tmpDir.getRoot(), "si-test1/foo"); + File file = new File(tmpDir, "si-test1/foo"); file.createNewFile(); Message result = successChannel.receive(60000); assertThat(result).isNotNull(); assertThat(result.getPayload()).isEqualTo(Boolean.TRUE); assertThat(file.delete()).isFalse(); crash.set(true); - file = new File(tmpDir.getRoot(), "si-test1/bar"); + file = new File(tmpDir, "si-test1/bar"); file.createNewFile(); result = failureChannel.receive(60000); assertThat(result).isNotNull(); @@ -119,7 +115,7 @@ public void testNoTx() throws Exception { assertThat(transactionManager.getCommitted()).isFalse(); assertThat(transactionManager.getRolledBack()).isFalse(); - verify(fileListFilter).remove(new File(tmpDir.getRoot(), "si-test1/foo")); + verify(fileListFilter).remove(new File(tmpDir, "si-test1/foo")); } @Test @@ -133,7 +129,7 @@ public void testTx() throws Exception { latch.countDown(); }); realTx.start(); - File file = new File(tmpDir.getRoot(), "si-test2/baz"); + File file = new File(tmpDir, "si-test2/baz"); file.createNewFile(); Message result = successChannel.receive(60000); assertThat(result).isNotNull(); @@ -141,7 +137,7 @@ public void testTx() throws Exception { assertThat(file.delete()).isTrue(); assertThat(transactionManager.getCommitted()).isTrue(); crash.set(true); - file = new File(tmpDir.getRoot(), "si-test2/qux"); + file = new File(tmpDir, "si-test2/qux"); file.createNewFile(); result = failureChannel.receive(60000); assertThat(result).isNotNull(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java index 788756c864f..469f38d628e 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java @@ -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. @@ -18,16 +18,14 @@ import java.io.File; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -35,8 +33,7 @@ * @author Iwein Fuld * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class FileToChannelIntegrationTests { diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java index 37c1bd5261d..55d1dd0b6f2 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/PatternMatchingFileListFilterTests.java @@ -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. @@ -20,7 +20,7 @@ import java.util.List; import java.util.regex.Pattern; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -28,6 +28,7 @@ import org.springframework.integration.file.filters.RegexPatternFileListFilter; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Mark Fisher @@ -80,9 +81,10 @@ public void patternEditorInContext() { context.close(); } - @Test(expected = BeanCreationException.class) + @Test public void invalidPatternSyntax() throws Throwable { - new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass()).close(); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass())); } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/RecursiveDirectoryScannerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/RecursiveDirectoryScannerTests.java index d73e89c31ba..92bc4f6e985 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/RecursiveDirectoryScannerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/RecursiveDirectoryScannerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-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. @@ -20,10 +20,9 @@ import java.io.IOException; import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.integration.file.filters.AcceptOnceFileListFilter; @@ -49,15 +48,16 @@ public class RecursiveDirectoryScannerTests { private File subSubLevelFile; - @Rule - public TemporaryFolder recursivePath = new TemporaryFolder(); + @TempDir + public File recursivePath; - @Before + @BeforeEach public void setup() throws IOException { - this.subFolder = this.recursivePath.newFolder("subFolder"); + this.subFolder = new File(this.recursivePath, "subFolder"); this.subSubFolder = new File(this.subFolder, "subSubFolder"); - this.subSubFolder.mkdir(); - this.topLevelFile = this.recursivePath.newFile("file1"); + this.subSubFolder.mkdirs(); + this.topLevelFile = new File(this.recursivePath, "file1"); + this.topLevelFile.createNewFile(); this.subLevelFile = new File(this.subFolder, "file2"); this.subLevelFile.createNewFile(); this.subSubLevelFile = new File(this.subSubFolder, "file3"); @@ -68,7 +68,7 @@ public void setup() throws IOException { public void shouldReturnAllFilesIncludingDirs() throws IOException { RecursiveDirectoryScanner scanner = new RecursiveDirectoryScanner(); scanner.setFilter(new AcceptOnceFileListFilter<>()); - List files = scanner.listFiles(this.recursivePath.getRoot()); + List files = scanner.listFiles(this.recursivePath); assertThat(files.size()).isEqualTo(5); assertThat(files).contains(this.topLevelFile); assertThat(files).contains(this.subLevelFile); @@ -77,7 +77,7 @@ public void shouldReturnAllFilesIncludingDirs() throws IOException { assertThat(files).contains(this.subSubFolder); File file = new File(this.subSubFolder, "file4"); file.createNewFile(); - files = scanner.listFiles(this.recursivePath.getRoot()); + files = scanner.listFiles(this.recursivePath); assertThat(files.size()).isEqualTo(1); assertThat(files).contains(file); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/AutoCreateDirectoryIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/AutoCreateDirectoryIntegrationTests.java index 5b06424d1fd..e56e2912791 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/AutoCreateDirectoryIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/AutoCreateDirectoryIntegrationTests.java @@ -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. @@ -18,10 +18,9 @@ import java.io.File; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -29,7 +28,7 @@ import org.springframework.integration.file.FileReadingMessageSource; import org.springframework.integration.file.FileWritingMessageHandler; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +36,7 @@ * @author Mark Fisher * @author Artem Bilan */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class AutoCreateDirectoryIntegrationTests { @@ -48,7 +47,7 @@ public class AutoCreateDirectoryIntegrationTests { @Autowired private ApplicationContext context; - @BeforeClass + @BeforeAll public static void setupNonAutoCreatedDirectories() { new File(BASE_PATH).delete(); new File(BASE_PATH + File.separator + "customInbound").mkdirs(); @@ -56,7 +55,7 @@ public static void setupNonAutoCreatedDirectories() { new File(BASE_PATH + File.separator + "customOutboundGateway").mkdirs(); } - @AfterClass + @AfterAll public static void deleteBaseDirectory() { new File(BASE_PATH).delete(); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java index 5dc1d11d775..1153b33b1d1 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/ChainElementsTests.java @@ -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. @@ -20,9 +20,9 @@ import java.util.Locale; import java.util.Properties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; @@ -46,13 +46,13 @@ public class ChainElementsTests { private Locale localeBeforeTest; - @Before + @BeforeEach public void setUp() { localeBeforeTest = Locale.getDefault(); Locale.setDefault(new Locale("en", "US")); } - @After + @AfterEach public void tearDown() { Locale.setDefault(localeBeforeTest); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileListFilterFactoryBeanTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileListFilterFactoryBeanTests.java index 0dcda8d2985..663311b680a 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileListFilterFactoryBeanTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileListFilterFactoryBeanTests.java @@ -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. @@ -20,7 +20,7 @@ import java.util.Collection; import java.util.Iterator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.integration.file.filters.AbstractFileListFilter; @@ -31,6 +31,7 @@ import org.springframework.integration.test.util.TestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; /** * @author Mark Fisher @@ -39,13 +40,13 @@ */ public class FileListFilterFactoryBeanTests { - @Test(expected = IllegalArgumentException.class) + @Test public void customFilterAndFilenamePatternAreMutuallyExclusive() throws Exception { FileListFilterFactoryBean factory = new FileListFilterFactoryBean(); factory.setIgnoreHidden(false); factory.setFilter(new TestFilter()); factory.setFilenamePattern("foo"); - factory.getObject(); + assertThatIllegalArgumentException().isThrownBy(factory::getObject); } @Test diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/file-message-history-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests-context.xml similarity index 90% rename from spring-integration-file/src/test/java/org/springframework/integration/file/config/file-message-history-context.xml rename to spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests-context.xml index 80db2acc563..69af4ae5a9d 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/file-message-history-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests-context.xml @@ -10,9 +10,7 @@ - - - diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java index be776fda1e6..d65a525859b 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java @@ -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. @@ -21,14 +21,15 @@ import java.io.FileWriter; import java.util.Properties; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; -import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -38,20 +39,22 @@ * @author Gunnar Hillert * @author Artem Bilan */ +@SpringJUnitConfig public class FileMessageHistoryTests { + @TempDir + public static File tempFolder; + + @Autowired + PollableChannel outChannel; + @Test public void testMessageHistory() throws Exception { - ClassPathXmlApplicationContext context = - new ClassPathXmlApplicationContext("file-message-history-context.xml", getClass()); - - TemporaryFolder input = context.getBean(TemporaryFolder.class); - File file = input.newFile("FileMessageHistoryTest.txt"); + File file = new File(tempFolder, "FileMessageHistoryTest.txt"); BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write("hello"); out.close(); - PollableChannel outChannel = context.getBean("outChannel", PollableChannel.class); Message message = outChannel.receive(10000); assertThat(message).isNotNull(); MessageHistory history = MessageHistory.read(message); @@ -60,7 +63,6 @@ public void testMessageHistory() throws Exception { assertThat(componentHistoryRecord).isNotNull(); assertThat(componentHistoryRecord.get("type")).isEqualTo("file:inbound-channel-adapter"); - context.close(); } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java index 50b06ed2d2b..efd8c66a51d 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserTests.java @@ -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. @@ -23,8 +23,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -42,8 +41,7 @@ import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.FileCopyUtils; import org.springframework.util.ReflectionUtils; @@ -61,8 +59,7 @@ * @author Artem Bilan * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class FileOutboundChannelAdapterParserTests { diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserWithErrorsTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserWithErrorsTests.java index 7e74987d0c7..a3c924cc0f8 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserWithErrorsTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundChannelAdapterParserWithErrorsTests.java @@ -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. @@ -16,7 +16,7 @@ package org.springframework.integration.file.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests-context.xml index 28b32100cc2..3ea9cc1a0b8 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests-context.xml @@ -18,11 +18,11 @@ static-field="org.springframework.integration.file.config.FileOutboundGatewayParserTests.tempFolder"/> @@ -33,32 +33,32 @@ + directory="#{temporaryFolder}" requires-reply="false"/> + directory="#{temporaryFolder}"/> + directory="#{temporaryFolder}"/> + directory="#{temporaryFolder}"/> + directory="#{temporaryFolder}"/> + directory="#{temporaryFolder}"/> diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests.java index 22cf4240ba1..29d2ba468fc 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundGatewayParserTests.java @@ -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. @@ -18,11 +18,9 @@ import java.io.File; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -40,7 +38,7 @@ import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.FileCopyUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -52,12 +50,12 @@ * @author Artem Bilan * @author Tony Falabella */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class FileOutboundGatewayParserTests { - @ClassRule - public static final TemporaryFolder tempFolder = new TemporaryFolder(); + @TempDir + public static File tempFolder; @Autowired private EventDrivenConsumer ordered; @@ -89,9 +87,12 @@ public class FileOutboundGatewayParserTests { private static volatile int adviceCalled; - @Before + @BeforeEach public void setup() { - tempFolder.delete(); + File[] files = tempFolder.listFiles(); + for (File file : files) { + file.delete(); + } } @Test @@ -120,7 +121,7 @@ public void testOutboundGatewayWithDirectoryExpression() { FileWritingMessageHandler handler = TestUtils.getPropertyValue(gatewayWithDirectoryExpression, "handler", FileWritingMessageHandler.class); assertThat(TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class) - .getExpressionString()).isEqualTo("temporaryFolder.root"); + .getExpressionString()).isEqualTo("temporaryFolder"); handler.handleMessage(new GenericMessage<>("foo")); assertThat(adviceCalled).isEqualTo(1); } @@ -140,7 +141,7 @@ public void gatewayWithIgnoreMode() throws Exception { messagingTemplate.setDefaultDestination(this.gatewayWithIgnoreModeChannel); final String expectedFileContent = "Initial File Content:"; - final File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt"); + final File testFile = new File(tempFolder, "fileToAppend.txt"); messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:")); @@ -172,7 +173,7 @@ public void gatewayWithFailMode() throws Exception { String expectedFileContent = "Initial File Content:"; - File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt"); + File testFile = new File(tempFolder, "fileToAppend.txt"); messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:")); @@ -199,7 +200,7 @@ public void gatewayWithFailModeLowercase() throws Exception { String expectedFileContent = "Initial File Content:"; - File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt"); + File testFile = new File(tempFolder, "fileToAppend.txt"); messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:")); @@ -228,7 +229,7 @@ public void gatewayWithAppendMode() throws Exception { String expectedFileContent = "Initial File Content:String content:"; - File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt"); + File testFile = new File(tempFolder, "fileToAppend.txt"); messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:")); Message m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:")); @@ -263,7 +264,7 @@ public void gatewayWithReplaceMode() throws Exception { String expectedFileContent = "String content:"; - File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt"); + File testFile = new File(tempFolder, "fileToAppend.txt"); messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:")); Message m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:")); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilterTests.java index 8f27c743e5d..0b4c40e00cf 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-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. @@ -21,7 +21,7 @@ import java.util.Map; import java.util.function.Function; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AcceptOnceFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AcceptOnceFileListFilterTests.java index 937551edab0..559fe7b62b6 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AcceptOnceFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/AcceptOnceFileListFilterTests.java @@ -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. @@ -22,7 +22,7 @@ import java.util.Queue; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.integration.test.util.TestUtils; import org.springframework.util.StopWatch; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/ChainFileListFilterIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/ChainFileListFilterIntegrationTests.java index a89110e4d3b..25d7528b209 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/ChainFileListFilterIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/ChainFileListFilterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-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. @@ -21,7 +21,7 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/FileSystemMarkerFilePresentFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/FileSystemMarkerFilePresentFileListFilterTests.java index 372378170b6..64e83962341 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/FileSystemMarkerFilePresentFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/FileSystemMarkerFilePresentFileListFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-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. @@ -19,9 +19,8 @@ import java.io.File; import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import static org.assertj.core.api.Assertions.assertThat; @@ -32,17 +31,17 @@ */ public class FileSystemMarkerFilePresentFileListFilterTests { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); + @TempDir + public File folder; @Test public void test() throws Exception { FileSystemMarkerFilePresentFileListFilter filter = new FileSystemMarkerFilePresentFileListFilter( new SimplePatternFileListFilter("*.txt")); - File foo = this.folder.newFile("foo.txt"); + File foo = new File(folder, "foo.txt"); foo.createNewFile(); assertThat(filter.filterFiles(new File[] {foo}).size()).isEqualTo(0); - File complete = this.folder.newFile("foo.txt.complete"); + File complete = new File(folder, "foo.txt.complete"); complete.createNewFile(); List filtered = filter.filterFiles(new File[] {foo, complete}); assertThat(filtered.size()).isEqualTo(1); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/SimplePatternFileListFilterTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/SimplePatternFileListFilterTests.java index 68959899400..d8497a24691 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/filters/SimplePatternFileListFilterTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/filters/SimplePatternFileListFilterTests.java @@ -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. @@ -18,7 +18,7 @@ import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileChannelCacheTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileChannelCacheTests.java index bd8cdf16ef1..6c62a510a0f 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileChannelCacheTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileChannelCacheTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * Copyright 2019-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. @@ -19,9 +19,8 @@ import java.io.File; import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import static org.assertj.core.api.Assertions.assertThat; @@ -31,12 +30,12 @@ */ public class FileChannelCacheTests { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); + @TempDir + public File temp; @Test public void throwsExceptionWhenFileNotExists() throws IOException { - File testFile = new File(temp.getRoot(), "test0"); + File testFile = new File(temp, "test0"); assertThat(testFile.exists()).isFalse(); assertThat(FileChannelCache.tryLockFor(testFile)).isNull(); assertThat(testFile.exists()).isFalse(); @@ -44,7 +43,7 @@ public void throwsExceptionWhenFileNotExists() throws IOException { @Test public void fileLocked() throws IOException { - File testFile = temp.newFile("test1"); + File testFile = new File(temp, "test1"); testFile.createNewFile(); assertThat(testFile.exists()).isTrue(); assertThat(FileChannelCache.tryLockFor(testFile)).isNotNull(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java index cb8a124ebdf..edc983e0341 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java @@ -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. @@ -18,9 +18,8 @@ import java.io.File; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -29,7 +28,7 @@ import org.springframework.integration.file.FileReadingMessageSource; import org.springframework.integration.file.filters.CompositeFileListFilter; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +37,7 @@ * @author Gunnar Hillert * @author Artme Bilan */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class FileLockingNamespaceTests { @@ -54,7 +53,7 @@ public class FileLockingNamespaceTests { FileReadingMessageSource customLockingSource; - @Before + @BeforeEach public void extractSources() { nioLockingSource = (FileReadingMessageSource) new DirectFieldAccessor(nioAdapter).getPropertyValue("source"); customLockingSource = diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingWithMultipleSourcesIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingWithMultipleSourcesIntegrationTests.java index aa634d1f5c1..c4df282711d 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingWithMultipleSourcesIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingWithMultipleSourcesIntegrationTests.java @@ -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. @@ -19,17 +19,16 @@ import java.io.File; import java.io.IOException; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.file.FileReadingMessageSource; import org.springframework.messaging.Message; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -37,13 +36,13 @@ * @author Iwein Fuld * @author Artem Bilan */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class FileLockingWithMultipleSourcesIntegrationTests { private static File workdir; - @BeforeClass + @BeforeAll public static void setupWorkDirectory() { workdir = new File(new File(System.getProperty("java.io.tmpdir")), FileLockingWithMultipleSourcesIntegrationTests.class.getSimpleName()); @@ -62,7 +61,7 @@ public static void setupWorkDirectory() { @Qualifier("fileSource2") private FileReadingMessageSource fileSource3; - @Before + @BeforeEach public void cleanoutWorkDir() { for (File file : workdir.listFiles()) { file.delete(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/NioFileLockerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/NioFileLockerTests.java index e9f1bb9dc48..3e7fb0ae0b5 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/NioFileLockerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/NioFileLockerTests.java @@ -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. @@ -22,9 +22,8 @@ import java.util.ArrayList; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.test.util.TestUtils; @@ -38,18 +37,9 @@ */ public class NioFileLockerTests { + @TempDir private File workdir; - @Rule - public TemporaryFolder temp = new TemporaryFolder() { - - @Override - public void create() throws IOException { - super.create(); - workdir = temp.newFolder(NioFileLockerTests.class.getSimpleName()); - } - }; - @Test public void fileListedByFirstFilter() throws Exception { NioFileLocker filter = new NioFileLocker(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java index c044b1d16c9..c0964dcc2cf 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java @@ -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. @@ -21,7 +21,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.BeanFactory; @@ -38,6 +38,7 @@ import org.springframework.messaging.support.GenericMessage; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; @@ -124,7 +125,7 @@ public void testRemoteDirWithNull() throws Exception { } @SuppressWarnings("unchecked") - @Test(expected = IllegalArgumentException.class) + @Test public void testEmptyTemporaryFileSuffixCannotBeNull() throws Exception { SessionFactory sf = mock(SessionFactory.class); Session session = mock(Session.class); @@ -132,8 +133,8 @@ public void testEmptyTemporaryFileSuffixCannotBeNull() throws Exception { FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sf); handler.setBeanFactory(mock(BeanFactory.class)); handler.setRemoteDirectoryExpressionString("headers['path']"); - handler.setTemporaryFileSuffix(null); - handler.onInit(); + assertThatIllegalArgumentException() + .isThrownBy(() -> handler.setTemporaryFileSuffix(null)); } @SuppressWarnings("unchecked") diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java index fd031a8bd21..3859a5c2ca3 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/FileTailingMessageProducerTests.java @@ -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. @@ -25,10 +25,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; @@ -57,9 +56,6 @@ public class FileTailingMessageProducerTests { private static final String TAIL_OPTIONS_FOLLOW_NAME_ALL_LINES = "-F -n +0"; - @Rule - public TailRule tailRule = new TailRule(TAIL_OPTIONS_FOLLOW_NAME_ALL_LINES); - private final Log logger = LogFactory.getLog(this.getClass()); private final String tmpDir = System.getProperty("java.io.tmpdir"); @@ -68,14 +64,14 @@ public class FileTailingMessageProducerTests { private FileTailingMessageProducerSupport adapter; - @Before + @BeforeEach public void setup() { File f = new File(tmpDir, "FileTailingMessageProducerTests"); f.mkdir(); this.testDir = f; } - @After + @AfterEach public void tearDown() { if (this.adapter != null) { adapter.stop(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailAvailable.java b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailAvailable.java index afcb4921be4..e17cfe27160 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailAvailable.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailAvailable.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 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. @@ -21,13 +21,23 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.api.extension.ExtendWith; + /** * @author Gary Russell * @since 3.0 * */ +@ExtendWith(TailCondition.class) @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface TailAvailable { + /** + * The options for the 'tail' command. + * @return the options. + * @author Jiandong Ma + * @since 6.5 + */ + String options() default ""; } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailRule.java b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailCondition.java similarity index 70% rename from spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailRule.java rename to spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailCondition.java index 7d486d1c8ee..6716234f9ea 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailRule.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/tail/TailCondition.java @@ -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. @@ -20,6 +20,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.reflect.AnnotatedElement; +import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -30,12 +32,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.core.annotation.MergedAnnotations; /** * Ignores tests annotated with {@link TailAvailable} if 'tail' with the requested options @@ -43,36 +44,40 @@ * * @author Gary Russell * @author Artem Bilan + * @author Jiandong Ma * - * @since 3.0 + * @since 6.5 * */ -public class TailRule extends TestWatcher { +public class TailCondition implements ExecutionCondition { - private static final Log logger = LogFactory.getLog(TailRule.class); + private static final Log logger = LogFactory.getLog(TailCondition.class); private static final String tmpDir = System.getProperty("java.io.tmpdir"); - private final String commandToTest; + private String commandToTest; - public TailRule(String optionsToTest) { + private static final ConditionEvaluationResult ENABLED = ConditionEvaluationResult.enabled( + "@TailAvailable is not present"); + + public void setOptionsToTest(String optionsToTest) { this.commandToTest = "tail " + optionsToTest + " "; } @Override - public Statement apply(Statement base, Description description) { - if (description.getAnnotation(TailAvailable.class) != null) { + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + Optional element = context.getElement(); + MergedAnnotations annotations = MergedAnnotations.from(element.get(), + MergedAnnotations.SearchStrategy.TYPE_HIERARCHY); + if (annotations.get(TailAvailable.class).isPresent()) { + TailAvailable tail = annotations.get(TailAvailable.class).synthesize(); + setOptionsToTest(tail.options()); if (!tailWorksOnThisMachine()) { - return new Statement() { - - @Override - public void evaluate() { - // skip - } - }; + return ConditionEvaluationResult.disabled( + "Tests Ignored: 'Tail' command does not work on this platform"); } } - return super.apply(base, description); + return ENABLED; } private boolean tailWorksOnThisMachine() { @@ -127,15 +132,4 @@ private boolean tailWorksOnThisMachine() { } return result == 0; } - - public static class TestRule { - - @Test - public void test1() { - TailRule rule = new TailRule("-BLAH"); - assertThat(rule.tailWorksOnThisMachine()).isFalse(); - } - - } - } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformerTests.java index cc7c719cc38..449bb194955 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformerTests.java @@ -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. @@ -19,9 +19,9 @@ import java.io.File; import java.io.FileOutputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.integration.file.FileHeaders; import org.springframework.integration.support.MessageBuilder; @@ -46,7 +46,7 @@ public abstract class AbstractFilePayloadTransformerTests { - @Before + @BeforeEach public void setUp() { transformer = new FileToByteArrayTransformer(); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/FileToStringTransformerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/FileToStringTransformerTests.java index ce0d5a573ac..ff3d9278ebf 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/FileToStringTransformerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/transformer/FileToStringTransformerTests.java @@ -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. @@ -16,8 +16,8 @@ package org.springframework.integration.file.transformer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.messaging.Message; @@ -30,7 +30,7 @@ public class FileToStringTransformerTests extends AbstractFilePayloadTransformerTests { - @Before + @BeforeEach public void setUp() { transformer = new FileToStringTransformer(); transformer.setCharset(DEFAULT_ENCODING); diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/ScriptsFactoryTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/ScriptsFactoryTests.java index cd20475a9b5..3757f824a7f 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/ScriptsFactoryTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/ScriptsFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 the original author or authors. + * Copyright 2016-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. @@ -16,8 +16,7 @@ package org.springframework.integration.groovy; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -36,7 +35,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -44,7 +43,7 @@ * @author Artem Bilan * @since 5.0 */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class ScriptsFactoryTests { diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java index 1f62b0c2e1a..5c427e6738f 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSourceTests.java @@ -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. @@ -16,7 +16,7 @@ package org.springframework.integration.groovy.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ByteArrayResource; import org.springframework.integration.scripting.RefreshableResourceScriptSource; diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/ServiceActivatorParserTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/ServiceActivatorParserTests.java index 9d1b48e7e25..30b2c5b6324 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/ServiceActivatorParserTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/ServiceActivatorParserTests.java @@ -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. @@ -16,7 +16,7 @@ package org.springframework.integration.groovy.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java index 673e98e5e0f..04d8b3dd615 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/ChainElementsTests.java @@ -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. @@ -19,7 +19,7 @@ import java.io.ByteArrayInputStream; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayWithMethodExpressionTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayWithMethodExpressionTests.java index 3154ae0f54f..2144a74b910 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayWithMethodExpressionTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayWithMethodExpressionTests.java @@ -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. @@ -16,9 +16,8 @@ package org.springframework.integration.http.config; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; @@ -30,12 +29,12 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -44,8 +43,7 @@ * @author Oleg Zhurakousky * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig @DirtiesContext public class HttpOutboundGatewayWithMethodExpressionTests { @@ -63,7 +61,7 @@ public class HttpOutboundGatewayWithMethodExpressionTests { private MockRestServiceServer mockServer; - @Before + @BeforeEach public void setup() { this.mockServer = MockRestServiceServer.createServer(this.restTemplate); } @@ -96,11 +94,11 @@ public void testExplicitlySetMethod() { this.mockServer.verify(); } - @Test(expected = BeanDefinitionParsingException.class) + @Test public void testMutuallyExclusivityInMethodAndMethodExpression() { - new ClassPathXmlApplicationContext( - "http-outbound-gateway-with-httpmethod-expression-fail.xml", getClass()) - .close(); + assertThatExceptionOfType(BeanDefinitionParsingException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext( + "http-outbound-gateway-with-httpmethod-expression-fail.xml", getClass())); } } diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/UriVariableExpressionTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/UriVariableExpressionTests.java index 4a74715cf5b..cd535625c58 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/UriVariableExpressionTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/UriVariableExpressionTests.java @@ -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. @@ -22,7 +22,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/support/DefaultHttpHeaderMapperFromMessageOutboundTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/support/DefaultHttpHeaderMapperFromMessageOutboundTests.java index b01b8cf7122..c5667f02513 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/support/DefaultHttpHeaderMapperFromMessageOutboundTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/support/DefaultHttpHeaderMapperFromMessageOutboundTests.java @@ -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. @@ -29,8 +29,8 @@ import java.util.Map; import java.util.TimeZone; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -42,6 +42,8 @@ import org.springframework.util.StopWatch; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; /** * @author Oleg Zhurakousky @@ -55,14 +57,16 @@ public class DefaultHttpHeaderMapperFromMessageOutboundTests { // ACCEPT tests - @Test(expected = IllegalArgumentException.class) + @Test public void validateAcceptHeaderWithNoSlash() { HeaderMapper mapper = DefaultHttpHeaderMapper.outboundMapper(); Map messageHeaders = new HashMap<>(); messageHeaders.put("Accept", "bar"); HttpHeaders headers = new HttpHeaders(); - mapper.fromHeaders(new MessageHeaders(messageHeaders), headers); + MessageHeaders messageHeadersObj = new MessageHeaders(messageHeaders); + assertThatIllegalArgumentException() + .isThrownBy(() -> mapper.fromHeaders(messageHeadersObj, headers)); } @Test @@ -158,13 +162,15 @@ public void validateAcceptHeaderMultipleAsMediaTypeCollection() { // ACCEPT_CHARSET tests - @Test(expected = UnsupportedCharsetException.class) + @Test public void validateAcceptCharsetHeaderWithWrongCharset() { HeaderMapper mapper = DefaultHttpHeaderMapper.outboundMapper(); Map messageHeaders = new HashMap<>(); messageHeaders.put("Accept-Charset", "foo"); HttpHeaders headers = new HttpHeaders(); - mapper.fromHeaders(new MessageHeaders(messageHeaders), headers); + MessageHeaders messageHeadersObj = new MessageHeaders(messageHeaders); + assertThatExceptionOfType(UnsupportedCharsetException.class) + .isThrownBy(() -> mapper.fromHeaders(messageHeadersObj, headers)); } @Test @@ -298,26 +304,30 @@ public void validateContentLengthAsNumber() { assertThat(headers.getContentLength()).isEqualTo(1); } - @Test(expected = NumberFormatException.class) + @Test public void validateContentLengthAsNonNumericString() { HeaderMapper mapper = DefaultHttpHeaderMapper.outboundMapper(); Map messageHeaders = new HashMap<>(); messageHeaders.put("Content-Length", "foo"); HttpHeaders headers = new HttpHeaders(); - mapper.fromHeaders(new MessageHeaders(messageHeaders), headers); + MessageHeaders messageHeadersObj = new MessageHeaders(messageHeaders); + assertThatExceptionOfType(NumberFormatException.class) + .isThrownBy(() -> mapper.fromHeaders(messageHeadersObj, headers)); } // Content-Type test - @Test(expected = IllegalArgumentException.class) + @Test public void validateContentTypeWrongValue() { HeaderMapper mapper = DefaultHttpHeaderMapper.outboundMapper(); Map messageHeaders = new HashMap<>(); messageHeaders.put(MessageHeaders.CONTENT_TYPE, "foo"); HttpHeaders headers = new HttpHeaders(); - mapper.fromHeaders(new MessageHeaders(messageHeaders), headers); + MessageHeaders messageHeadersObj = new MessageHeaders(messageHeaders); + assertThatIllegalArgumentException() + .isThrownBy(() -> mapper.fromHeaders(messageHeadersObj, headers)); } @Test @@ -542,7 +552,7 @@ public void validateTransferEncodingToHeaders() { } @Test - @Ignore + @Disabled public void perf() { HeaderMapper mapper = DefaultHttpHeaderMapper.outboundMapper(); diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java index 9b746fdbbe0..76f80c204bb 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java @@ -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. @@ -16,9 +16,9 @@ package org.springframework.integration.jdbc; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.jdbc.core.JdbcOperations; @@ -42,12 +42,12 @@ public class JdbcOutboundGatewayTests { private static EmbeddedDatabase dataSource; - @BeforeClass + @BeforeAll public static void setup() { dataSource = new EmbeddedDatabaseBuilder().build(); } - @AfterClass + @AfterAll public static void teardown() { dataSource.shutdown(); } diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java index 8112496151b..d8ea1f44df3 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapterIntegrationTests.java @@ -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. @@ -22,10 +22,10 @@ import java.util.List; import java.util.Map; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.jdbc.core.JdbcTemplate; @@ -50,7 +50,7 @@ public class JdbcPollingChannelAdapterIntegrationTests { private static JdbcTemplate jdbcTemplate; - @BeforeClass + @BeforeAll public static void setUp() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); builder.setType(EmbeddedDatabaseType.DERBY) @@ -59,12 +59,12 @@ public static void setUp() { jdbcTemplate = new JdbcTemplate(embeddedDatabase); } - @AfterClass + @AfterAll public static void tearDown() { embeddedDatabase.shutdown(); } - @After + @AfterEach public void cleanup() { jdbcTemplate.execute("DELETE FROM item"); jdbcTemplate.execute("DELETE FROM copy"); diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/MessageGroupQueueTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/MessageGroupQueueTests.java index 6915510ebfc..cb6c2988af4 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/MessageGroupQueueTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/MessageGroupQueueTests.java @@ -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. @@ -20,15 +20,14 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.LogFactory; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.MessageGroupQueue; import org.springframework.integration.store.MessageGroupStore; import org.springframework.integration.store.SimpleMessageStore; -import org.springframework.integration.test.support.LongRunningIntegrationTest; +import org.springframework.integration.test.condition.LongRunningTest; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; @@ -38,11 +37,9 @@ * @author Oleg Zhurakousky * @author Artem Bilan */ +@LongRunningTest public class MessageGroupQueueTests { - @ClassRule - public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); - @Test public void validateMgqInterruption() throws Exception { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcExecutorTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcExecutorTests.java index 627c2071594..b27cb1094b0 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcExecutorTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcExecutorTests.java @@ -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. @@ -23,7 +23,7 @@ import javax.sql.DataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests.java index 77c7a21ac8d..8d524404950 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests.java @@ -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. @@ -18,8 +18,7 @@ import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.jdbc.storedproc.User; @@ -28,7 +27,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +36,7 @@ * * @since 2.2 */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext // close at the end after class public class StoredProcOutboundChannelAdapterWithinChainTests { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespace2IntegrationTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespace2IntegrationTests.java index 54db506403b..836d3605605 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespace2IntegrationTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespace2IntegrationTests.java @@ -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. @@ -23,16 +23,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.Message; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -40,8 +38,7 @@ * @author Gunnar Hillert * @author Gary Russell */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext // close at the end after class public class StoredProcPollingChannelAdapterWithNamespace2IntegrationTests { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests.java index d6616f79ceb..832b066e237 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/InnerPollerParserTests.java @@ -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. @@ -16,7 +16,7 @@ package org.springframework.integration.jdbc.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcTypesEnumTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcTypesEnumTests.java index 19962cde7a1..a85561f6e9f 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcTypesEnumTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcTypesEnumTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 the original author or authors. + * Copyright 2016-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. @@ -18,7 +18,7 @@ import java.sql.Types; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcInvalidConfigsTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcInvalidConfigsTests.java index 518ede3d2e8..7aa2fcb08bb 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcInvalidConfigsTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcInvalidConfigsTests.java @@ -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. @@ -19,7 +19,7 @@ import java.io.ByteArrayInputStream; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcOutboundGatewayParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcOutboundGatewayParserTests.java index 85a9d108b19..0fc50e5f7df 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcOutboundGatewayParserTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcOutboundGatewayParserTests.java @@ -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. @@ -21,8 +21,8 @@ import java.util.Map; import java.util.Map.Entry; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.ConfigurableApplicationContext; @@ -282,7 +282,7 @@ public void advised() throws Exception { assertThat(adviceCalled).isEqualTo(1); } - @After + @AfterEach public void tearDown() { if (context != null) { context.close(); diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java index 3e4ee22c5cb..de35758cbfd 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java @@ -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. @@ -22,8 +22,8 @@ import java.util.Map; import java.util.Map.Entry; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.ConfigurableApplicationContext; @@ -271,7 +271,7 @@ public void testAutoChannel() throws Exception { autoChannelAdapter.stop(); } - @After + @AfterEach public void tearDown() { this.pollingAdapter.stop(); ThreadPoolTaskScheduler taskScheduler = context.getBean(ThreadPoolTaskScheduler.class); diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/mysql/MySqlJdbcMessageStoreMultipleChannelTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/mysql/MySqlJdbcMessageStoreMultipleChannelTests.java index cf5eb58d2d0..591de33fde7 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/mysql/MySqlJdbcMessageStoreMultipleChannelTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/mysql/MySqlJdbcMessageStoreMultipleChannelTests.java @@ -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. @@ -26,11 +26,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -42,8 +41,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionTemplate; @@ -55,10 +53,9 @@ * @author Gunnar Hillert * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) -@Ignore +@Disabled public class MySqlJdbcMessageStoreMultipleChannelTests { private static final Log LOG = LogFactory.getLog(MySqlJdbcMessageStoreMultipleChannelTests.class); @@ -85,12 +82,12 @@ public class MySqlJdbcMessageStoreMultipleChannelTests { @Autowired private DataSource dataSource; - @Before + @BeforeEach public void beforeTest() { this.jdbcTemplate = new JdbcTemplate(dataSource); } - @After + @AfterEach public void afterTest() { new TransactionTemplate(this.transactionManager).execute(status -> { this.jdbcTemplate.update("delete from INT_GROUP_TO_MESSAGE"); diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelOnePollerIntegrationTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelOnePollerIntegrationTests.java index a9ff82b7138..0ceeca69b27 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelOnePollerIntegrationTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelOnePollerIntegrationTests.java @@ -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. @@ -21,10 +21,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -33,8 +32,7 @@ import org.springframework.integration.store.MessageGroup; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionTemplate; import org.springframework.util.StopWatch; @@ -47,8 +45,7 @@ * @author Gary Russell * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext // close at the end after class public class JdbcMessageStoreChannelOnePollerIntegrationTests { @@ -72,14 +69,14 @@ public class JdbcMessageStoreChannelOnePollerIntegrationTests { @Qualifier("service-relay") private AbstractEndpoint serviceRelay; - @Before + @BeforeEach public void clear() { for (MessageGroup group : this.messageStore) { this.messageStore.removeMessageGroup(group.getGroupId()); } } - @After + @AfterEach public void tearDown() { this.serviceRelay.stop(); } diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelTests.java index 6ec14b09962..569915db910 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreChannelTests.java @@ -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. @@ -21,10 +21,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -34,8 +33,7 @@ import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +48,7 @@ * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class JdbcMessageStoreChannelTests { @@ -68,13 +65,13 @@ public class JdbcMessageStoreChannelTests { @Qualifier("service-activator") private AbstractEndpoint serviceActivator; - @Before + @BeforeEach public void init() { Service.reset(1); this.serviceActivator.start(); } - @After + @AfterEach public void tearDown() { this.serviceActivator.stop(); } diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreRegionTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreRegionTests.java index 634d0b41c82..5ea1a6daf22 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreRegionTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/JdbcMessageStoreRegionTests.java @@ -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. @@ -18,11 +18,11 @@ import java.util.List; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.integration.support.MessageBuilder; import org.springframework.jdbc.core.JdbcTemplate; @@ -47,7 +47,7 @@ public class JdbcMessageStoreRegionTests { private JdbcMessageStore messageStore2; - @BeforeClass + @BeforeAll public static void setupDatabase() { dataSource = new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseType.H2) @@ -56,12 +56,12 @@ public static void setupDatabase() { .build(); } - @AfterClass + @AfterAll public static void shutDownDatabase() { dataSource.shutdown(); } - @Before + @BeforeEach public void beforeTest() { this.jdbcTemplate = new JdbcTemplate(dataSource); this.messageStore1 = new JdbcMessageStore(dataSource); @@ -71,7 +71,7 @@ public void beforeTest() { this.messageStore2.setRegion("region2"); } - @After + @AfterEach public void afterTest() { this.jdbcTemplate.execute("delete from INT_GROUP_TO_MESSAGE"); this.jdbcTemplate.execute("delete from INT_MESSAGE"); diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/AbstractTxTimeoutMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/AbstractTxTimeoutMessageStoreTests.java index 5853eb15743..bf02c07386e 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/AbstractTxTimeoutMessageStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/AbstractTxTimeoutMessageStoreTests.java @@ -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. @@ -31,8 +31,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -46,7 +45,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; @@ -60,7 +59,7 @@ * @author Gunnar Hillert * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext // close at the end after class public abstract class AbstractTxTimeoutMessageStoreTests { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DerbyTxTimeoutMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DerbyTxTimeoutMessageStoreTests.java index 4813bdeda15..1a5075c8902 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DerbyTxTimeoutMessageStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/DerbyTxTimeoutMessageStoreTests.java @@ -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. @@ -16,7 +16,7 @@ package org.springframework.integration.jdbc.store.channel; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; import org.springframework.test.context.ContextConfiguration; @@ -26,7 +26,7 @@ * @author Artem Bilan * */ -@Ignore +@Disabled @ContextConfiguration public class DerbyTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests.java index ac8f5ae1435..54d3877ac4d 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/H2TxTimeoutMessageStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-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. @@ -16,9 +16,8 @@ package org.springframework.integration.jdbc.store.channel; -import org.junit.Rule; - -import org.springframework.integration.test.support.LongRunningIntegrationTest; +import org.springframework.integration.test.condition.LongRunningTest; +import org.springframework.test.context.ContextConfiguration; /** * @@ -27,9 +26,8 @@ * @author Manuel Jordan * @since 4.3 */ +@LongRunningTest +@ContextConfiguration public class H2TxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests { - @Rule - public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); - } diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/MySqlTxTimeoutMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/MySqlTxTimeoutMessageStoreTests.java index 2b981ec2ee6..69d1f963f54 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/MySqlTxTimeoutMessageStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/MySqlTxTimeoutMessageStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 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. @@ -16,7 +16,7 @@ package org.springframework.integration.jdbc.store.channel; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; import org.springframework.test.context.ContextConfiguration; @@ -26,7 +26,7 @@ * @author Artem Bilan * */ -@Ignore +@Disabled @ContextConfiguration public class MySqlTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/OracleTxTimeoutMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/OracleTxTimeoutMessageStoreTests.java index 071371494af..4769e977dc2 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/OracleTxTimeoutMessageStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/OracleTxTimeoutMessageStoreTests.java @@ -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. @@ -16,7 +16,7 @@ package org.springframework.integration.jdbc.store.channel; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; import org.springframework.test.context.ContextConfiguration; @@ -26,7 +26,7 @@ * @author Artem Bilan * */ -@Ignore +@Disabled @ContextConfiguration public class OracleTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/PostgresTxTimeoutMessageStoreTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/PostgresTxTimeoutMessageStoreTests.java index 83871310b19..64930158980 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/PostgresTxTimeoutMessageStoreTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/PostgresTxTimeoutMessageStoreTests.java @@ -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. @@ -16,7 +16,7 @@ package org.springframework.integration.jdbc.store.channel; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; import org.springframework.test.context.ContextConfiguration; @@ -26,7 +26,7 @@ * @author Artem Bilan * */ -@Ignore +@Disabled @ContextConfiguration public class PostgresTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/storedproc/ProcedureParameterTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/storedproc/ProcedureParameterTests.java index f4e9a4a0ec4..3026596ef07 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/storedproc/ProcedureParameterTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/storedproc/ProcedureParameterTests.java @@ -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. @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java index 570cf4f618f..4a9aaac73fe 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java @@ -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. @@ -17,8 +17,7 @@ package org.springframework.integration.jms.config; import jakarta.jms.Destination; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.jms.DefaultJmsHeaderMapper; @@ -29,8 +28,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -40,8 +38,7 @@ * @author Gary Russell * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class JmsHeaderEnricherTests { diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java index c21973077ef..2c304ed2e35 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java @@ -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. @@ -18,7 +18,7 @@ import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -32,6 +32,7 @@ import org.springframework.messaging.PollableChannel; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Mark Fisher @@ -102,21 +103,18 @@ public void adapterWithConnectionFactoryAndDestinationName() { } } - @Test(expected = BeanDefinitionStoreException.class) + @Test public void adapterWithConnectionFactoryOnly() { - new ClassPathXmlApplicationContext("jmsInboundWithConnectionFactoryOnly.xml", this.getClass()).close(); + assertThatExceptionOfType(BeanDefinitionStoreException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("jmsInboundWithConnectionFactoryOnly.xml", this.getClass())); } - @Test(expected = BeanCreationException.class) + @Test public void adapterWithDestinationOnly() { - try { - new ClassPathXmlApplicationContext("jmsInboundWithDestinationOnly.xml", this.getClass()).close(); - } - catch (BeanCreationException e) { - Throwable rootCause = e.getRootCause(); - assertThat(rootCause.getClass()).isEqualTo(NoSuchBeanDefinitionException.class); - throw e; - } + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("jmsInboundWithDestinationOnly.xml", this.getClass())) + .extracting(e -> e.getRootCause().getClass()) + .isEqualTo(NoSuchBeanDefinitionException.class); } @Test @@ -131,9 +129,10 @@ public void testAdapterWithDestinationAndDefaultConnectionFactory() { } } - @Test(expected = BeanCreationException.class) + @Test public void adapterWithDestinationNameOnly() { - new ClassPathXmlApplicationContext("jmsInboundWithDestinationNameOnly.xml", this.getClass()).close(); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("jmsInboundWithDestinationNameOnly.xml", this.getClass())); } @Test diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageDrivenChannelAdapterParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageDrivenChannelAdapterParserTests.java index b26eb2f2fda..566416afc32 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageDrivenChannelAdapterParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageDrivenChannelAdapterParserTests.java @@ -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. @@ -18,7 +18,7 @@ import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.NotReadablePropertyException; diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java index bc661eb5675..221628416ba 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java @@ -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. @@ -17,7 +17,7 @@ package org.springframework.integration.jms.config; import jakarta.jms.DeliveryMode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -33,6 +33,7 @@ import org.springframework.messaging.support.GenericMessage; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Mark Fisher @@ -162,15 +163,11 @@ public void adapterWithMessageConverter() { context.close(); } - @Test(expected = BeanDefinitionStoreException.class) + @Test public void adapterWithEmptyConnectionFactory() { - try { - new ClassPathXmlApplicationContext("jmsOutboundWithEmptyConnectionFactory.xml", this.getClass()).close(); - } - catch (BeanDefinitionStoreException e) { - assertThat(e.getMessage().contains("connection-factory")).isTrue(); - throw e; - } + assertThatExceptionOfType(BeanDefinitionStoreException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("jmsOutboundWithEmptyConnectionFactory.xml", this.getClass())) + .withMessageContaining("connection-factory"); } @Test