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

0 commit comments

Comments
 (0)