Skip to content

Commit 868979d

Browse files
garyrussellartembilan
authored andcommitted
Convert remaining spring-rabbit tests to JUnit 5
* Fix possible race in testConsumerBatching * Convert all spring-amqp tests to JUnit 5 * Convert remaining tests to JUnit 5; remove JUnit 4 test dependency * Remove JUnit vintage engine dependency
1 parent accd202 commit 868979d

File tree

78 files changed

+460
-646
lines changed

Some content is hidden

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

78 files changed

+460
-646
lines changed

build.gradle

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,21 @@ subprojects { subproject ->
124124
// dependencies that are common across all java projects
125125
dependencies {
126126
compileOnly "com.google.code.findbugs:jsr305:$googleJsr305Version"
127-
testCompile ("junit:junit:$junit4Version") {
128-
exclude group: 'org.hamcrest', module: 'hamcrest-core'
129-
}
130127
testCompile "org.apache.logging.log4j:log4j-core:$log4jVersion"
131128
testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion"
132129
testCompile ("org.mockito:mockito-core:$mockitoVersion") {
133130
exclude group: 'org.hamcrest', module: 'hamcrest-core'
134131
}
132+
testCompile "org.mockito:mockito-junit-jupiter:$mockitoVersion"
135133
testCompile "org.springframework:spring-test:$springVersion"
136134

137135
testRuntime "org.apache.logging.log4j:log4j-jcl:$log4jVersion"
138136

139137
testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
138+
testCompile "org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion"
140139
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion"
141140
testRuntime "org.junit.platform:junit-platform-launcher:$junitPlatformVersion"
142141

143-
// To support JUnit 4 tests
144-
testRuntime "org.junit.vintage:junit-vintage-engine:$junitJupiterVersion"
145-
146142
// To avoid compiler warnings about @API annotations in JUnit code
147143
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
148144

@@ -368,7 +364,11 @@ project('spring-rabbit-junit') {
368364
dependencies { // no spring-amqp dependencies allowed
369365

370366
compile "org.springframework:spring-core:$springVersion"
371-
compile ("junit:junit:$junit4Version", optional)
367+
compile "org.springframework:spring-test:$springVersion"
368+
compile ("junit:junit:$junit4Version") {
369+
optional(it)
370+
exclude group: 'org.hamcrest', module: 'hamcrest-core'
371+
}
372372
compile "com.rabbitmq:amqp-client:$rabbitmqVersion"
373373
compile ("com.rabbitmq:http-client:$rabbitmqHttpClientVersion") {
374374
exclude group: 'org.springframework', module: 'spring-web'
@@ -396,10 +396,6 @@ project('spring-rabbit-test') {
396396
dependencies {
397397

398398
compile project(":spring-rabbit")
399-
compile ("junit:junit:$junit4Version") {
400-
optional(it)
401-
exclude group: 'org.hamcrest', module: 'hamcrest-core'
402-
}
403399
compile "org.hamcrest:hamcrest-all:$hamcrestVersion"
404400
compile ("org.mockito:mockito-core:$mockitoVersion") {
405401
exclude group: 'org.hamcrest', module: 'hamcrest-core'

spring-amqp/src/test/java/org/springframework/amqp/core/AddressTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020

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

2323
/**
2424
* @author Mark Pollack

spring-amqp/src/test/java/org/springframework/amqp/core/BindingBuilderTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import java.util.Collections;
2222

23-
import org.junit.BeforeClass;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.junit.jupiter.api.Test;
2525

2626
/**
2727
* @author Mark Fisher
@@ -31,7 +31,7 @@ public class BindingBuilderTests {
3131

3232
private static Queue queue;
3333

34-
@BeforeClass
34+
@BeforeAll
3535
public static void setUp() {
3636
queue = new Queue("q");
3737
}

spring-amqp/src/test/java/org/springframework/amqp/core/MessagePropertiesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.HashSet;
2222
import java.util.Set;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626

2727
/**

spring-amqp/src/test/java/org/springframework/amqp/core/MessageTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.Collections;
2727
import java.util.Date;
2828

29-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3030

3131
import org.springframework.amqp.support.converter.SimpleMessageConverter;
3232
import org.springframework.amqp.utils.SerializationUtils;

spring-amqp/src/test/java/org/springframework/amqp/core/QueueBuilderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
/**
2727
* Tests for {@link QueueBuilder}

spring-amqp/src/test/java/org/springframework/amqp/core/QueueNameTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import java.util.regex.Pattern;
2222

23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
/**
2626
* @author Gary Russell

spring-amqp/src/test/java/org/springframework/amqp/core/builder/BuilderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020

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

2323
import org.springframework.amqp.core.DirectExchange;
2424
import org.springframework.amqp.core.Exchange;

spring-amqp/src/test/java/org/springframework/amqp/core/builder/MessageBuilderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Collections;
2323
import java.util.Date;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.amqp.core.Address;
2828
import org.springframework.amqp.core.Message;

spring-amqp/src/test/java/org/springframework/amqp/remoting/RemotingTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
package org.springframework.amqp.remoting;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2021

2122
import java.util.concurrent.atomic.AtomicBoolean;
2223

23-
import org.junit.Before;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2526

2627
import org.springframework.amqp.AmqpException;
2728
import org.springframework.amqp.core.Address;
@@ -58,7 +59,7 @@ public class RemotingTest {
5859
* Set up a rig of directly wired-up proxy and service listener so that both can be tested together without needing
5960
* a running rabbit.
6061
*/
61-
@Before
62+
@BeforeEach
6263
public void initializeTestRig() {
6364
// Set up the service
6465
TestServiceInterface testService = new TestServiceImpl();
@@ -113,15 +114,15 @@ public void testSimulatedTimeout() {
113114
}
114115
}
115116

116-
@Test(expected = RuntimeException.class)
117+
@Test
117118
public void testExceptionPropagation() {
118-
riggedProxy.exceptionThrowingMethod();
119+
assertThatExceptionOfType(AmqpException.class).isThrownBy(() -> riggedProxy.exceptionThrowingMethod());
119120
}
120121

121-
@Test(expected = GeneralException.class)
122-
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
122+
@Test
123123
public void testExceptionReturningMethod() {
124-
riggedProxy.notReallyExceptionReturningMethod();
124+
assertThatExceptionOfType(GeneralException.class)
125+
.isThrownBy(() -> riggedProxy.notReallyExceptionReturningMethod());
125126
}
126127

127128
@Test

spring-amqp/src/test/java/org/springframework/amqp/remoting/testservice/TestServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.amqp.remoting.testservice;
1818

19+
import org.springframework.amqp.AmqpException;
20+
1921
/**
2022
* @author David Bilge
2123
* @author Gary Russell
@@ -34,7 +36,7 @@ public String simpleStringReturningTestMethod(String string) {
3436

3537
@Override
3638
public void exceptionThrowingMethod() {
37-
throw new RuntimeException("This is an exception");
39+
throw new AmqpException("This is an exception");
3840
}
3941

4042
@Override

spring-amqp/src/test/java/org/springframework/amqp/support/AmqpMessageHeaderAccessorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Date;
2323
import java.util.Map;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.amqp.core.MessageDeliveryMode;
2828
import org.springframework.amqp.core.MessageProperties;

spring-amqp/src/test/java/org/springframework/amqp/support/MessagePostProcessorUtilsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Collection;
2323
import java.util.Iterator;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.amqp.AmqpException;
2828
import org.springframework.amqp.core.Message;

spring-amqp/src/test/java/org/springframework/amqp/support/SimpleAmqpHeaderMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.Map;
2525
import java.util.Set;
2626

27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828

2929
import org.springframework.amqp.core.Message;
3030
import org.springframework.amqp.core.MessageDeliveryMode;

spring-amqp/src/test/java/org/springframework/amqp/support/converter/ContentTypeDelegatingMessageConverterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import java.io.Serializable;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.amqp.core.Message;
2727
import org.springframework.amqp.core.MessageProperties;

spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultClassMapperTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import java.util.LinkedHashMap;
2424
import java.util.Map;
2525

26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.extension.ExtendWith;
2828
import org.mockito.Spy;
29-
import org.mockito.junit.MockitoJUnitRunner;
29+
import org.mockito.junit.jupiter.MockitoExtension;
3030

3131
import org.springframework.amqp.core.MessageProperties;
3232

@@ -35,7 +35,7 @@
3535
* @author Gary Russell
3636
*
3737
*/
38-
@RunWith(MockitoJUnitRunner.class)
38+
@ExtendWith(MockitoExtension.class)
3939
public class DefaultClassMapperTests {
4040

4141
@Spy

spring-amqp/src/test/java/org/springframework/amqp/support/converter/DefaultJackson2JavaTypeMapperTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import java.util.HashMap;
2525
import java.util.Map;
2626

27-
import org.junit.Before;
28-
import org.junit.Test;
29-
import org.junit.runner.RunWith;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.extension.ExtendWith;
3030
import org.mockito.Spy;
31-
import org.mockito.junit.MockitoJUnitRunner;
31+
import org.mockito.junit.jupiter.MockitoExtension;
3232

3333
import org.springframework.amqp.core.MessageProperties;
3434

@@ -45,7 +45,7 @@
4545
* @author Artem Bilan
4646
*/
4747

48-
@RunWith(MockitoJUnitRunner.class)
48+
@ExtendWith(MockitoExtension.class)
4949
public class DefaultJackson2JavaTypeMapperTests {
5050

5151
@Spy
@@ -59,7 +59,7 @@ public class DefaultJackson2JavaTypeMapperTests {
5959
@SuppressWarnings("rawtypes")
6060
private final Class<HashMap> mapClass = HashMap.class;
6161

62-
@Before
62+
@BeforeEach
6363
public void setup() {
6464
this.javaTypeMapper.setTrustedPackages("org.springframework.amqp.support.converter");
6565
}

spring-amqp/src/test/java/org/springframework/amqp/support/converter/Jackson2JsonMessageConverterTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27-
import org.junit.Before;
28-
import org.junit.Test;
29-
import org.junit.runner.RunWith;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
3029

3130
import org.springframework.amqp.core.Message;
3231
import org.springframework.amqp.core.MessageProperties;
3332
import org.springframework.beans.factory.annotation.Autowired;
3433
import org.springframework.core.ParameterizedTypeReference;
3534
import org.springframework.data.web.JsonPath;
36-
import org.springframework.test.context.ContextConfiguration;
37-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
35+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3836

3937
import com.fasterxml.jackson.databind.ObjectMapper;
4038
import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
@@ -47,8 +45,7 @@
4745
* @author Andreas Asplund
4846
* @author Artem Bilan
4947
*/
50-
@ContextConfiguration
51-
@RunWith(SpringJUnit4ClassRunner.class)
48+
@SpringJUnitConfig
5249
public class Jackson2JsonMessageConverterTests {
5350

5451
public static final String TRUSTED_PACKAGE = Jackson2JsonMessageConverterTests.class.getPackage().getName();
@@ -60,7 +57,7 @@ public class Jackson2JsonMessageConverterTests {
6057
@Autowired
6158
private Jackson2JsonMessageConverter jsonConverterWithDefaultType;
6259

63-
@Before
60+
@BeforeEach
6461
public void before() {
6562
converter = new Jackson2JsonMessageConverter(TRUSTED_PACKAGE);
6663
trade = new SimpleTrade();

spring-amqp/src/test/java/org/springframework/amqp/support/converter/Jackson2XmlMessageConverterTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27-
import org.junit.Before;
28-
import org.junit.Test;
29-
import org.junit.runner.RunWith;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
3029

3130
import org.springframework.amqp.core.Message;
3231
import org.springframework.amqp.core.MessageProperties;
3332
import org.springframework.beans.factory.annotation.Autowired;
3433
import org.springframework.core.ParameterizedTypeReference;
35-
import org.springframework.test.context.ContextConfiguration;
36-
import org.springframework.test.context.junit4.SpringRunner;
34+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3735

3836
import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
3937
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -44,8 +42,7 @@
4442
*
4543
* @since 2.1
4644
*/
47-
@ContextConfiguration
48-
@RunWith(SpringRunner.class)
45+
@SpringJUnitConfig
4946
public class Jackson2XmlMessageConverterTests {
5047

5148
public static final String TRUSTED_PACKAGE = Jackson2XmlMessageConverterTests.class.getPackage().getName();
@@ -57,7 +54,7 @@ public class Jackson2XmlMessageConverterTests {
5754
@Autowired
5855
private Jackson2XmlMessageConverter xmlConverterWithDefaultType;
5956

60-
@Before
57+
@BeforeEach
6158
public void before() {
6259
converter = new Jackson2XmlMessageConverter(TRUSTED_PACKAGE);
6360
trade = new SimpleTrade();

spring-amqp/src/test/java/org/springframework/amqp/support/converter/MarshallingMessageConverterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import javax.xml.transform.stream.StreamResult;
2626
import javax.xml.transform.stream.StreamSource;
2727

28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
import org.springframework.amqp.core.Message;
3131
import org.springframework.amqp.core.MessageProperties;

spring-amqp/src/test/java/org/springframework/amqp/support/converter/MessagingMessageConverterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static org.assertj.core.api.Assertions.assertThat;
2020
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2121

22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

2424
import org.springframework.amqp.core.MessageProperties;
2525
import org.springframework.messaging.Message;

spring-amqp/src/test/java/org/springframework/amqp/support/converter/SerializerMessageConverterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.io.ObjectInputStream;
2828
import java.io.ObjectOutputStream;
2929

30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
3131
import org.mockito.Mockito;
3232

3333
import org.springframework.amqp.core.Message;

0 commit comments

Comments
 (0)