Skip to content

Commit 8f4c2be

Browse files
committed
More @DirtiesContext for tests in core module
Additional code style cleanups in the affected classes **Auto-cherry-pick to `6.3.x` & `6.2.x`**
1 parent 09750f2 commit 8f4c2be

File tree

67 files changed

+417
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+417
-424
lines changed

Diff for: spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/AggregatorExpressionIntegrationTests.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,17 +19,16 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22-
import org.junit.Test;
23-
import org.junit.runner.RunWith;
22+
import org.junit.jupiter.api.Test;
2423

2524
import org.springframework.beans.factory.annotation.Autowired;
2625
import org.springframework.beans.factory.annotation.Qualifier;
2726
import org.springframework.integration.IntegrationMessageHeaderAccessor;
2827
import org.springframework.messaging.MessageChannel;
2928
import org.springframework.messaging.PollableChannel;
3029
import org.springframework.messaging.support.GenericMessage;
31-
import org.springframework.test.context.ContextConfiguration;
32-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30+
import org.springframework.test.annotation.DirtiesContext;
31+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
3534

@@ -39,8 +38,8 @@
3938
* @author Oleg Zhurakousky
4039
* @author Artem Bilan
4140
*/
42-
@RunWith(SpringJUnit4ClassRunner.class)
43-
@ContextConfiguration
41+
@SpringJUnitConfig
42+
@DirtiesContext
4443
public class AggregatorExpressionIntegrationTests {
4544

4645
@Autowired
@@ -51,7 +50,7 @@ public class AggregatorExpressionIntegrationTests {
5150
@Qualifier("output")
5251
private PollableChannel output;
5352

54-
@Test//(timeout=5000)
53+
@Test
5554
public void testVanillaAggregation() {
5655
for (int i = 0; i < 5; i++) {
5756
Map<String, Object> headers = stubHeaders(i, 5, 1);

Diff for: spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/AnnotationAggregatorTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
import org.springframework.integration.support.MessageBuilder;
3939
import org.springframework.messaging.Message;
4040
import org.springframework.messaging.PollableChannel;
41+
import org.springframework.test.annotation.DirtiesContext;
4142
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4243

4344
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,6 +48,7 @@
4748
* @author Artem Bilan
4849
*/
4950
@SpringJUnitConfig(classes = AnnotationAggregatorTests.TestConfiguration.class)
51+
@DirtiesContext
5052
public class AnnotationAggregatorTests {
5153

5254
@Autowired

Diff for: spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/MethodInvokingAggregatorReturningMessageTests.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,24 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121

22-
import org.junit.Test;
23-
import org.junit.runner.RunWith;
22+
import org.junit.jupiter.api.Test;
2423

2524
import org.springframework.beans.factory.annotation.Autowired;
2625
import org.springframework.integration.channel.DirectChannel;
2726
import org.springframework.integration.support.MessageBuilder;
2827
import org.springframework.messaging.Message;
2928
import org.springframework.messaging.PollableChannel;
30-
import org.springframework.test.context.ContextConfiguration;
31-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
29+
import org.springframework.test.annotation.DirtiesContext;
30+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
3433

3534
/**
3635
* @author Mark Fisher
3736
* @author Artem Bilan
3837
*/
39-
@ContextConfiguration
40-
@RunWith(SpringJUnit4ClassRunner.class)
38+
@SpringJUnitConfig
39+
@DirtiesContext
4140
public class MethodInvokingAggregatorReturningMessageTests {
4241

4342
@Autowired
@@ -52,7 +51,7 @@ public class MethodInvokingAggregatorReturningMessageTests {
5251
@Autowired
5352
PollableChannel defaultOutput;
5453

55-
@Test // INT-1107
54+
@Test
5655
public void messageReturningPojoAggregatorResultIsNotWrappedInAnotherMessage() {
5756
List<String> payload = Collections.singletonList("test");
5857
this.pojoInput.send(MessageBuilder.withPayload(payload).build());

Diff for: spring-integration-core/src/test/java/org/springframework/integration/aggregator/integration/ResequencerIntegrationTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.integration.aggregator.integration;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.beans.factory.annotation.Autowired;
2322
import org.springframework.context.ApplicationContext;
@@ -31,8 +30,7 @@
3130
import org.springframework.messaging.Message;
3231
import org.springframework.messaging.MessageChannel;
3332
import org.springframework.test.annotation.DirtiesContext;
34-
import org.springframework.test.context.ContextConfiguration;
35-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3634

3735
import static org.assertj.core.api.Assertions.assertThat;
3836

@@ -41,8 +39,7 @@
4139
* @author David Liu
4240
* @author Artem Bilan
4341
*/
44-
@RunWith(SpringJUnit4ClassRunner.class)
45-
@ContextConfiguration
42+
@SpringJUnitConfig
4643
@DirtiesContext
4744
public class ResequencerIntegrationTests {
4845

Diff for: spring-integration-core/src/test/java/org/springframework/integration/dispatcher/TransactionalPollerWithMixedAopConfigTests.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,37 @@
1616

1717
package org.springframework.integration.dispatcher;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.aop.framework.Advised;
22-
import org.springframework.context.support.ClassPathXmlApplicationContext;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.context.ApplicationContext;
24+
import org.springframework.test.annotation.DirtiesContext;
25+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2326

2427
import static org.assertj.core.api.Assertions.assertThat;
2528

2629
/**
30+
* This test was influenced by INT-1483 where via registering TX Advisor
31+
* in the BeanFactory while having <aop:config> resent resulted in
32+
* TX Advisor being applied on all beans in AC
33+
*
2734
* @author Oleg Zhurakousky
2835
* @author Gunnar Hillert
2936
* @author Gary Russell
30-
*
31-
* This test was influenced by INT-1483 where by registering TX Advisor
32-
* in the BeanFactory while having <aop:config> resent resulted in
33-
* TX Advisor being applied on all beans in AC
37+
* @author Artem Bilan
3438
*/
39+
@SpringJUnitConfig
40+
@DirtiesContext
3541
public class TransactionalPollerWithMixedAopConfigTests {
3642

43+
@Autowired
44+
ApplicationContext applicationContext;
45+
3746
@Test
3847
public void validateTransactionalProxyIsolationToThePollerOnly() {
39-
ClassPathXmlApplicationContext context =
40-
new ClassPathXmlApplicationContext("TransactionalPollerWithMixedAopConfig-context.xml", this.getClass());
41-
42-
assertThat(!(context.getBean("foo") instanceof Advised)).isTrue();
43-
assertThat(!(context.getBean("inputChannel") instanceof Advised)).isTrue();
44-
context.close();
48+
assertThat(this.applicationContext.getBean("foo")).isNotInstanceOf(Advised.class);
49+
assertThat(applicationContext.getBean("inputChannel")).isNotInstanceOf(Advised.class);
4550
}
4651

4752
public static class SampleService {
@@ -58,9 +63,4 @@ public Foo(String value) {
5863

5964
}
6065

61-
// public static class SampleAdvice implements MethodInterceptor{
62-
// public Object invoke(MethodInvocation invocation) throws Throwable {
63-
// return invocation.proceed();
64-
// }
65-
// }
6666
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,43 +16,48 @@
1616

1717
package org.springframework.integration.dispatcher;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

21-
import org.springframework.context.support.ClassPathXmlApplicationContext;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.context.ApplicationContext;
2223
import org.springframework.integration.gateway.RequestReplyExchanger;
2324
import org.springframework.messaging.Message;
2425
import org.springframework.messaging.MessageChannel;
2526
import org.springframework.messaging.MessageDeliveryException;
2627
import org.springframework.messaging.MessageHandler;
2728
import org.springframework.messaging.SubscribableChannel;
2829
import org.springframework.messaging.support.GenericMessage;
30+
import org.springframework.test.annotation.DirtiesContext;
31+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2932

3033
import static org.assertj.core.api.Assertions.assertThat;
3134

3235
/**
3336
* @author Oleg Zhurakousky
3437
* @author Gunnar Hillert
3538
* @author Gary Russell
36-
*
39+
* @author Artem Bilan
3740
*/
41+
@SpringJUnitConfig
42+
@DirtiesContext
3843
public class UnicastingDispatcherTests {
3944

40-
@SuppressWarnings("unchecked")
45+
@Autowired
46+
ApplicationContext applicationContext;
47+
4148
@Test
42-
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() throws Exception {
43-
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
44-
SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class);
49+
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() {
50+
SubscribableChannel errorChannel = this.applicationContext.getBean("errorChannel", SubscribableChannel.class);
4551
MessageHandler errorHandler = message -> {
4652
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
4753
assertThat(message.getPayload() instanceof MessageDeliveryException).isTrue();
48-
replyChannel.send(new GenericMessage<String>("reply"));
54+
replyChannel.send(new GenericMessage<>("reply"));
4955
};
5056
errorChannel.subscribe(errorHandler);
5157

52-
RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class);
53-
Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello"));
58+
RequestReplyExchanger exchanger = this.applicationContext.getBean(RequestReplyExchanger.class);
59+
Message<?> reply = exchanger.exchange(new GenericMessage<>("Hello"));
5460
assertThat(reply.getPayload()).isEqualTo("reply");
55-
context.close();
5661
}
5762

5863
}

Diff for: spring-integration-core/src/test/java/org/springframework/integration/dsl/LambdaMessageProcessorTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.integration.handler.LambdaMessageProcessor;
3636
import org.springframework.messaging.Message;
3737
import org.springframework.messaging.support.GenericMessage;
38+
import org.springframework.test.annotation.DirtiesContext;
3839
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3940

4041
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,6 +48,7 @@
4748
* @since 5.0
4849
*/
4950
@SpringJUnitConfig
51+
@DirtiesContext
5052
public class LambdaMessageProcessorTests {
5153

5254
@Autowired

Diff for: spring-integration-core/src/test/java/org/springframework/integration/dsl/lifecycle/IntegrationComponentSpecLifecycleTests.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 the original author or authors.
2+
* Copyright 2018-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.integration.dsl.lifecycle;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.beans.BeansException;
2322
import org.springframework.beans.factory.BeanClassLoaderAware;
@@ -42,7 +41,7 @@
4241
import org.springframework.integration.config.EnableIntegration;
4342
import org.springframework.integration.dsl.IntegrationComponentSpec;
4443
import org.springframework.test.annotation.DirtiesContext;
45-
import org.springframework.test.context.junit4.SpringRunner;
44+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4645
import org.springframework.util.StringValueResolver;
4746

4847
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +51,7 @@
5251
*
5352
* @since 5.0.7
5453
*/
55-
@RunWith(SpringRunner.class)
54+
@SpringJUnitConfig
5655
@DirtiesContext
5756
public class IntegrationComponentSpecLifecycleTests {
5857

Diff for: spring-integration-core/src/test/java/org/springframework/integration/dsl/publishsubscribe/PublishSubscribeTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2022 the original author or authors.
2+
* Copyright 2017-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,7 @@
2020
import java.util.List;
2121
import java.util.function.Consumer;
2222

23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.Test;
2524

2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.beans.factory.annotation.Qualifier;
@@ -34,7 +33,8 @@
3433
import org.springframework.messaging.MessageChannel;
3534
import org.springframework.messaging.MessageHandler;
3635
import org.springframework.messaging.support.GenericMessage;
37-
import org.springframework.test.context.junit4.SpringRunner;
36+
import org.springframework.test.annotation.DirtiesContext;
37+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3838

3939
import static org.assertj.core.api.Assertions.assertThat;
4040

@@ -44,7 +44,8 @@
4444
*
4545
* @since 5.0
4646
*/
47-
@RunWith(SpringRunner.class)
47+
@SpringJUnitConfig
48+
@DirtiesContext
4849
public class PublishSubscribeTests {
4950

5051
@Autowired

Diff for: spring-integration-core/src/test/java/org/springframework/integration/dsl/routers/NoFallbackAllowedTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 the original author or authors.
2+
* Copyright 2019-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727
import org.springframework.integration.config.EnableIntegration;
2828
import org.springframework.integration.dsl.IntegrationFlow;
2929
import org.springframework.messaging.support.GenericMessage;
30+
import org.springframework.test.annotation.DirtiesContext;
3031
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3132

3233
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,6 +40,7 @@
3940
*
4041
*/
4142
@SpringJUnitConfig
43+
@DirtiesContext
4244
public class NoFallbackAllowedTests {
4345

4446
@Test

0 commit comments

Comments
 (0)