Skip to content

Commit 4ccec0b

Browse files
committed
More @DirtiesContext in test of core module
The another attempt to mitigate out of memory error on GitHub Actions
1 parent a171ffd commit 4ccec0b

16 files changed

+117
-128
lines changed

spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorWithCorrelationStrategyTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -18,8 +18,7 @@
1818

1919
import java.util.List;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.beans.factory.annotation.Autowired;
2524
import org.springframework.beans.factory.annotation.Qualifier;
@@ -31,8 +30,8 @@
3130
import org.springframework.messaging.Message;
3231
import org.springframework.messaging.MessageChannel;
3332
import org.springframework.messaging.PollableChannel;
34-
import org.springframework.test.context.ContextConfiguration;
35-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33+
import org.springframework.test.annotation.DirtiesContext;
34+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3635

3736
import static org.assertj.core.api.Assertions.assertThat;
3837

@@ -42,8 +41,8 @@
4241
* @author Gunnar Hillert
4342
* @author Artem Bilan
4443
*/
45-
@ContextConfiguration
46-
@RunWith(SpringJUnit4ClassRunner.class)
44+
@SpringJUnitConfig
45+
@DirtiesContext
4746
public class AggregatorWithCorrelationStrategyTests {
4847

4948
@Autowired

spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -18,8 +18,7 @@
1818

1919
import java.util.concurrent.TimeUnit;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.beans.factory.annotation.Autowired;
2524
import org.springframework.beans.factory.annotation.Qualifier;
@@ -33,15 +32,15 @@
3332
import org.springframework.messaging.MessageChannel;
3433
import org.springframework.messaging.PollableChannel;
3534
import org.springframework.test.annotation.DirtiesContext;
36-
import org.springframework.test.context.junit4.SpringRunner;
35+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3736

3837
import static org.assertj.core.api.Assertions.assertThat;
3938

4039
/**
4140
* @author Dave Syer
4241
* @author Artem Bilan
4342
*/
44-
@RunWith(SpringRunner.class)
43+
@SpringJUnitConfig
4544
@DirtiesContext
4645
public class ChannelWithMessageStoreParserTests {
4746

@@ -71,7 +70,6 @@ public class ChannelWithMessageStoreParserTests {
7170
private MessageGroupStore priorityMessageStore;
7271

7372
@Test
74-
@DirtiesContext
7573
public void testActivatorSendsToPersistentQueue() throws Exception {
7674

7775
input.send(createMessage("123", "id1", 3, 1, null));
@@ -87,7 +85,6 @@ public void testActivatorSendsToPersistentQueue() throws Exception {
8785
}
8886

8987
@Test
90-
@DirtiesContext
9188
public void testPriorityMessageStore() {
9289
assertThat(TestUtils.getPropertyValue(this.priorityChannel, "queue.messageGroupStore"))
9390
.isSameAs(this.priorityMessageStore);
@@ -96,6 +93,7 @@ public void testPriorityMessageStore() {
9693

9794
private static <T> Message<T> createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber,
9895
MessageChannel outputChannel) {
96+
9997
return MessageBuilder.withPayload(payload).setCorrelationId(correlationId).setSequenceSize(sequenceSize)
10098
.setSequenceNumber(sequenceNumber).setReplyChannel(outputChannel).build();
10199
}

spring-integration-core/src/test/java/org/springframework/integration/config/CorrelationStrategyInvalidConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -31,7 +31,7 @@
3131
public class CorrelationStrategyInvalidConfigurationTests {
3232

3333
@Test
34-
public void testCorrelationStrategyWithVoidReturningMethods() throws Exception {
34+
public void testCorrelationStrategyWithVoidReturningMethods() {
3535
assertThatExceptionOfType(BeanCreationException.class)
3636
.isThrownBy(() -> new ClassPathXmlApplicationContext("correlationStrategyWithVoidMethods.xml",
3737
getClass()))

spring-integration-core/src/test/java/org/springframework/integration/config/EndpointParserTests.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -18,7 +18,7 @@
1818

1919
import java.util.concurrent.TimeUnit;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.springframework.context.support.ClassPathXmlApplicationContext;
2424
import org.springframework.messaging.MessageChannel;
@@ -35,16 +35,15 @@ public class EndpointParserTests {
3535

3636
@Test
3737
public void testSimpleEndpoint() throws InterruptedException {
38-
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
39-
"simpleEndpointTests.xml", this.getClass());
40-
context.start();
41-
MessageChannel channel = (MessageChannel) context.getBean("endpointParserTestInput");
42-
TestHandler handler = (TestHandler) context.getBean("testHandler");
43-
assertThat(handler.getMessageString()).isNull();
44-
channel.send(new GenericMessage<>("test"));
45-
assertThat(handler.getLatch().await(10000, TimeUnit.MILLISECONDS)).isTrue();
46-
assertThat(handler.getMessageString()).isEqualTo("test");
47-
context.close();
38+
try (var context = new ClassPathXmlApplicationContext("simpleEndpointTests.xml", getClass())) {
39+
context.start();
40+
MessageChannel channel = (MessageChannel) context.getBean("endpointParserTestInput");
41+
TestHandler handler = (TestHandler) context.getBean("testHandler");
42+
assertThat(handler.getMessageString()).isNull();
43+
channel.send(new GenericMessage<>("test"));
44+
assertThat(handler.getLatch().await(10000, TimeUnit.MILLISECONDS)).isTrue();
45+
assertThat(handler.getMessageString()).isEqualTo("test");
46+
}
4847
}
4948

5049
}

spring-integration-core/src/test/java/org/springframework/integration/config/FilterParserTests.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.integration.config;
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.beans.factory.annotation.Qualifier;
@@ -30,19 +29,20 @@
3029
import org.springframework.messaging.MessageChannel;
3130
import org.springframework.messaging.PollableChannel;
3231
import org.springframework.messaging.support.GenericMessage;
33-
import org.springframework.test.context.ContextConfiguration;
34-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
32+
import org.springframework.test.annotation.DirtiesContext;
33+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3534
import org.springframework.util.StringUtils;
3635

3736
import static org.assertj.core.api.Assertions.assertThat;
37+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3838

3939
/**
4040
* @author Mark Fisher
4141
* @author Gary Russell
4242
* @author Artem Bilan
4343
*/
44-
@RunWith(SpringJUnit4ClassRunner.class)
45-
@ContextConfiguration
44+
@SpringJUnitConfig
45+
@DirtiesContext
4646
public class FilterParserTests {
4747

4848
@Autowired
@@ -136,9 +136,10 @@ public void exceptionThrowingFilterAccepts() {
136136
assertThat(reply).isNotNull();
137137
}
138138

139-
@Test(expected = MessageRejectedException.class)
139+
@Test
140140
public void exceptionThrowingFilterRejects() {
141-
exceptionInput.send(new GenericMessage<>(""));
141+
assertThatExceptionOfType(MessageRejectedException.class)
142+
.isThrownBy(() -> exceptionInput.send(new GenericMessage<>("")));
142143
}
143144

144145
@Test
@@ -150,20 +151,14 @@ public void filterWithDiscardChannel() {
150151
assertThat(adapterOutput.receive(0)).isNull();
151152
}
152153

153-
@Test(expected = MessageRejectedException.class)
154-
public void filterWithDiscardChannelAndException() throws Exception {
155-
Exception exception = null;
156-
try {
157-
discardAndExceptionInput.send(new GenericMessage<>(""));
158-
}
159-
catch (Exception e) {
160-
exception = e;
161-
}
154+
@Test
155+
public void filterWithDiscardChannelAndException() {
156+
assertThatExceptionOfType(MessageRejectedException.class)
157+
.isThrownBy(() -> discardAndExceptionInput.send(new GenericMessage<>("")));
162158
Message<?> discard = discardAndExceptionOutput.receive(0);
163159
assertThat(discard).isNotNull();
164160
assertThat(discard.getPayload()).isEqualTo("");
165161
assertThat(adapterOutput.receive(0)).isNull();
166-
throw exception;
167162
}
168163

169164
public static class TestSelectorBean {

spring-integration-core/src/test/java/org/springframework/integration/config/GlobalChannelInterceptorProcessorTests.java

Lines changed: 16 additions & 16 deletions
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,16 +20,16 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23-
import org.junit.Before;
24-
import org.junit.Test;
25-
import org.mockito.Mockito;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2625

2726
import org.springframework.beans.factory.ListableBeanFactory;
2827
import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper;
2928
import org.springframework.messaging.support.ChannelInterceptor;
3029
import org.springframework.messaging.support.InterceptableChannel;
3130

3231
import static org.mockito.Mockito.mock;
32+
import static org.mockito.Mockito.never;
3333
import static org.mockito.Mockito.verify;
3434
import static org.mockito.Mockito.when;
3535

@@ -44,7 +44,7 @@ public class GlobalChannelInterceptorProcessorTests {
4444

4545
private ListableBeanFactory beanFactory;
4646

47-
@Before
47+
@BeforeEach
4848
public void setup() {
4949
this.globalChannelInterceptorProcessor = new GlobalChannelInterceptorProcessor();
5050
this.beanFactory = mock(ListableBeanFactory.class);
@@ -58,19 +58,19 @@ public void testProcessorWithNoInterceptor() {
5858
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
5959
verify(this.beanFactory)
6060
.getBeansOfType(GlobalChannelInterceptorWrapper.class);
61-
verify(this.beanFactory, Mockito.never())
61+
verify(this.beanFactory, never())
6262
.getBeansOfType(InterceptableChannel.class);
6363
}
6464

6565
@Test
6666
public void testProcessorWithInterceptorDefaultPattern() {
6767
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
6868
Map<String, InterceptableChannel> channels = new HashMap<>();
69-
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
69+
ChannelInterceptor channelInterceptor = mock();
7070
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper =
7171
new GlobalChannelInterceptorWrapper(channelInterceptor);
7272

73-
InterceptableChannel channel = Mockito.mock(InterceptableChannel.class);
73+
InterceptableChannel channel = mock();
7474

7575
interceptors.put("Test-1", globalChannelInterceptorWrapper);
7676
channels.put("Test-1", channel);
@@ -89,11 +89,11 @@ public void testProcessorWithInterceptorDefaultPattern() {
8989
public void testProcessorWithInterceptorMatchingPattern() {
9090
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
9191
Map<String, InterceptableChannel> channels = new HashMap<>();
92-
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
92+
ChannelInterceptor channelInterceptor = mock();
9393
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper =
9494
new GlobalChannelInterceptorWrapper(channelInterceptor);
9595

96-
InterceptableChannel channel = Mockito.mock(InterceptableChannel.class);
96+
InterceptableChannel channel = mock();
9797

9898
globalChannelInterceptorWrapper.setPatterns(new String[] {"Te*"});
9999
interceptors.put("Test-1", globalChannelInterceptorWrapper);
@@ -112,11 +112,11 @@ public void testProcessorWithInterceptorMatchingPattern() {
112112
public void testProcessorWithInterceptorNotMatchingPattern() {
113113
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
114114
Map<String, InterceptableChannel> channels = new HashMap<>();
115-
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
115+
ChannelInterceptor channelInterceptor = mock();
116116
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper =
117117
new GlobalChannelInterceptorWrapper(channelInterceptor);
118118

119-
InterceptableChannel channel = Mockito.mock(InterceptableChannel.class);
119+
InterceptableChannel channel = mock();
120120

121121
globalChannelInterceptorWrapper.setPatterns(new String[] {"te*"});
122122
interceptors.put("Test-1", globalChannelInterceptorWrapper);
@@ -128,19 +128,19 @@ public void testProcessorWithInterceptorNotMatchingPattern() {
128128

129129
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
130130

131-
verify(channel, Mockito.never())
131+
verify(channel, never())
132132
.addInterceptor(channelInterceptor);
133133
}
134134

135135
@Test
136136
public void testProcessorWithInterceptorMatchingNegativePattern() {
137137
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
138138
Map<String, InterceptableChannel> channels = new HashMap<>();
139-
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
139+
ChannelInterceptor channelInterceptor = mock();
140140
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper =
141141
new GlobalChannelInterceptorWrapper(channelInterceptor);
142142

143-
InterceptableChannel channel = Mockito.mock(InterceptableChannel.class);
143+
InterceptableChannel channel = mock();
144144

145145
globalChannelInterceptorWrapper.setPatterns(new String[] {"!te*", "!Te*"});
146146
interceptors.put("Test-1", globalChannelInterceptorWrapper);
@@ -151,7 +151,7 @@ public void testProcessorWithInterceptorMatchingNegativePattern() {
151151
.thenReturn(channels);
152152
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
153153

154-
verify(channel, Mockito.never())
154+
verify(channel, never())
155155
.addInterceptor(channelInterceptor);
156156
}
157157

spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-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.
@@ -18,8 +18,7 @@
1818

1919
import java.util.concurrent.Executor;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.beans.DirectFieldAccessor;
2524
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,7 +28,8 @@
2928
import org.springframework.integration.support.utils.IntegrationUtils;
3029
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
3130
import org.springframework.messaging.support.GenericMessage;
32-
import org.springframework.test.context.junit4.SpringRunner;
31+
import org.springframework.test.annotation.DirtiesContext;
32+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3333
import org.springframework.util.ErrorHandler;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,7 +39,8 @@
3939
* @author Gary Russell
4040
* @author Artem Bilan
4141
*/
42-
@RunWith(SpringRunner.class)
42+
@SpringJUnitConfig
43+
@DirtiesContext
4344
public class PublishSubscribeChannelParserTests {
4445

4546
@Autowired

0 commit comments

Comments
 (0)