diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java index a6f0bb16c7..5c908585e9 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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 @@ package org.springframework.integration.config; import java.util.List; -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; @@ -31,8 +30,8 @@ import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -42,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gunnar Hillert * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class AggregatorWithCorrelationStrategyTests { @Autowired diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java index 40f30db02a..a62b6bed5c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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 @@ package org.springframework.integration.config; import java.util.concurrent.TimeUnit; -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; @@ -33,7 +32,7 @@ import org.springframework.messaging.Message; 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; @@ -41,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer * @author Artem Bilan */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class ChannelWithMessageStoreParserTests { @@ -71,7 +70,6 @@ public class ChannelWithMessageStoreParserTests { private MessageGroupStore priorityMessageStore; @Test - @DirtiesContext public void testActivatorSendsToPersistentQueue() throws Exception { input.send(createMessage("123", "id1", 3, 1, null)); @@ -87,7 +85,6 @@ public class ChannelWithMessageStoreParserTests { } @Test - @DirtiesContext public void testPriorityMessageStore() { assertThat(TestUtils.getPropertyValue(this.priorityChannel, "queue.messageGroupStore")) .isSameAs(this.priorityMessageStore); @@ -96,6 +93,7 @@ public class ChannelWithMessageStoreParserTests { private static Message createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber, MessageChannel outputChannel) { + return MessageBuilder.withPayload(payload).setCorrelationId(correlationId).setSequenceSize(sequenceSize) .setSequenceNumber(sequenceNumber).setReplyChannel(outputChannel).build(); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/CorrelationStrategyInvalidConfigurationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/CorrelationStrategyInvalidConfigurationTests.java index 79e021af5f..542a6fc2b5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/CorrelationStrategyInvalidConfigurationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/CorrelationStrategyInvalidConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; public class CorrelationStrategyInvalidConfigurationTests { @Test - public void testCorrelationStrategyWithVoidReturningMethods() throws Exception { + public void testCorrelationStrategyWithVoidReturningMethods() { assertThatExceptionOfType(BeanCreationException.class) .isThrownBy(() -> new ClassPathXmlApplicationContext("correlationStrategyWithVoidMethods.xml", getClass())) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java index 00d02feb6d..79ee96e6ec 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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 @@ package org.springframework.integration.config; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.messaging.MessageChannel; @@ -35,16 +35,15 @@ public class EndpointParserTests { @Test public void testSimpleEndpoint() throws InterruptedException { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "simpleEndpointTests.xml", this.getClass()); - context.start(); - MessageChannel channel = (MessageChannel) context.getBean("endpointParserTestInput"); - TestHandler handler = (TestHandler) context.getBean("testHandler"); - assertThat(handler.getMessageString()).isNull(); - channel.send(new GenericMessage<>("test")); - assertThat(handler.getLatch().await(10000, TimeUnit.MILLISECONDS)).isTrue(); - assertThat(handler.getMessageString()).isEqualTo("test"); - context.close(); + try (var context = new ClassPathXmlApplicationContext("simpleEndpointTests.xml", getClass())) { + context.start(); + MessageChannel channel = (MessageChannel) context.getBean("endpointParserTestInput"); + TestHandler handler = (TestHandler) context.getBean("testHandler"); + assertThat(handler.getMessageString()).isNull(); + channel.send(new GenericMessage<>("test")); + assertThat(handler.getLatch().await(10000, TimeUnit.MILLISECONDS)).isTrue(); + assertThat(handler.getMessageString()).isEqualTo("test"); + } } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java index c93a19b23a..f932117933 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java @@ -16,8 +16,7 @@ package org.springframework.integration.config; -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; @@ -30,19 +29,20 @@ 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.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Mark Fisher * @author Gary Russell * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig +@DirtiesContext public class FilterParserTests { @Autowired @@ -136,9 +136,10 @@ public class FilterParserTests { assertThat(reply).isNotNull(); } - @Test(expected = MessageRejectedException.class) + @Test public void exceptionThrowingFilterRejects() { - exceptionInput.send(new GenericMessage<>("")); + assertThatExceptionOfType(MessageRejectedException.class) + .isThrownBy(() -> exceptionInput.send(new GenericMessage<>(""))); } @Test @@ -150,20 +151,14 @@ public class FilterParserTests { assertThat(adapterOutput.receive(0)).isNull(); } - @Test(expected = MessageRejectedException.class) - public void filterWithDiscardChannelAndException() throws Exception { - Exception exception = null; - try { - discardAndExceptionInput.send(new GenericMessage<>("")); - } - catch (Exception e) { - exception = e; - } + @Test + public void filterWithDiscardChannelAndException() { + assertThatExceptionOfType(MessageRejectedException.class) + .isThrownBy(() -> discardAndExceptionInput.send(new GenericMessage<>(""))); Message discard = discardAndExceptionOutput.receive(0); assertThat(discard).isNotNull(); assertThat(discard.getPayload()).isEqualTo(""); assertThat(adapterOutput.receive(0)).isNull(); - throw exception; } public static class TestSelectorBean { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/GlobalChannelInterceptorProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/GlobalChannelInterceptorProcessorTests.java index 70e305b33d..f6d4f59753 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/GlobalChannelInterceptorProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/GlobalChannelInterceptorProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-2024 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,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper; @@ -30,6 +29,7 @@ import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.messaging.support.InterceptableChannel; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -44,7 +44,7 @@ public class GlobalChannelInterceptorProcessorTests { private ListableBeanFactory beanFactory; - @Before + @BeforeEach public void setup() { this.globalChannelInterceptorProcessor = new GlobalChannelInterceptorProcessor(); this.beanFactory = mock(ListableBeanFactory.class); @@ -58,7 +58,7 @@ public class GlobalChannelInterceptorProcessorTests { this.globalChannelInterceptorProcessor.afterSingletonsInstantiated(); verify(this.beanFactory) .getBeansOfType(GlobalChannelInterceptorWrapper.class); - verify(this.beanFactory, Mockito.never()) + verify(this.beanFactory, never()) .getBeansOfType(InterceptableChannel.class); } @@ -66,11 +66,11 @@ public class GlobalChannelInterceptorProcessorTests { public void testProcessorWithInterceptorDefaultPattern() { Map interceptors = new HashMap<>(); Map channels = new HashMap<>(); - ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class); + ChannelInterceptor channelInterceptor = mock(); GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor); - InterceptableChannel channel = Mockito.mock(InterceptableChannel.class); + InterceptableChannel channel = mock(); interceptors.put("Test-1", globalChannelInterceptorWrapper); channels.put("Test-1", channel); @@ -89,11 +89,11 @@ public class GlobalChannelInterceptorProcessorTests { public void testProcessorWithInterceptorMatchingPattern() { Map interceptors = new HashMap<>(); Map channels = new HashMap<>(); - ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class); + ChannelInterceptor channelInterceptor = mock(); GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor); - InterceptableChannel channel = Mockito.mock(InterceptableChannel.class); + InterceptableChannel channel = mock(); globalChannelInterceptorWrapper.setPatterns(new String[] {"Te*"}); interceptors.put("Test-1", globalChannelInterceptorWrapper); @@ -112,11 +112,11 @@ public class GlobalChannelInterceptorProcessorTests { public void testProcessorWithInterceptorNotMatchingPattern() { Map interceptors = new HashMap<>(); Map channels = new HashMap<>(); - ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class); + ChannelInterceptor channelInterceptor = mock(); GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor); - InterceptableChannel channel = Mockito.mock(InterceptableChannel.class); + InterceptableChannel channel = mock(); globalChannelInterceptorWrapper.setPatterns(new String[] {"te*"}); interceptors.put("Test-1", globalChannelInterceptorWrapper); @@ -128,7 +128,7 @@ public class GlobalChannelInterceptorProcessorTests { this.globalChannelInterceptorProcessor.afterSingletonsInstantiated(); - verify(channel, Mockito.never()) + verify(channel, never()) .addInterceptor(channelInterceptor); } @@ -136,11 +136,11 @@ public class GlobalChannelInterceptorProcessorTests { public void testProcessorWithInterceptorMatchingNegativePattern() { Map interceptors = new HashMap<>(); Map channels = new HashMap<>(); - ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class); + ChannelInterceptor channelInterceptor = mock(); GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor); - InterceptableChannel channel = Mockito.mock(InterceptableChannel.class); + InterceptableChannel channel = mock(); globalChannelInterceptorWrapper.setPatterns(new String[] {"!te*", "!Te*"}); interceptors.put("Test-1", globalChannelInterceptorWrapper); @@ -151,7 +151,7 @@ public class GlobalChannelInterceptorProcessorTests { .thenReturn(channels); this.globalChannelInterceptorProcessor.afterSingletonsInstantiated(); - verify(channel, Mockito.never()) + verify(channel, never()) .addInterceptor(channelInterceptor); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java index 8206f696e9..b9c3b6eb62 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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 @@ package org.springframework.integration.config; import java.util.concurrent.Executor; -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; @@ -29,7 +28,8 @@ import org.springframework.integration.dispatcher.BroadcastingDispatcher; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.integration.util.ErrorHandlingTaskExecutor; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.ErrorHandler; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @author Artem Bilan */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig +@DirtiesContext public class PublishSubscribeChannelParserTests { @Autowired diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerParserTests.java index 429e141b85..60bb88d248 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -33,6 +33,7 @@ import org.springframework.integration.store.SimpleMessageGroup; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -48,6 +49,7 @@ import static org.springframework.integration.test.util.TestUtils.getPropertyVal * @author Gary Russell */ @SpringJUnitConfig +@DirtiesContext public class ResequencerParserTests { @Autowired diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerWithMessageStoreParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerWithMessageStoreParserTests.java index 9702ad7102..3ed75396e8 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerWithMessageStoreParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ResequencerWithMessageStoreParserTests.java @@ -16,8 +16,7 @@ package org.springframework.integration.config; -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; @@ -27,8 +26,8 @@ import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -36,8 +35,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class ResequencerWithMessageStoreParserTests { @Autowired @@ -75,6 +74,7 @@ public class ResequencerWithMessageStoreParserTests { private static Message createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber, MessageChannel outputChannel) { + return MessageBuilder.withPayload(payload) .setCorrelationId(correlationId) .setSequenceSize(sequenceSize) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java index 937f36a195..1c4016b03c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/RouterFactoryBeanDelegationTests.java @@ -16,18 +16,17 @@ package org.springframework.integration.config; -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; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.router.AbstractMappingMessageRouter; +import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -35,8 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Mark Fisher * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig +@DirtiesContext public class RouterFactoryBeanDelegationTests { @Autowired @@ -57,8 +56,7 @@ public class RouterFactoryBeanDelegationTests { @Test public void checkResolutionRequiredConfiguredOnTargetRouter() { - @SuppressWarnings("unchecked") - boolean resolutionRequired = (Boolean) new DirectFieldAccessor(router).getPropertyValue("resolutionRequired"); + boolean resolutionRequired = TestUtils.getPropertyValue(router, "resolutionRequired", Boolean.class); assertThat(resolutionRequired).as("The 'resolutionRequired' property should be 'true'").isTrue(); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java index a479cc2241..9bf2f1f60e 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/SelectorChainParserTests.java @@ -18,19 +18,18 @@ package org.springframework.integration.config; import java.util.List; -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; import org.springframework.context.ApplicationContext; import org.springframework.integration.core.MessageSelector; import org.springframework.integration.selector.MessageSelectorChain; import org.springframework.integration.selector.MessageSelectorChain.VotingStrategy; +import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -39,8 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Iwein Fuld * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class SelectorChainParserTests { @Autowired @@ -96,12 +95,11 @@ public class SelectorChainParserTests { @SuppressWarnings("unchecked") private List getSelectors(MessageSelectorChain chain) { - DirectFieldAccessor accessor = new DirectFieldAccessor(chain); - return (List) accessor.getPropertyValue("selectors"); + return (List) TestUtils.getPropertyValue(chain, "selectors", List.class); } private VotingStrategy getStrategy(MessageSelectorChain chain) { - return (VotingStrategy) new DirectFieldAccessor(chain).getPropertyValue("votingStrategy"); + return TestUtils.getPropertyValue(chain, "votingStrategy", VotingStrategy.class); } public static class StubPojoSelector { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/TopLevelSelectorParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/TopLevelSelectorParserTests.java index 82a92c0039..3e4a030634 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/TopLevelSelectorParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/TopLevelSelectorParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,23 +16,23 @@ package org.springframework.integration.config; -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.ApplicationContext; import org.springframework.integration.core.MessageSelector; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Mark Fisher + * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class TopLevelSelectorParserTests { @Autowired @@ -40,8 +40,8 @@ public class TopLevelSelectorParserTests { @Test public void topLevelSelector() { - MessageSelector selector = (MessageSelector) context.getBean("selector"); - assertThat(selector.accept(new GenericMessage("test"))).isTrue(); + MessageSelector selector = context.getBean("selector", MessageSelector.class); + assertThat(selector.accept(new GenericMessage<>("test"))).isTrue(); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/WireTapParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/WireTapParserTests.java index 86c85b28d3..99e17cfbc1 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/WireTapParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/WireTapParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,8 @@ package org.springframework.integration.config; import java.util.List; -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; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.channel.interceptor.WireTap; @@ -31,17 +29,18 @@ 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.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class WireTapParserTests { @Autowired @@ -68,7 +67,7 @@ public class WireTapParserTests { @Test public void simpleWireTap() { assertThat(wireTapChannel.receive(0)).isNull(); - Message original = new GenericMessage("test"); + Message original = new GenericMessage<>("test"); noSelectors.send(original); Message intercepted = wireTapChannel.receive(0); assertThat(intercepted).isNotNull(); @@ -78,7 +77,7 @@ public class WireTapParserTests { @Test public void simpleWireTapWithIdAndSelectorExpression() { assertThat(TestUtils.getPropertyValue(wireTap, "selector")).isInstanceOf(ExpressionEvaluatingSelector.class); - Message original = new GenericMessage("test"); + Message original = new GenericMessage<>("test"); withId.send(original); Message intercepted = wireTapChannel.receive(0); assertThat(intercepted).isNotNull(); @@ -88,7 +87,7 @@ public class WireTapParserTests { @Test public void wireTapWithAcceptingSelector() { assertThat(wireTapChannel.receive(0)).isNull(); - Message original = new GenericMessage("test"); + Message original = new GenericMessage<>("test"); accepting.send(original); Message intercepted = wireTapChannel.receive(0); assertThat(intercepted).isNotNull(); @@ -98,7 +97,7 @@ public class WireTapParserTests { @Test public void wireTapWithRejectingSelector() { assertThat(wireTapChannel.receive(0)).isNull(); - Message original = new GenericMessage("test"); + Message original = new GenericMessage<>("test"); rejecting.send(original); Message intercepted = wireTapChannel.receive(0); assertThat(intercepted).isNull(); @@ -110,7 +109,7 @@ public class WireTapParserTests { int expectedTimeoutCount = 0; int otherTimeoutCount = 0; for (WireTap wireTap : wireTaps) { - long timeout = ((Long) new DirectFieldAccessor(wireTap).getPropertyValue("timeout")).longValue(); + long timeout = TestUtils.getPropertyValue(wireTap, "timeout", Long.class); if (timeout == 0) { defaultTimeoutCount++; } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/BridgeFromIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/BridgeFromIntegrationTests.java index 0981a39356..3e915f9b72 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/BridgeFromIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/BridgeFromIntegrationTests.java @@ -16,8 +16,7 @@ package org.springframework.integration.config.annotation; -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.annotation.Bean; @@ -32,8 +31,8 @@ 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.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -42,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; * * @since 5.0.8 */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = BridgeFromIntegrationTests.RootTestConfiguration.class) +@SpringJUnitConfig(classes = BridgeFromIntegrationTests.RootTestConfiguration.class) +@DirtiesContext public class BridgeFromIntegrationTests { @Autowired diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/CustomMessagingAnnotationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/CustomMessagingAnnotationTests.java index bc1d109c98..c394f7875d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/CustomMessagingAnnotationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/CustomMessagingAnnotationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 the original author or authors. + * Copyright 2017-2024 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. @@ -50,6 +50,7 @@ import org.springframework.integration.util.MessagingAnnotationUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -63,6 +64,7 @@ import static org.mockito.Mockito.verify; * @since 4.3.8 */ @SpringJUnitConfig +@DirtiesContext public class CustomMessagingAnnotationTests { @Autowired(required = false) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java index ff166b0674..5ac483f7dd 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessorAopIntegrationTests.java @@ -20,8 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; -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; @@ -31,8 +30,8 @@ import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.SubscribableChannel; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -41,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Mark Fisher * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class MessagingAnnotationPostProcessorAopIntegrationTests { @Qualifier("input")