Skip to content

Commit 17ee9b3

Browse files
committed
Migrate few modules to Junit Jupiter
including: `spring-integration-amqp`, `spring-integration-file`, 'spring-integration-groovy' Signed-off-by: Jiandong Ma <[email protected]>
1 parent debd4d4 commit 17ee9b3

File tree

42 files changed

+267
-314
lines changed

Some content is hidden

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

42 files changed

+267
-314
lines changed

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 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.
@@ -22,18 +22,17 @@
2222
import java.util.concurrent.TimeUnit;
2323
import java.util.concurrent.locks.Lock;
2424

25-
import org.junit.After;
26-
import org.junit.ClassRule;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.Test;
2927

3028
import org.springframework.amqp.core.AmqpTemplate;
3129
import org.springframework.amqp.core.MessageListener;
3230
import org.springframework.amqp.core.Queue;
3331
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
3432
import org.springframework.amqp.rabbit.core.RabbitAdmin;
3533
import org.springframework.amqp.rabbit.core.RabbitTemplate;
36-
import org.springframework.amqp.rabbit.junit.BrokerRunning;
34+
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
35+
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition;
3736
import org.springframework.amqp.rabbit.listener.BlockingQueueConsumer;
3837
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
3938
import org.springframework.amqp.support.converter.MessageConversionException;
@@ -49,8 +48,7 @@
4948
import org.springframework.messaging.support.GenericMessage;
5049
import org.springframework.test.annotation.DirtiesContext;
5150
import org.springframework.test.annotation.DirtiesContext.ClassMode;
52-
import org.springframework.test.context.ContextConfiguration;
53-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
51+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5452

5553
import static org.assertj.core.api.Assertions.assertThat;
5654
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -65,15 +63,11 @@
6563
* @since 4.0
6664
*
6765
*/
68-
@ContextConfiguration
69-
@RunWith(SpringJUnit4ClassRunner.class)
66+
@SpringJUnitConfig
67+
@RabbitAvailable(queues = {"pollableWithEP", "withEP", "testConvertFail"})
7068
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
7169
public class ChannelTests {
7270

73-
@ClassRule
74-
public static final BrokerRunning brokerIsRunning =
75-
BrokerRunning.isRunningWithEmptyQueues("pollableWithEP", "withEP", "testConvertFail");
76-
7771
@Autowired
7872
private PublishSubscribeAmqpChannel channel;
7973

@@ -98,10 +92,10 @@ public class ChannelTests {
9892
@Autowired
9993
private AmqpHeaderMapper mapperOut;
10094

101-
@After
95+
@AfterEach
10296
public void tearDown() {
103-
brokerIsRunning.deleteExchanges("si.fanout.foo", "si.fanout.channel", "si.fanout.pubSubWithEP");
104-
brokerIsRunning.removeTestQueues();
97+
RabbitAvailableCondition.getBrokerRunning().deleteExchanges("si.fanout.foo", "si.fanout.channel", "si.fanout.pubSubWithEP");
98+
RabbitAvailableCondition.getBrokerRunning().removeTestQueues();
10599
}
106100

107101
@Test

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.amqp.core.MessageDeliveryMode;
2524
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
@@ -35,8 +34,7 @@
3534
import org.springframework.messaging.MessageChannel;
3635
import org.springframework.messaging.support.ChannelInterceptor;
3736
import org.springframework.test.annotation.DirtiesContext;
38-
import org.springframework.test.context.ContextConfiguration;
39-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
37+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4038

4139
import static org.assertj.core.api.Assertions.assertThat;
4240

@@ -45,8 +43,7 @@
4543
* @author Gary Russell
4644
* @since 2.1
4745
*/
48-
@ContextConfiguration
49-
@RunWith(SpringJUnit4ClassRunner.class)
46+
@SpringJUnitConfig
5047
@DirtiesContext
5148
public class AmqpChannelParserTests {
5249

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpOutboundGatewayParserTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.concurrent.atomic.AtomicBoolean;
2222

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

2726
import org.springframework.amqp.core.MessageDeliveryMode;
@@ -42,7 +41,7 @@
4241
import org.springframework.messaging.Message;
4342
import org.springframework.messaging.MessageChannel;
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.ReflectionUtils;
4746

4847
import static org.assertj.core.api.Assertions.assertThat;
@@ -57,7 +56,7 @@
5756
* @since 2.1
5857
*
5958
*/
60-
@RunWith(SpringRunner.class)
59+
@SpringJUnitConfig
6160
@DirtiesContext
6261
public class AmqpOutboundGatewayParserTests {
6362

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayIntegrationTests.java

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

1717
package org.springframework.integration.amqp.config;
1818

19-
import org.junit.ClassRule;
20-
import org.junit.Test;
21-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Test;
2220

23-
import org.springframework.amqp.rabbit.junit.BrokerRunning;
21+
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
2422
import org.springframework.beans.factory.annotation.Autowired;
2523
import org.springframework.messaging.Message;
2624
import org.springframework.messaging.MessageChannel;
2725
import org.springframework.messaging.PollableChannel;
2826
import org.springframework.messaging.support.GenericMessage;
2927
import org.springframework.test.annotation.DirtiesContext;
30-
import org.springframework.test.context.ContextConfiguration;
31-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
28+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3229

3330
import static org.assertj.core.api.Assertions.assertThat;
3431

@@ -38,14 +35,11 @@
3835
* @author Gary Russell
3936
* @since 2.1
4037
*/
41-
@ContextConfiguration
42-
@RunWith(SpringJUnit4ClassRunner.class)
38+
@SpringJUnitConfig
39+
@RabbitAvailable
4340
@DirtiesContext
4441
public class OutboundGatewayIntegrationTests {
4542

46-
@ClassRule
47-
public static final BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
48-
4943
@Autowired
5044
private MessageChannel toRabbit;
5145

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/AmqpMessageSourceTests.java

Lines changed: 2 additions & 2 deletions
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-2025 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.
@@ -25,7 +25,7 @@
2525
import com.rabbitmq.client.ConnectionFactory;
2626
import com.rabbitmq.client.Envelope;
2727
import com.rabbitmq.client.GetResponse;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
import org.springframework.amqp.core.MessageProperties;
3131
import org.springframework.amqp.rabbit.batch.MessageBatch;

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/ManualAckTests.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 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.
@@ -17,25 +17,22 @@
1717
package org.springframework.integration.amqp.inbound;
1818

1919
import com.rabbitmq.client.Channel;
20-
import org.junit.Rule;
21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
20+
import org.junit.jupiter.api.Test;
2321

2422
import org.springframework.amqp.core.AcknowledgeMode;
2523
import org.springframework.amqp.core.AnonymousQueue;
2624
import org.springframework.amqp.core.Queue;
2725
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
2826
import org.springframework.amqp.rabbit.core.RabbitAdmin;
2927
import org.springframework.amqp.rabbit.core.RabbitTemplate;
30-
import org.springframework.amqp.rabbit.junit.BrokerRunning;
28+
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
3129
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
3230
import org.springframework.amqp.support.AmqpHeaders;
3331
import org.springframework.beans.factory.BeanFactory;
3432
import org.springframework.beans.factory.annotation.Autowired;
3533
import org.springframework.context.annotation.Bean;
3634
import org.springframework.context.annotation.ComponentScan;
3735
import org.springframework.context.annotation.Configuration;
38-
import org.springframework.integration.amqp.inbound.ManualAckTests.ManualAckConfig;
3936
import org.springframework.integration.annotation.MessageEndpoint;
4037
import org.springframework.integration.annotation.ServiceActivator;
4138
import org.springframework.integration.channel.QueueChannel;
@@ -46,25 +43,22 @@
4643
import org.springframework.messaging.handler.annotation.Header;
4744
import org.springframework.messaging.handler.annotation.Payload;
4845
import org.springframework.test.annotation.DirtiesContext;
49-
import org.springframework.test.context.ContextConfiguration;
50-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
46+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5147

5248
import static org.assertj.core.api.Assertions.assertThat;
5349
import static org.mockito.Mockito.mock;
50+
import static org.springframework.integration.amqp.inbound.ManualAckTests.ManualAckConfig;
5451

5552
/**
5653
* @author Gary Russell
5754
* @since 4.0
5855
*
5956
*/
60-
@ContextConfiguration(classes = ManualAckConfig.class)
61-
@RunWith(SpringJUnit4ClassRunner.class)
57+
@RabbitAvailable
58+
@SpringJUnitConfig(ManualAckConfig.class)
6259
@DirtiesContext
6360
public class ManualAckTests {
6461

65-
@Rule
66-
public BrokerRunning brokerRunning = BrokerRunning.isRunning();
67-
6862
@Autowired
6963
private MessageChannel foo;
7064

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/JsonConverterCompatibilityTests.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 the original author or authors.
2+
* Copyright 2016-2025 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.
@@ -17,15 +17,15 @@
1717
package org.springframework.integration.amqp.support;
1818

1919
import com.rabbitmq.client.AMQP.BasicProperties;
20-
import org.junit.After;
21-
import org.junit.Before;
22-
import org.junit.Rule;
23-
import org.junit.Test;
20+
import org.junit.jupiter.api.AfterEach;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
2423

2524
import org.springframework.amqp.core.MessageProperties;
2625
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
2726
import org.springframework.amqp.rabbit.core.RabbitTemplate;
28-
import org.springframework.amqp.rabbit.junit.BrokerRunning;
27+
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
28+
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition;
2929
import org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter;
3030
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
3131
import org.springframework.integration.json.ObjectToJsonTransformer;
@@ -39,24 +39,22 @@
3939
* @since 4.3
4040
*
4141
*/
42+
@RabbitAvailable(queues = {JsonConverterCompatibilityTests.JSON_TESTQ})
4243
public class JsonConverterCompatibilityTests {
4344

44-
private static final String JSON_TESTQ = "si.json.tests";
45-
46-
@Rule
47-
public BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues(JSON_TESTQ);
45+
public static final String JSON_TESTQ = "si.json.tests";
4846

4947
private RabbitTemplate rabbitTemplate;
5048

51-
@Before
49+
@BeforeEach
5250
public void setUp() {
5351
this.rabbitTemplate = new RabbitTemplate(new CachingConnectionFactory("localhost"));
5452
this.rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
5553
}
5654

57-
@After
55+
@AfterEach
5856
public void tearDown() {
59-
this.brokerRunning.removeTestQueues();
57+
RabbitAvailableCondition.getBrokerRunning().removeTestQueues();
6058
((CachingConnectionFactory) this.rabbitTemplate.getConnectionFactory()).destroy();
6159
}
6260

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/MappingUtilsTests.java

Lines changed: 2 additions & 2 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-2025 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,7 +16,7 @@
1616

1717
package org.springframework.integration.amqp.support;
1818

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

2121
import org.springframework.amqp.core.MessageDeliveryMode;
2222
import org.springframework.amqp.support.AmqpHeaders;

spring-integration-file/src/test/java/org/springframework/integration/file/AutoCreateDirectoryTests.java

Lines changed: 9 additions & 8 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-2025 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,9 +18,9 @@
1818

1919
import java.io.File;
2020

21-
import org.junit.After;
22-
import org.junit.Before;
23-
import org.junit.Test;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2424

2525
import org.springframework.beans.factory.BeanFactory;
2626

@@ -44,8 +44,8 @@ public class AutoCreateDirectoryTests {
4444

4545
private static final String OUTBOUND_PATH = BASE_PATH + File.separator + "outbound";
4646

47-
@Before
48-
@After
47+
@BeforeEach
48+
@AfterEach
4949
public void clearDirectories() {
5050
File baseDir = new File(BASE_PATH);
5151
File inboundDir = new File(INBOUND_PATH);
@@ -92,13 +92,14 @@ public void autoCreateForOutboundEnabledByDefault() {
9292
assertThat(new File(OUTBOUND_PATH).exists()).isTrue();
9393
}
9494

95-
@Test(expected = IllegalArgumentException.class)
95+
@Test
9696
public void autoCreateForOutboundDisabled() {
9797
FileWritingMessageHandler handler = new FileWritingMessageHandler(
9898
new File(OUTBOUND_PATH));
9999
handler.setBeanFactory(mock(BeanFactory.class));
100100
handler.setAutoCreateDirectory(false);
101-
handler.afterPropertiesSet();
101+
assertThatIllegalArgumentException()
102+
.isThrownBy(handler::afterPropertiesSet);
102103
}
103104

104105
}

0 commit comments

Comments
 (0)