Migrate away from ExpectedException (#22922)
* Add limited checkstyles to test code Add a limited set of checkstyle rules to the test codebase to improve code consistency. * Fix checksyle violations in test code * Organize imports to fix checkstyle for test code * Migrate to assertThatExceptionOfType Migrate aware from ExpectedException rules to AssertJ exception assertions. Also include a checkstyle rules to ensure that the the ExpectedException is not accidentally used in the future. See gh-22894
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,9 +20,7 @@ import java.lang.reflect.Method;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.jms.StubTextMessage;
|
||||
@@ -50,10 +48,6 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public abstract class AbstractJmsAnnotationDrivenTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public abstract void sampleConfiguration();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.jms.annotation;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageListener;
|
||||
|
||||
import org.hamcrest.core.Is;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -29,6 +28,8 @@ import org.springframework.jms.config.SimpleJmsListenerEndpoint;
|
||||
import org.springframework.jms.listener.adapter.ListenerExecutionFailedException;
|
||||
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@@ -87,9 +88,9 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"annotation-driven-custom-handler-method-factory.xml", getClass());
|
||||
|
||||
thrown.expect(ListenerExecutionFailedException.class);
|
||||
thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
|
||||
testJmsHandlerMethodFactoryConfiguration(context);
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
testJmsHandlerMethodFactoryConfiguration(context))
|
||||
.withCauseInstanceOf(MethodArgumentNotValidException.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,15 +18,10 @@ package org.springframework.jms.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageListener;
|
||||
|
||||
import org.hamcrest.core.Is;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -50,6 +45,7 @@ import org.springframework.messaging.handler.annotation.support.MessageHandlerMe
|
||||
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -58,10 +54,6 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void sampleConfiguration() {
|
||||
@@ -140,9 +132,9 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class);
|
||||
|
||||
thrown.expect(ListenerExecutionFailedException.class);
|
||||
thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
|
||||
testJmsHandlerMethodFactoryConfiguration(context);
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
testJmsHandlerMethodFactoryConfiguration(context))
|
||||
.withCauseInstanceOf(MethodArgumentNotValidException.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,9 +178,10 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void unknownFactory() {
|
||||
thrown.expect(BeanCreationException.class);
|
||||
thrown.expectMessage("customFactory"); // not found
|
||||
new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class);
|
||||
// not found
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
|
||||
new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class))
|
||||
.withMessageContaining("customFactory");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,9 +22,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
@@ -47,7 +45,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -57,10 +55,6 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void simpleMessageListener() throws Exception {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
@@ -171,10 +165,10 @@ public class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void invalidProxy() {
|
||||
thrown.expect(BeanCreationException.class);
|
||||
thrown.expectCause(is(instanceOf(IllegalStateException.class)));
|
||||
thrown.expectMessage("handleIt2");
|
||||
new AnnotationConfigApplicationContext(Config.class, ProxyConfig.class, InvalidProxyTestBean.class);
|
||||
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
|
||||
new AnnotationConfigApplicationContext(Config.class, ProxyConfig.class, InvalidProxyTestBean.class))
|
||||
.withCauseInstanceOf(IllegalStateException.class)
|
||||
.withMessageContaining("handleIt2");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,9 +21,7 @@ import javax.jms.MessageListener;
|
||||
import javax.jms.Session;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.jms.StubConnectionFactory;
|
||||
@@ -42,6 +40,7 @@ import org.springframework.jms.support.destination.DynamicDestinationResolver;
|
||||
import org.springframework.util.backoff.BackOff;
|
||||
import org.springframework.util.backoff.FixedBackOff;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -59,10 +58,6 @@ public class JmsListenerContainerFactoryTests {
|
||||
private final TransactionManager transactionManager = mock(TransactionManager.class);
|
||||
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void createSimpleContainer() {
|
||||
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
|
||||
@@ -130,8 +125,8 @@ public class JmsListenerContainerFactoryTests {
|
||||
|
||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||
endpoint.setMessageListener(new MessageListenerAdapter());
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
factory.createListenerContainer(endpoint);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
factory.createListenerContainer(endpoint));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,12 +17,12 @@
|
||||
package org.springframework.jms.config;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -37,10 +37,6 @@ public class JmsListenerEndpointRegistrarTests {
|
||||
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
||||
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.registrar.setEndpointRegistry(this.registry);
|
||||
@@ -50,14 +46,14 @@ public class JmsListenerEndpointRegistrarTests {
|
||||
|
||||
@Test
|
||||
public void registerNullEndpoint() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.registrar.registerEndpoint(null, this.containerFactory);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.registrar.registerEndpoint(null, this.containerFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerNullEndpointId() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.registrar.registerEndpoint(new SimpleJmsListenerEndpoint(), this.containerFactory);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.registrar.registerEndpoint(new SimpleJmsListenerEndpoint(), this.containerFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,8 +61,8 @@ public class JmsListenerEndpointRegistrarTests {
|
||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||
endpoint.setId("");
|
||||
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.registrar.registerEndpoint(endpoint, this.containerFactory);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.registrar.registerEndpoint(endpoint, this.containerFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,9 +83,9 @@ public class JmsListenerEndpointRegistrarTests {
|
||||
endpoint.setId("some id");
|
||||
this.registrar.registerEndpoint(endpoint, null);
|
||||
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(endpoint.toString());
|
||||
this.registrar.afterPropertiesSet();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.registrar.afterPropertiesSet())
|
||||
.withMessageContaining(endpoint.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package org.springframework.jms.config;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -30,34 +31,30 @@ public class JmsListenerEndpointRegistryTests {
|
||||
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
||||
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void createWithNullEndpoint() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
registry.registerListenerContainer(null, containerFactory);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
registry.registerListenerContainer(null, containerFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithNullEndpointId() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
registry.registerListenerContainer(new SimpleJmsListenerEndpoint(), containerFactory);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
registry.registerListenerContainer(new SimpleJmsListenerEndpoint(), containerFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithNullContainerFactory() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
registry.registerListenerContainer(createEndpoint("foo", "myDestination"), null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
registry.registerListenerContainer(createEndpoint("foo", "myDestination"), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithDuplicateEndpointId() {
|
||||
registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory);
|
||||
|
||||
thrown.expect(IllegalStateException.class);
|
||||
registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,7 @@ package org.springframework.jms.config;
|
||||
|
||||
import javax.jms.MessageListener;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
@@ -30,6 +28,8 @@ import org.springframework.jms.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.jms.listener.endpoint.JmsActivationSpecConfig;
|
||||
import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -38,10 +38,6 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public class JmsListenerEndpointTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void setupJmsMessageContainerFullConfig() {
|
||||
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
||||
@@ -99,8 +95,8 @@ public class JmsListenerEndpointTests {
|
||||
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||
|
||||
thrown.expect(IllegalStateException.class);
|
||||
endpoint.setupListenerContainer(container);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
endpoint.setupListenerContainer(container));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,8 +105,8 @@ public class JmsListenerEndpointTests {
|
||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||
endpoint.setMessageListener(new MessageListenerAdapter());
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
endpoint.setupListenerContainer(container);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
endpoint.setupListenerContainer(container));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,11 +29,9 @@ import javax.jms.QueueSender;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
@@ -64,13 +62,9 @@ import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.mock;
|
||||
import static org.mockito.BDDMockito.verify;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -87,9 +81,6 @@ public class MethodJmsListenerEndpointTests {
|
||||
@Rule
|
||||
public final TestName name = new TestName();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -103,8 +94,8 @@ public class MethodJmsListenerEndpointTests {
|
||||
endpoint.setBean(this);
|
||||
endpoint.setMethod(getTestMethod());
|
||||
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
endpoint.createMessageListener(this.container);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
endpoint.createMessageListener(this.container));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -387,17 +378,17 @@ public class MethodJmsListenerEndpointTests {
|
||||
Session session = mock(Session.class);
|
||||
given(session.createTextMessage("content")).willReturn(reply);
|
||||
|
||||
this.thrown.expect(ReplyFailureException.class);
|
||||
this.thrown.expectCause(Matchers.isA(InvalidDestinationException.class));
|
||||
listener.onMessage(createSimpleJmsTextMessage("content"), session);
|
||||
assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() ->
|
||||
listener.onMessage(createSimpleJmsTextMessage("content"), session))
|
||||
.withCauseInstanceOf(InvalidDestinationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidSendTo() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("firstDestination");
|
||||
this.thrown.expectMessage("secondDestination");
|
||||
createDefaultInstance(String.class);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
createDefaultInstance(String.class))
|
||||
.withMessageContaining("firstDestination")
|
||||
.withMessageContaining("secondDestination");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -424,8 +415,9 @@ public class MethodJmsListenerEndpointTests {
|
||||
MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
|
||||
Session session = mock(Session.class);
|
||||
|
||||
this.thrown.expect(ListenerExecutionFailedException.class);
|
||||
listener.onMessage(createSimpleJmsTextMessage("invalid value"), session); // test is an invalid value
|
||||
// test is an invalid value
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
listener.onMessage(createSimpleJmsTextMessage("invalid value"), session));
|
||||
|
||||
}
|
||||
|
||||
@@ -436,10 +428,11 @@ public class MethodJmsListenerEndpointTests {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
|
||||
Session session = mock(Session.class);
|
||||
|
||||
this.thrown.expect(ListenerExecutionFailedException.class);
|
||||
this.thrown.expectCause(Matchers.isA(MessageConversionException.class));
|
||||
this.thrown.expectMessage(getDefaultListenerMethod(Integer.class).toGenericString()); // ref to method
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is not a valid integer
|
||||
// test is not a valid integer
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session))
|
||||
.withCauseInstanceOf(MessageConversionException.class)
|
||||
.withMessageContaining(getDefaultListenerMethod(Integer.class).toGenericString()); // ref to method
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -447,9 +440,10 @@ public class MethodJmsListenerEndpointTests {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);
|
||||
Session session = mock(Session.class);
|
||||
|
||||
this.thrown.expect(ListenerExecutionFailedException.class);
|
||||
this.thrown.expectCause(Matchers.isA(MessageConversionException.class));
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session); // Message<String> as Message<Integer>
|
||||
// Message<String> as Message<Integer>
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session))
|
||||
.withCauseInstanceOf(MessageConversionException.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,11 +26,8 @@ import javax.jms.MessageNotWriteableException;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.Captor;
|
||||
@@ -51,7 +48,9 @@ import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.converter.GenericMessageConverter;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
@@ -61,9 +60,6 @@ import static org.mockito.BDDMockito.*;
|
||||
*/
|
||||
public class JmsMessagingTemplateTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<MessageCreator> messageCreator;
|
||||
|
||||
@@ -169,8 +165,8 @@ public class JmsMessagingTemplateTests {
|
||||
public void sendNoDefaultSet() {
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.send(message);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.messagingTemplate.send(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,8 +223,8 @@ public class JmsMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void convertAndSendNoDefaultSet() throws JMSException {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.convertAndSend("my Payload");
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.messagingTemplate.convertAndSend("my Payload"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,9 +240,9 @@ public class JmsMessagingTemplateTests {
|
||||
this.messagingTemplate.convertAndSend("myQueue", "msg to convert");
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.thrown.expectMessage(new StringContains("Test exception"));
|
||||
this.messageCreator.getValue().createMessage(mock(Session.class));
|
||||
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() ->
|
||||
this.messageCreator.getValue().createMessage(mock(Session.class)))
|
||||
.withMessageContaining("Test exception");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -316,8 +312,8 @@ public class JmsMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void receiveNoDefaultSet() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.receive();
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
this.messagingTemplate::receive);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -381,8 +377,8 @@ public class JmsMessagingTemplateTests {
|
||||
javax.jms.Message jmsMessage = createJmsTextMessage("Hello");
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.receiveAndConvert("myQueue", Writer.class);
|
||||
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.receiveAndConvert("myQueue", Writer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -444,8 +440,8 @@ public class JmsMessagingTemplateTests {
|
||||
public void sendAndReceiveNoDefaultSet() {
|
||||
Message<String> message = createTextMessage();
|
||||
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.sendAndReceive(message);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.messagingTemplate.sendAndReceive(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -494,8 +490,8 @@ public class JmsMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void convertSendAndReceiveNoDefaultSet() throws JMSException {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.messagingTemplate.convertSendAndReceive("my Payload", String.class);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.messagingTemplate.convertSendAndReceive("my Payload", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -507,8 +503,8 @@ public class JmsMessagingTemplateTests {
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.send("myQueue", message);
|
||||
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.send("myQueue", message));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -520,16 +516,16 @@ public class JmsMessagingTemplateTests {
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
given(this.jmsTemplate.receive("myQueue")).willReturn(message);
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.receive("myQueue");
|
||||
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.receive("myQueue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertMessageNotReadableException() throws JMSException {
|
||||
willThrow(MessageNotReadableException.class).given(this.jmsTemplate).receive("myQueue");
|
||||
|
||||
this.thrown.expect(MessagingException.class);
|
||||
this.messagingTemplate.receive("myQueue");
|
||||
assertThatExceptionOfType(MessagingException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.receive("myQueue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -537,8 +533,8 @@ public class JmsMessagingTemplateTests {
|
||||
Destination destination = new Destination() {};
|
||||
willThrow(DestinationResolutionException.class).given(this.jmsTemplate).send(eq(destination), any());
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.send(destination, createTextMessage());
|
||||
assertThatExceptionOfType(org.springframework.messaging.core.DestinationResolutionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.send(destination, createTextMessage()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -546,8 +542,8 @@ public class JmsMessagingTemplateTests {
|
||||
Destination destination = new Destination() {};
|
||||
willThrow(DestinationResolutionException.class).given(this.jmsTemplate).receive(destination);
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.receive(destination);
|
||||
assertThatExceptionOfType(org.springframework.messaging.core.DestinationResolutionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.receive(destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -558,8 +554,8 @@ public class JmsMessagingTemplateTests {
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.send("myQueue", message);
|
||||
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.send("myQueue", message));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -570,16 +566,16 @@ public class JmsMessagingTemplateTests {
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
|
||||
this.messagingTemplate.send("myQueue", message);
|
||||
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.send("myQueue", message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertInvalidDestinationExceptionOnSendAndReceiveWithName() {
|
||||
willThrow(InvalidDestinationException.class).given(this.jmsTemplate).sendAndReceive(eq("unknownQueue"), any());
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.sendAndReceive("unknownQueue", createTextMessage());
|
||||
assertThatExceptionOfType(org.springframework.messaging.core.DestinationResolutionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.sendAndReceive("unknownQueue", createTextMessage()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -587,8 +583,8 @@ public class JmsMessagingTemplateTests {
|
||||
Destination destination = new Destination() {};
|
||||
willThrow(InvalidDestinationException.class).given(this.jmsTemplate).sendAndReceive(eq(destination), any());
|
||||
|
||||
this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
|
||||
this.messagingTemplate.sendAndReceive(destination, createTextMessage());
|
||||
assertThatExceptionOfType(org.springframework.messaging.core.DestinationResolutionException.class).isThrownBy(() ->
|
||||
this.messagingTemplate.sendAndReceive(destination, createTextMessage()));
|
||||
}
|
||||
|
||||
private void invokeMessageCreator() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Mark Pollack
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,24 +20,19 @@ import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsResponseTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void destinationDoesNotUseDestinationResolver() throws JMSException {
|
||||
Destination destination = mock(Destination.class);
|
||||
@@ -59,26 +54,26 @@ public class JmsResponseTests {
|
||||
|
||||
@Test
|
||||
public void createWithNulResponse() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
JmsResponse.forQueue(null, "myQueue");
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
JmsResponse.forQueue(null, "myQueue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithNullQueueName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
JmsResponse.forQueue("foo", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
JmsResponse.forQueue("foo", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithNullTopicName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
JmsResponse.forTopic("foo", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
JmsResponse.forTopic("foo", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithNulDestination() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
JmsResponse.forDestination("foo", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
JmsResponse.forDestination("foo", null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,6 +38,7 @@ import org.springframework.jms.support.converter.MessageConversionException;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,9 +30,7 @@ import javax.jms.Topic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.jms.StubTextMessage;
|
||||
@@ -47,7 +45,9 @@ import org.springframework.messaging.handler.annotation.support.DefaultMessageHa
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
@@ -55,9 +55,6 @@ import static org.mockito.BDDMockito.*;
|
||||
*/
|
||||
public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private static final Destination sharedReplyDestination = mock(Destination.class);
|
||||
|
||||
private final DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
|
||||
@@ -149,9 +146,10 @@ public class MessagingMessageListenerAdapterTests {
|
||||
MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
|
||||
Message<?> message = listener.toMessagingMessage(jmsMessage);
|
||||
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Header failure");
|
||||
message.getHeaders(); // Triggers headers resolution
|
||||
// Triggers headers resolution
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
message::getHeaders)
|
||||
.withMessageContaining("Header failure");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package org.springframework.jms.listener.endpoint;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.jms.support.QosSettings;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -29,9 +28,6 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class JmsMessageEndpointManagerTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void isPubSubDomainWithQueue() {
|
||||
JmsMessageEndpointManager endpoint = new JmsMessageEndpointManager();
|
||||
@@ -79,25 +75,25 @@ public class JmsMessageEndpointManagerTests {
|
||||
@Test
|
||||
public void isPubSubDomainWithNoConfig() {
|
||||
JmsMessageEndpointManager endpoint = new JmsMessageEndpointManager();
|
||||
|
||||
this.thrown.expect(IllegalStateException.class); // far from ideal
|
||||
endpoint.isPubSubDomain();
|
||||
// far from ideal
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
endpoint::isPubSubDomain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReplyPubSubDomainWithNoConfig() {
|
||||
JmsMessageEndpointManager endpoint = new JmsMessageEndpointManager();
|
||||
|
||||
this.thrown.expect(IllegalStateException.class); // far from ideal
|
||||
endpoint.isReplyPubSubDomain();
|
||||
// far from ideal
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
endpoint::isReplyPubSubDomain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReplyQosSettingsWithNoConfig() {
|
||||
JmsMessageEndpointManager endpoint = new JmsMessageEndpointManager();
|
||||
|
||||
this.thrown.expect(IllegalStateException.class); // far from ideal
|
||||
endpoint.getReplyQosSettings();
|
||||
// far from ideal
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
endpoint::getReplyQosSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,9 +32,7 @@ import javax.jms.QueueSession;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.jms.support.converter.MessageConversionException;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
@@ -42,6 +40,7 @@ import org.springframework.remoting.RemoteTimeoutException;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
@@ -51,9 +50,6 @@ import static org.mockito.BDDMockito.*;
|
||||
*/
|
||||
public class JmsInvokerTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private QueueConnectionFactory mockConnectionFactory;
|
||||
|
||||
private QueueConnection mockConnection;
|
||||
@@ -101,10 +97,10 @@ public class JmsInvokerTests {
|
||||
pfb.afterPropertiesSet();
|
||||
ITestBean proxy = (ITestBean) pfb.getObject();
|
||||
|
||||
thrown.expect(RemoteTimeoutException.class);
|
||||
thrown.expectMessage("1500 ms");
|
||||
thrown.expectMessage("getAge");
|
||||
proxy.getAge();
|
||||
assertThatExceptionOfType(RemoteTimeoutException.class).isThrownBy(() ->
|
||||
proxy.getAge())
|
||||
.withMessageContaining("1500 ms")
|
||||
.withMessageContaining("getAge");
|
||||
}
|
||||
|
||||
private void doTestJmsInvokerProxyFactoryBeanAndServiceExporter(boolean dynamicQueue) throws Throwable {
|
||||
@@ -146,21 +142,10 @@ public class JmsInvokerTests {
|
||||
assertEquals(50, proxy.getAge());
|
||||
proxy.setStringArray(new String[] {"str1", "str2"});
|
||||
assertTrue(Arrays.equals(new String[] {"str1", "str2"}, proxy.getStringArray()));
|
||||
|
||||
try {
|
||||
proxy.exceptional(new IllegalStateException());
|
||||
fail("Should have thrown IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
proxy.exceptional(new IllegalAccessException());
|
||||
fail("Should have thrown IllegalAccessException");
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
// expected
|
||||
}
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
proxy.exceptional(new IllegalStateException()));
|
||||
assertThatExceptionOfType(IllegalAccessException.class).isThrownBy(() ->
|
||||
proxy.exceptional(new IllegalAccessException()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,6 +36,7 @@ import org.springframework.jms.support.converter.MessageConversionException;
|
||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,15 +29,15 @@ import javax.jms.TextMessage;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
@@ -47,9 +47,6 @@ import static org.mockito.BDDMockito.*;
|
||||
*/
|
||||
public class MappingJackson2MessageConverterTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private MappingJackson2MessageConverter converter;
|
||||
|
||||
private Session sessionMock;
|
||||
@@ -206,8 +203,8 @@ public class MappingJackson2MessageConverterTests {
|
||||
Method method = this.getClass().getDeclaredMethod("invalid");
|
||||
MethodParameter returnType = new MethodParameter(method, -1);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
testToTextMessageWithReturnType(returnType);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
testToTextMessageWithReturnType(returnType));
|
||||
}
|
||||
|
||||
private void testToTextMessageWithReturnType(MethodParameter returnType) throws JMSException, NoSuchMethodException {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,14 +22,13 @@ import javax.jms.ObjectMessage;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.jms.StubTextMessage;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
@@ -40,14 +39,11 @@ public class MessagingMessageConverterTests {
|
||||
|
||||
private final MessagingMessageConverter converter = new MessagingMessageConverter();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Test
|
||||
public void onlyHandlesMessage() throws JMSException {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.converter.toMessage(new Object(), mock(Session.class));
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.converter.toMessage(new Object(), mock(Session.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import javax.jms.ConnectionFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
|
||||
Reference in New Issue
Block a user