Skip to content

Commit

Permalink
Convert remaining spring-rabbit tests to JUnit 5
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
garyrussell authored and artembilan committed Aug 22, 2019
1 parent accd202 commit 868979d
Show file tree
Hide file tree
Showing 78 changed files with 460 additions and 646 deletions.
18 changes: 7 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,21 @@ subprojects { subproject ->
// dependencies that are common across all java projects
dependencies {
compileOnly "com.google.code.findbugs:jsr305:$googleJsr305Version"
testCompile ("junit:junit:$junit4Version") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile "org.apache.logging.log4j:log4j-core:$log4jVersion"
testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion"
testCompile ("org.mockito:mockito-core:$mockitoVersion") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile "org.mockito:mockito-junit-jupiter:$mockitoVersion"
testCompile "org.springframework:spring-test:$springVersion"

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

testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
testCompile "org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion"
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion"
testRuntime "org.junit.platform:junit-platform-launcher:$junitPlatformVersion"

// To support JUnit 4 tests
testRuntime "org.junit.vintage:junit-vintage-engine:$junitJupiterVersion"

// To avoid compiler warnings about @API annotations in JUnit code
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'

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

compile "org.springframework:spring-core:$springVersion"
compile ("junit:junit:$junit4Version", optional)
compile "org.springframework:spring-test:$springVersion"
compile ("junit:junit:$junit4Version") {
optional(it)
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile "com.rabbitmq:amqp-client:$rabbitmqVersion"
compile ("com.rabbitmq:http-client:$rabbitmqHttpClientVersion") {
exclude group: 'org.springframework', module: 'spring-web'
Expand Down Expand Up @@ -396,10 +396,6 @@ project('spring-rabbit-test') {
dependencies {

compile project(":spring-rabbit")
compile ("junit:junit:$junit4Version") {
optional(it)
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile "org.hamcrest:hamcrest-all:$hamcrestVersion"
compile ("org.mockito:mockito-core:$mockitoVersion") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Mark Pollack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.util.Collections;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* @author Mark Fisher
Expand All @@ -31,7 +31,7 @@ public class BindingBuilderTests {

private static Queue queue;

@BeforeClass
@BeforeAll
public static void setUp() {
queue = new Queue("q");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;
import org.junit.jupiter.api.Test;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Collections;
import java.util.Date;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.support.converter.SimpleMessageConverter;
import org.springframework.amqp.utils.SerializationUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Tests for {@link QueueBuilder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.regex.Pattern;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* @author Gary Russell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Collections;
import java.util.Date;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.Address;
import org.springframework.amqp.core.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package org.springframework.amqp.remoting;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Address;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class RemotingTest {
* Set up a rig of directly wired-up proxy and service listener so that both can be tested together without needing
* a running rabbit.
*/
@Before
@BeforeEach
public void initializeTestRig() {
// Set up the service
TestServiceInterface testService = new TestServiceImpl();
Expand Down Expand Up @@ -113,15 +114,15 @@ public void testSimulatedTimeout() {
}
}

@Test(expected = RuntimeException.class)
@Test
public void testExceptionPropagation() {
riggedProxy.exceptionThrowingMethod();
assertThatExceptionOfType(AmqpException.class).isThrownBy(() -> riggedProxy.exceptionThrowingMethod());
}

@Test(expected = GeneralException.class)
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testExceptionReturningMethod() {
riggedProxy.notReallyExceptionReturningMethod();
assertThatExceptionOfType(GeneralException.class)
.isThrownBy(() -> riggedProxy.notReallyExceptionReturningMethod());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.amqp.remoting.testservice;

import org.springframework.amqp.AmqpException;

/**
* @author David Bilge
* @author Gary Russell
Expand All @@ -34,7 +36,7 @@ public String simpleStringReturningTestMethod(String string) {

@Override
public void exceptionThrowingMethod() {
throw new RuntimeException("This is an exception");
throw new AmqpException("This is an exception");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Date;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.core.MessageProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Collection;
import java.util.Iterator;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Map;
import java.util.Set;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageDeliveryMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.io.Serializable;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import org.springframework.amqp.core.MessageProperties;

Expand All @@ -35,7 +35,7 @@
* @author Gary Russell
*
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DefaultClassMapperTests {

@Spy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import org.springframework.amqp.core.MessageProperties;

Expand All @@ -45,7 +45,7 @@
* @author Artem Bilan
*/

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DefaultJackson2JavaTypeMapperTests {

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

@Before
@BeforeEach
public void setup() {
this.javaTypeMapper.setTrustedPackages("org.springframework.amqp.support.converter");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.web.JsonPath;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
Expand All @@ -47,8 +45,7 @@
* @author Andreas Asplund
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
public class Jackson2JsonMessageConverterTests {

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

@Before
@BeforeEach
public void before() {
converter = new Jackson2JsonMessageConverter(TRUSTED_PACKAGE);
trade = new SimpleTrade();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
Expand All @@ -44,8 +42,7 @@
*
* @since 2.1
*/
@ContextConfiguration
@RunWith(SpringRunner.class)
@SpringJUnitConfig
public class Jackson2XmlMessageConverterTests {

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

@Before
@BeforeEach
public void before() {
converter = new Jackson2XmlMessageConverter(TRUSTED_PACKAGE);
trade = new SimpleTrade();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.core.MessageProperties;
import org.springframework.messaging.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import org.springframework.amqp.core.Message;
Expand Down
Loading

0 comments on commit 868979d

Please sign in to comment.