Migrate to Mockito.mock(T...) where feasible
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.jms.annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import jakarta.jms.JMSException;
|
||||
import jakarta.jms.Session;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -172,7 +171,7 @@ abstract class AbstractJmsAnnotationDrivenTests {
|
||||
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
||||
endpoint.setupListenerContainer(container);
|
||||
MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
|
||||
listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
|
||||
listener.onMessage(new StubTextMessage("failValidation"), mock());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -204,7 +204,7 @@ class JmsListenerAnnotationBeanPostProcessorTests {
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
return mock(PlatformTransactionManager.class);
|
||||
return mock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class JmsListenerContainerFactoryIntegrationTests {
|
||||
DefaultMessageListenerContainer messageListenerContainer = containerFactory.createListenerContainer(endpoint);
|
||||
Object listener = messageListenerContainer.getMessageListener();
|
||||
if (listener instanceof SessionAwareMessageListener) {
|
||||
((SessionAwareMessageListener<Message>) listener).onMessage(message, mock(Session.class));
|
||||
((SessionAwareMessageListener<Message>) listener).onMessage(message, mock());
|
||||
}
|
||||
else {
|
||||
((MessageListener) listener).onMessage(message);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class JmsListenerContainerFactoryTests {
|
||||
|
||||
private final MessageConverter messageConverter = new SimpleMessageConverter();
|
||||
|
||||
private final TransactionManager transactionManager = mock(TransactionManager.class);
|
||||
private final TransactionManager transactionManager = mock();
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -100,7 +100,7 @@ public class JmsListenerEndpointTests {
|
||||
|
||||
@Test
|
||||
public void setupMessageContainerUnsupportedContainer() {
|
||||
MessageListenerContainer container = mock(MessageListenerContainer.class);
|
||||
MessageListenerContainer container = mock();
|
||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||
endpoint.setMessageListener(new MessageListenerAdapter());
|
||||
|
||||
|
||||
@@ -181,21 +181,21 @@ public class JmsNamespaceHandlerTests {
|
||||
assertThat(testBean2.getName()).isNull();
|
||||
assertThat(testBean3.message).isNull();
|
||||
|
||||
TextMessage message1 = mock(TextMessage.class);
|
||||
TextMessage message1 = mock();
|
||||
given(message1.getText()).willReturn("Test1");
|
||||
|
||||
MessageListener listener1 = getListener("listener1");
|
||||
listener1.onMessage(message1);
|
||||
assertThat(testBean1.getName()).isEqualTo("Test1");
|
||||
|
||||
TextMessage message2 = mock(TextMessage.class);
|
||||
TextMessage message2 = mock();
|
||||
given(message2.getText()).willReturn("Test2");
|
||||
|
||||
MessageListener listener2 = getListener("listener2");
|
||||
listener2.onMessage(message2);
|
||||
assertThat(testBean2.getName()).isEqualTo("Test2");
|
||||
|
||||
TextMessage message3 = mock(TextMessage.class);
|
||||
TextMessage message3 = mock();
|
||||
|
||||
MessageListener listener3 = getListener(DefaultMessageListenerContainer.class.getName() + "#0");
|
||||
listener3.onMessage(message3);
|
||||
|
||||
@@ -113,8 +113,8 @@ class MethodJmsListenerEndpointTests {
|
||||
|
||||
@Test
|
||||
void setExtraCollaborators() {
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
DestinationResolver destinationResolver = mock(DestinationResolver.class);
|
||||
MessageConverter messageConverter = mock();
|
||||
DestinationResolver destinationResolver = mock();
|
||||
this.container.setMessageConverter(messageConverter);
|
||||
this.container.setDestinationResolver(destinationResolver);
|
||||
|
||||
@@ -129,7 +129,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveMessageAndSession() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(jakarta.jms.Message.class, Session.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session);
|
||||
assertDefaultListenerMethodInvocation();
|
||||
}
|
||||
@@ -138,7 +138,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveGenericMessage() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session);
|
||||
assertDefaultListenerMethodInvocation();
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveHeaderAndPayload() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
StubTextMessage message = createSimpleJmsTextMessage("my payload");
|
||||
message.setIntProperty("myCounter", 55);
|
||||
listener.onMessage(message, session);
|
||||
@@ -158,7 +158,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveCustomHeaderNameAndPayload() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
StubTextMessage message = createSimpleJmsTextMessage("my payload");
|
||||
message.setIntProperty("myCounter", 24);
|
||||
listener.onMessage(message, session);
|
||||
@@ -169,7 +169,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveCustomHeaderNameAndPayloadWithHeaderNameSet() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
StubTextMessage message = createSimpleJmsTextMessage("my payload");
|
||||
message.setIntProperty("myCounter", 24);
|
||||
listener.onMessage(message, session);
|
||||
@@ -180,7 +180,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveHeaders() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, Map.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
StubTextMessage message = createSimpleJmsTextMessage("my payload");
|
||||
message.setIntProperty("customInt", 1234);
|
||||
message.setJMSMessageID("abcd-1234");
|
||||
@@ -192,7 +192,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveMessageHeaders() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(MessageHeaders.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
StubTextMessage message = createSimpleJmsTextMessage("my payload");
|
||||
message.setLongProperty("customLong", 4567L);
|
||||
message.setJMSType("myMessageType");
|
||||
@@ -204,7 +204,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveJmsMessageHeaderAccessor() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(JmsMessageHeaderAccessor.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
StubTextMessage message = createSimpleJmsTextMessage("my payload");
|
||||
message.setBooleanProperty("customBoolean", true);
|
||||
message.setJMSPriority(9);
|
||||
@@ -218,8 +218,8 @@ class MethodJmsListenerEndpointTests {
|
||||
MyBean myBean = new MyBean();
|
||||
myBean.name = "myBean name";
|
||||
|
||||
Session session = mock(Session.class);
|
||||
ObjectMessage message = mock(ObjectMessage.class);
|
||||
Session session = mock();
|
||||
ObjectMessage message = mock();
|
||||
given(message.getObject()).willReturn(myBean);
|
||||
|
||||
listener.onMessage(message, session);
|
||||
@@ -230,7 +230,7 @@ class MethodJmsListenerEndpointTests {
|
||||
void resolveConvertedPayload() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
listener.onMessage(createSimpleJmsTextMessage("33"), session);
|
||||
assertDefaultListenerMethodInvocation();
|
||||
@@ -243,9 +243,9 @@ class MethodJmsListenerEndpointTests {
|
||||
String correlationId = "link-1234";
|
||||
Destination replyDestination = new Destination() {};
|
||||
|
||||
TextMessage reply = mock(TextMessage.class);
|
||||
QueueSender queueSender = mock(QueueSender.class);
|
||||
Session session = mock(Session.class);
|
||||
TextMessage reply = mock();
|
||||
QueueSender queueSender = mock();
|
||||
Session session = mock();
|
||||
given(session.createTextMessage(body)).willReturn(reply);
|
||||
given(session.createProducer(replyDestination)).willReturn(queueSender);
|
||||
|
||||
@@ -346,10 +346,10 @@ class MethodJmsListenerEndpointTests {
|
||||
String correlationId = "link-1234";
|
||||
Destination replyDestination = new Destination() {};
|
||||
|
||||
DestinationResolver destinationResolver = mock(DestinationResolver.class);
|
||||
TextMessage reply = mock(TextMessage.class);
|
||||
QueueSender queueSender = mock(QueueSender.class);
|
||||
Session session = mock(Session.class);
|
||||
DestinationResolver destinationResolver = mock();
|
||||
TextMessage reply = mock();
|
||||
QueueSender queueSender = mock();
|
||||
Session session = mock();
|
||||
|
||||
given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
|
||||
.willReturn(replyDestination);
|
||||
@@ -377,8 +377,8 @@ class MethodJmsListenerEndpointTests {
|
||||
void emptySendTo() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
|
||||
|
||||
TextMessage reply = mock(TextMessage.class);
|
||||
Session session = mock(Session.class);
|
||||
TextMessage reply = mock();
|
||||
Session session = mock();
|
||||
given(session.createTextMessage("content")).willReturn(reply);
|
||||
|
||||
assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() ->
|
||||
@@ -404,7 +404,7 @@ class MethodJmsListenerEndpointTests {
|
||||
|
||||
Method method = getListenerMethod(methodName, String.class);
|
||||
MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
listener.onMessage(createSimpleJmsTextMessage("test"), session); // test is a valid value
|
||||
assertListenerMethodInvocation(this.sample, methodName);
|
||||
}
|
||||
@@ -416,7 +416,7 @@ class MethodJmsListenerEndpointTests {
|
||||
|
||||
Method method = getListenerMethod("validatePayload", String.class);
|
||||
MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
// test is an invalid value
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
@@ -429,7 +429,7 @@ class MethodJmsListenerEndpointTests {
|
||||
@Test
|
||||
void invalidPayloadType() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
// test is not a valid integer
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
@@ -441,7 +441,7 @@ class MethodJmsListenerEndpointTests {
|
||||
@Test
|
||||
void invalidMessagePayloadType() throws JMSException {
|
||||
MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
// Message<String> as Message<Integer>
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
|
||||
@@ -59,9 +59,9 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testTransactionCommit() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
final Session session = mock(Session.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
final Session session = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
|
||||
@@ -82,9 +82,9 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testTransactionRollback() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
final Session session = mock(Session.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
final Session session = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
|
||||
@@ -105,9 +105,9 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testParticipatingTransactionWithCommit() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
final Session session = mock(Session.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
final Session session = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
|
||||
@@ -138,9 +138,9 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testParticipatingTransactionWithRollbackOnly() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
final Session session = mock(Session.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
final Session session = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
|
||||
@@ -173,10 +173,10 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testSuspendedTransaction() throws JMSException {
|
||||
final ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
final Session session = mock(Session.class);
|
||||
final Session session2 = mock(Session.class);
|
||||
final ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
final Session session = mock();
|
||||
final Session session2 = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
|
||||
@@ -214,10 +214,10 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testTransactionSuspension() throws JMSException {
|
||||
final ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
final Session session = mock(Session.class);
|
||||
final Session session2 = mock(Session.class);
|
||||
final ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
final Session session = mock();
|
||||
final Session session2 = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session, session2);
|
||||
@@ -257,11 +257,11 @@ public class JmsTransactionManagerTests {
|
||||
public void testTransactionCommitWithMessageProducer() throws JMSException {
|
||||
Destination dest = new StubQueue();
|
||||
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
Session session = mock(Session.class);
|
||||
MessageProducer producer = mock(MessageProducer.class);
|
||||
final Message message = mock(Message.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
Session session = mock();
|
||||
MessageProducer producer = mock();
|
||||
final Message message = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
|
||||
@@ -283,9 +283,9 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testLazyTransactionalSession() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
final Session session = mock(Session.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
final Session session = mock();
|
||||
|
||||
JmsTransactionManager tm = new JmsTransactionManager(cf);
|
||||
tm.setLazyResourceRetrieval(true);
|
||||
@@ -308,7 +308,7 @@ public class JmsTransactionManagerTests {
|
||||
|
||||
@Test
|
||||
public void testLazyWithoutSessionAccess() {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
ConnectionFactory cf = mock();
|
||||
|
||||
JmsTransactionManager tm = new JmsTransactionManager(cf);
|
||||
tm.setLazyResourceRetrieval(true);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnection() throws JMSException {
|
||||
Connection con = mock(Connection.class);
|
||||
Connection con = mock();
|
||||
|
||||
SingleConnectionFactory scf = new SingleConnectionFactory(con);
|
||||
Connection con1 = scf.createConnection();
|
||||
@@ -65,7 +65,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithQueueConnection() throws JMSException {
|
||||
Connection con = mock(QueueConnection.class);
|
||||
QueueConnection con = mock();
|
||||
|
||||
SingleConnectionFactory scf = new SingleConnectionFactory(con);
|
||||
QueueConnection con1 = scf.createQueueConnection();
|
||||
@@ -86,7 +86,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithTopicConnection() throws JMSException {
|
||||
Connection con = mock(TopicConnection.class);
|
||||
TopicConnection con = mock();
|
||||
|
||||
SingleConnectionFactory scf = new SingleConnectionFactory(con);
|
||||
TopicConnection con1 = scf.createTopicConnection();
|
||||
@@ -107,8 +107,8 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionFactory() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
@@ -129,8 +129,8 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException {
|
||||
QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
|
||||
QueueConnection con = mock(QueueConnection.class);
|
||||
QueueConnectionFactory cf = mock();
|
||||
QueueConnection con = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
@@ -151,8 +151,8 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
|
||||
QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
|
||||
QueueConnection con = mock(QueueConnection.class);
|
||||
QueueConnectionFactory cf = mock();
|
||||
QueueConnection con = mock();
|
||||
|
||||
given(cf.createQueueConnection()).willReturn(con);
|
||||
|
||||
@@ -173,8 +173,8 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithTopicConnectionFactoryAndJms11Usage() throws JMSException {
|
||||
TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
|
||||
TopicConnection con = mock(TopicConnection.class);
|
||||
TopicConnectionFactory cf = mock();
|
||||
TopicConnection con = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
@@ -195,8 +195,8 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
|
||||
TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
|
||||
TopicConnection con = mock(TopicConnection.class);
|
||||
TopicConnectionFactory cf = mock();
|
||||
TopicConnection con = mock();
|
||||
|
||||
given(cf.createTopicConnection()).willReturn(con);
|
||||
|
||||
@@ -217,7 +217,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionAggregatedStartStop() throws JMSException {
|
||||
Connection con = mock(Connection.class);
|
||||
Connection con = mock();
|
||||
|
||||
SingleConnectionFactory scf = new SingleConnectionFactory(con);
|
||||
Connection con1 = scf.createConnection();
|
||||
@@ -249,8 +249,8 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionFactoryAndClientId() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
|
||||
@@ -272,8 +272,8 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionFactoryAndExceptionListener() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
|
||||
ExceptionListener listener = new ChainedExceptionListener();
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
@@ -300,7 +300,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionFactoryAndReconnectOnException() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
ConnectionFactory cf = mock();
|
||||
TestConnection con = new TestConnection();
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
@@ -320,7 +320,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionFactoryAndExceptionListenerAndReconnectOnException() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
ConnectionFactory cf = mock();
|
||||
TestConnection con = new TestConnection();
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
@@ -343,7 +343,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionFactoryAndLocalExceptionListenerWithCleanup() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
ConnectionFactory cf = mock();
|
||||
TestConnection con = new TestConnection();
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
@@ -381,7 +381,7 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithConnectionFactoryAndLocalExceptionListenerWithReconnect() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
ConnectionFactory cf = mock();
|
||||
TestConnection con = new TestConnection();
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
|
||||
@@ -415,10 +415,10 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testCachingConnectionFactory() throws JMSException {
|
||||
ConnectionFactory cf = mock(ConnectionFactory.class);
|
||||
Connection con = mock(Connection.class);
|
||||
Session txSession = mock(Session.class);
|
||||
Session nonTxSession = mock(Session.class);
|
||||
ConnectionFactory cf = mock();
|
||||
Connection con = mock();
|
||||
Session txSession = mock();
|
||||
Session nonTxSession = mock();
|
||||
|
||||
given(cf.createConnection()).willReturn(con);
|
||||
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
|
||||
@@ -455,10 +455,10 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
|
||||
QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
|
||||
QueueConnection con = mock(QueueConnection.class);
|
||||
QueueSession txSession = mock(QueueSession.class);
|
||||
QueueSession nonTxSession = mock(QueueSession.class);
|
||||
QueueConnectionFactory cf = mock();
|
||||
QueueConnection con = mock();
|
||||
QueueSession txSession = mock();
|
||||
QueueSession nonTxSession = mock();
|
||||
|
||||
given(cf.createQueueConnection()).willReturn(con);
|
||||
given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
|
||||
@@ -495,10 +495,10 @@ public class SingleConnectionFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
|
||||
TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
|
||||
TopicConnection con = mock(TopicConnection.class);
|
||||
TopicSession txSession = mock(TopicSession.class);
|
||||
TopicSession nonTxSession = mock(TopicSession.class);
|
||||
TopicConnectionFactory cf = mock();
|
||||
TopicConnection con = mock();
|
||||
TopicSession txSession = mock();
|
||||
TopicSession nonTxSession = mock();
|
||||
|
||||
given(cf.createTopicConnection()).willReturn(con);
|
||||
given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class JmsMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void payloadConverterIsConsistentConstructor() {
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
MessageConverter messageConverter = mock();
|
||||
given(this.jmsTemplate.getMessageConverter()).willReturn(messageConverter);
|
||||
JmsMessagingTemplate messagingTemplate = new JmsMessagingTemplate(this.jmsTemplate);
|
||||
messagingTemplate.afterPropertiesSet();
|
||||
@@ -98,7 +98,7 @@ public class JmsMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void payloadConverterIsConsistentSetter() {
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
MessageConverter messageConverter = mock();
|
||||
given(this.jmsTemplate.getMessageConverter()).willReturn(messageConverter);
|
||||
JmsMessagingTemplate messagingTemplate = new JmsMessagingTemplate();
|
||||
messagingTemplate.setJmsTemplate(this.jmsTemplate);
|
||||
@@ -108,7 +108,7 @@ public class JmsMessagingTemplateTests {
|
||||
|
||||
@Test
|
||||
public void customConverterAlwaysTakesPrecedence() {
|
||||
MessageConverter customMessageConverter = mock(MessageConverter.class);
|
||||
MessageConverter customMessageConverter = mock();
|
||||
JmsMessagingTemplate messagingTemplate = new JmsMessagingTemplate();
|
||||
messagingTemplate.setJmsMessageConverter(
|
||||
new MessagingMessageConverter(customMessageConverter));
|
||||
@@ -246,7 +246,7 @@ public class JmsMessagingTemplateTests {
|
||||
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
|
||||
|
||||
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() ->
|
||||
this.messageCreator.getValue().createMessage(mock(Session.class)))
|
||||
this.messageCreator.getValue().createMessage(mock()))
|
||||
.withMessageContaining("Test exception");
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ public class JmsMessagingTemplateTests {
|
||||
@Test
|
||||
public void convertMessageConversionExceptionOnSend() throws JMSException {
|
||||
Message<String> message = createTextMessage();
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
MessageConverter messageConverter = mock();
|
||||
willThrow(org.springframework.jms.support.converter.MessageConversionException.class)
|
||||
.given(messageConverter).toMessage(eq(message), any());
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
@@ -515,7 +515,7 @@ public class JmsMessagingTemplateTests {
|
||||
@Test
|
||||
public void convertMessageConversionExceptionOnReceive() throws JMSException {
|
||||
jakarta.jms.Message message = createJmsTextMessage();
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
MessageConverter messageConverter = mock();
|
||||
willThrow(org.springframework.jms.support.converter.MessageConversionException.class)
|
||||
.given(messageConverter).fromMessage(message);
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
@@ -554,7 +554,7 @@ public class JmsMessagingTemplateTests {
|
||||
@Test
|
||||
public void convertMessageFormatException() throws JMSException {
|
||||
Message<String> message = createTextMessage();
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
MessageConverter messageConverter = mock();
|
||||
willThrow(MessageFormatException.class).given(messageConverter).toMessage(eq(message), any());
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
@@ -566,7 +566,7 @@ public class JmsMessagingTemplateTests {
|
||||
@Test
|
||||
public void convertMessageNotWritableException() throws JMSException {
|
||||
Message<String> message = createTextMessage();
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
MessageConverter messageConverter = mock();
|
||||
willThrow(MessageNotWriteableException.class).given(messageConverter).toMessage(eq(message), any());
|
||||
this.messagingTemplate.setJmsMessageConverter(messageConverter);
|
||||
invokeMessageCreator();
|
||||
@@ -645,7 +645,7 @@ public class JmsMessagingTemplateTests {
|
||||
|
||||
|
||||
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
|
||||
Session mock = mock(Session.class);
|
||||
Session mock = mock();
|
||||
given(mock.createTextMessage(any())).willAnswer(
|
||||
(Answer<TextMessage>) invocation ->
|
||||
new StubTextMessage((String) invocation.getArguments()[0]));
|
||||
|
||||
@@ -25,7 +25,6 @@ import javax.naming.Context;
|
||||
import jakarta.jms.Connection;
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.DeliveryMode;
|
||||
import jakarta.jms.Destination;
|
||||
import jakarta.jms.JMSException;
|
||||
import jakarta.jms.Message;
|
||||
import jakarta.jms.MessageConsumer;
|
||||
@@ -78,15 +77,15 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
class JmsTemplateTests {
|
||||
|
||||
private Context jndiContext;
|
||||
private Context jndiContext = mock();
|
||||
|
||||
private ConnectionFactory connectionFactory;
|
||||
private ConnectionFactory connectionFactory = mock();
|
||||
|
||||
protected Connection connection;
|
||||
protected Connection connection = mock();
|
||||
|
||||
private Session session;
|
||||
private Session session = mock();
|
||||
|
||||
private Destination queue;
|
||||
private Queue queue = mock();
|
||||
|
||||
private QosSettings qosSettings = new QosSettings(DeliveryMode.PERSISTENT, 9, 10000);
|
||||
|
||||
@@ -96,12 +95,6 @@ class JmsTemplateTests {
|
||||
*/
|
||||
@BeforeEach
|
||||
void setupMocks() throws Exception {
|
||||
this.jndiContext = mock(Context.class);
|
||||
this.connectionFactory = mock(ConnectionFactory.class);
|
||||
this.connection = mock(Connection.class);
|
||||
this.session = mock(Session.class);
|
||||
this.queue = mock(Queue.class);
|
||||
|
||||
given(this.connectionFactory.createConnection()).willReturn(this.connection);
|
||||
given(this.connection.createSession(useTransactedTemplate(), Session.AUTO_ACKNOWLEDGE)).willReturn(this.session);
|
||||
given(this.session.getTransacted()).willReturn(useTransactedSession());
|
||||
@@ -153,7 +146,7 @@ class JmsTemplateTests {
|
||||
JmsTemplate template = createTemplate();
|
||||
template.setConnectionFactory(this.connectionFactory);
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
given(this.session.createProducer(null)).willReturn(messageProducer);
|
||||
given(messageProducer.getPriority()).willReturn(4);
|
||||
|
||||
@@ -175,7 +168,7 @@ class JmsTemplateTests {
|
||||
template.setMessageIdEnabled(false);
|
||||
template.setMessageTimestampEnabled(false);
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
given(this.session.createProducer(null)).willReturn(messageProducer);
|
||||
given(messageProducer.getPriority()).willReturn(4);
|
||||
|
||||
@@ -354,8 +347,8 @@ class JmsTemplateTests {
|
||||
template.setMessageTimestampEnabled(false);
|
||||
}
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage textMessage = mock();
|
||||
|
||||
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
|
||||
given(this.session.createTextMessage("just testing")).willReturn(textMessage);
|
||||
@@ -404,8 +397,8 @@ class JmsTemplateTests {
|
||||
template.setMessageConverter(new SimpleMessageConverter());
|
||||
String s = "Hello world";
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage textMessage = mock();
|
||||
|
||||
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
|
||||
given(this.session.createTextMessage("Hello world")).willReturn(textMessage);
|
||||
@@ -529,7 +522,7 @@ class JmsTemplateTests {
|
||||
}
|
||||
template.setReceiveTimeout(timeout);
|
||||
|
||||
MessageConsumer messageConsumer = mock(MessageConsumer.class);
|
||||
MessageConsumer messageConsumer = mock();
|
||||
|
||||
String selectorString = "selector";
|
||||
given(this.session.createConsumer(this.queue,
|
||||
@@ -541,7 +534,7 @@ class JmsTemplateTests {
|
||||
: Session.AUTO_ACKNOWLEDGE);
|
||||
}
|
||||
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
TextMessage textMessage = mock();
|
||||
|
||||
if (testConverter) {
|
||||
given(textMessage.getText()).willReturn("Hello World!");
|
||||
@@ -650,20 +643,20 @@ class JmsTemplateTests {
|
||||
template.setReceiveTimeout(timeout);
|
||||
|
||||
Session localSession = getLocalSession();
|
||||
TemporaryQueue replyDestination = mock(TemporaryQueue.class);
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TemporaryQueue replyDestination = mock();
|
||||
MessageProducer messageProducer = mock();
|
||||
given(localSession.createProducer(this.queue)).willReturn(messageProducer);
|
||||
given(localSession.createTemporaryQueue()).willReturn(replyDestination);
|
||||
|
||||
MessageConsumer messageConsumer = mock(MessageConsumer.class);
|
||||
MessageConsumer messageConsumer = mock();
|
||||
given(localSession.createConsumer(replyDestination)).willReturn(messageConsumer);
|
||||
|
||||
|
||||
TextMessage request = mock(TextMessage.class);
|
||||
MessageCreator messageCreator = mock(MessageCreator.class);
|
||||
TextMessage request = mock();
|
||||
MessageCreator messageCreator = mock();
|
||||
given(messageCreator.createMessage(localSession)).willReturn(request);
|
||||
|
||||
TextMessage reply = mock(TextMessage.class);
|
||||
TextMessage reply = mock();
|
||||
if (timeout == JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT) {
|
||||
given(messageConsumer.receiveNoWait()).willReturn(reply);
|
||||
}
|
||||
@@ -766,8 +759,8 @@ class JmsTemplateTests {
|
||||
template.setMessageConverter(new SimpleMessageConverter());
|
||||
String s = "Hello world";
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage textMessage = mock();
|
||||
|
||||
reset(this.session);
|
||||
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
|
||||
|
||||
@@ -29,14 +29,13 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
class JmsTemplateTransactedTests extends JmsTemplateTests {
|
||||
|
||||
private Session localSession;
|
||||
private Session localSession = mock();
|
||||
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
void setupMocks() throws Exception {
|
||||
super.setupMocks();
|
||||
this.localSession = mock(Session.class);
|
||||
given(this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE)).willReturn(this.localSession);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class JmsGatewaySupportTests {
|
||||
|
||||
@Test
|
||||
void testJmsGatewaySupportWithConnectionFactory() throws Exception {
|
||||
ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory mockConnectionFactory = mock();
|
||||
final List<String> test = new ArrayList<>(1);
|
||||
JmsGatewaySupport gateway = new JmsGatewaySupport() {
|
||||
@Override
|
||||
|
||||
@@ -43,8 +43,8 @@ public class DefaultMessageListenerContainerTests {
|
||||
|
||||
@Test
|
||||
public void applyBackOff() {
|
||||
BackOff backOff = mock(BackOff.class);
|
||||
BackOffExecution execution = mock(BackOffExecution.class);
|
||||
BackOff backOff = mock();
|
||||
BackOffExecution execution = mock();
|
||||
given(execution.nextBackOff()).willReturn(BackOffExecution.STOP);
|
||||
given(backOff.start()).willReturn(execution);
|
||||
|
||||
@@ -62,8 +62,8 @@ public class DefaultMessageListenerContainerTests {
|
||||
|
||||
@Test
|
||||
public void applyBackOffRetry() {
|
||||
BackOff backOff = mock(BackOff.class);
|
||||
BackOffExecution execution = mock(BackOffExecution.class);
|
||||
BackOff backOff = mock();
|
||||
BackOffExecution execution = mock();
|
||||
given(execution.nextBackOff()).willReturn(50L, BackOffExecution.STOP);
|
||||
given(backOff.start()).willReturn(execution);
|
||||
|
||||
@@ -79,8 +79,8 @@ public class DefaultMessageListenerContainerTests {
|
||||
|
||||
@Test
|
||||
public void recoverResetBackOff() {
|
||||
BackOff backOff = mock(BackOff.class);
|
||||
BackOffExecution execution = mock(BackOffExecution.class);
|
||||
BackOff backOff = mock();
|
||||
BackOffExecution execution = mock();
|
||||
given(execution.nextBackOff()).willReturn(50L, 50L, 50L); // 3 attempts max
|
||||
given(backOff.start()).willReturn(execution);
|
||||
|
||||
@@ -125,7 +125,7 @@ public class DefaultMessageListenerContainerTests {
|
||||
|
||||
private ConnectionFactory createFailingContainerFactory() {
|
||||
try {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).will(invocation -> {
|
||||
throw new JMSException("Test exception");
|
||||
});
|
||||
@@ -138,7 +138,7 @@ public class DefaultMessageListenerContainerTests {
|
||||
|
||||
private ConnectionFactory createRecoverableContainerFactory(final int failingAttempts) {
|
||||
try {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).will(new Answer<Object>() {
|
||||
int currentAttempts = 0;
|
||||
@Override
|
||||
@@ -161,8 +161,8 @@ public class DefaultMessageListenerContainerTests {
|
||||
|
||||
private ConnectionFactory createSuccessfulConnectionFactory() {
|
||||
try {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).willReturn(mock(Connection.class));
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(mock());
|
||||
return connectionFactory;
|
||||
}
|
||||
catch (JMSException ex) {
|
||||
|
||||
@@ -94,19 +94,19 @@ public class SimpleMessageListenerContainerTests {
|
||||
|
||||
@Test
|
||||
public void testContextRefreshedEventDoesNotStartTheConnectionIfAutoStartIsSetToFalse() throws Exception {
|
||||
MessageConsumer messageConsumer = mock(MessageConsumer.class);
|
||||
Session session = mock(Session.class);
|
||||
MessageConsumer messageConsumer = mock();
|
||||
Session session = mock();
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
// and then the MessageConsumer gets created...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
this.container.setConnectionFactory(connectionFactory);
|
||||
@@ -125,20 +125,20 @@ public class SimpleMessageListenerContainerTests {
|
||||
|
||||
@Test
|
||||
public void testContextRefreshedEventStartsTheConnectionByDefault() throws Exception {
|
||||
MessageConsumer messageConsumer = mock(MessageConsumer.class);
|
||||
Session session = mock(Session.class);
|
||||
MessageConsumer messageConsumer = mock();
|
||||
Session session = mock();
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
// and then the MessageConsumer gets created...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
// and the connection is start()ed after the listener is registered...
|
||||
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
this.container.setConnectionFactory(connectionFactory);
|
||||
@@ -159,7 +159,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
public void testCorrectSessionExposedForSessionAwareMessageListenerInvocation() throws Exception {
|
||||
final SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
|
||||
|
||||
final Session session = mock(Session.class);
|
||||
final Session session = mock();
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
// and then the MessageConsumer gets created...
|
||||
@@ -168,13 +168,13 @@ public class SimpleMessageListenerContainerTests {
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
given(session.getAcknowledgeMode()).willReturn(Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
// and the connection is start()ed after the listener is registered...
|
||||
|
||||
final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
final ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
final Set<String> failure = new HashSet<>(1);
|
||||
@@ -194,7 +194,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
this.container.afterPropertiesSet();
|
||||
this.container.start();
|
||||
|
||||
final Message message = mock(Message.class);
|
||||
final Message message = mock();
|
||||
messageConsumer.sendMessage(message);
|
||||
|
||||
if (!failure.isEmpty()) {
|
||||
@@ -209,17 +209,17 @@ public class SimpleMessageListenerContainerTests {
|
||||
public void testTaskExecutorCorrectlyInvokedWhenSpecified() throws Exception {
|
||||
final SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
|
||||
|
||||
final Session session = mock(Session.class);
|
||||
final Session session = mock();
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
given(session.getAcknowledgeMode()).willReturn(Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
|
||||
final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
final ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
final TestMessageListener listener = new TestMessageListener();
|
||||
@@ -236,7 +236,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
this.container.afterPropertiesSet();
|
||||
this.container.start();
|
||||
|
||||
final Message message = mock(Message.class);
|
||||
final Message message = mock();
|
||||
messageConsumer.sendMessage(message);
|
||||
|
||||
assertThat(listener.executorInvoked).isTrue();
|
||||
@@ -250,7 +250,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
public void testRegisteredExceptionListenerIsInvokedOnException() throws Exception {
|
||||
final SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
// and then the MessageConsumer gets created...
|
||||
@@ -258,13 +258,13 @@ public class SimpleMessageListenerContainerTests {
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
// and the connection is start()ed after the listener is registered...
|
||||
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
final JMSException theException = new JMSException(EXCEPTION_MESSAGE);
|
||||
@@ -275,14 +275,14 @@ public class SimpleMessageListenerContainerTests {
|
||||
throw theException;
|
||||
});
|
||||
|
||||
ExceptionListener exceptionListener = mock(ExceptionListener.class);
|
||||
ExceptionListener exceptionListener = mock();
|
||||
|
||||
this.container.setExceptionListener(exceptionListener);
|
||||
this.container.afterPropertiesSet();
|
||||
this.container.start();
|
||||
|
||||
// manually trigger an Exception with the above bad MessageListener...
|
||||
final Message message = mock(Message.class);
|
||||
final Message message = mock();
|
||||
|
||||
// a Throwable from a MessageListener MUST simply be swallowed...
|
||||
messageConsumer.sendMessage(message);
|
||||
@@ -297,7 +297,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
public void testRegisteredErrorHandlerIsInvokedOnException() throws Exception {
|
||||
final SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
@@ -306,12 +306,12 @@ public class SimpleMessageListenerContainerTests {
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
final IllegalStateException theException = new IllegalStateException("intentional test failure");
|
||||
@@ -322,13 +322,13 @@ public class SimpleMessageListenerContainerTests {
|
||||
throw theException;
|
||||
});
|
||||
|
||||
ErrorHandler errorHandler = mock(ErrorHandler.class);
|
||||
ErrorHandler errorHandler = mock();
|
||||
this.container.setErrorHandler(errorHandler);
|
||||
this.container.afterPropertiesSet();
|
||||
this.container.start();
|
||||
|
||||
// manually trigger an Exception with the above bad MessageListener...
|
||||
Message message = mock(Message.class);
|
||||
Message message = mock();
|
||||
|
||||
// a Throwable from a MessageListener MUST simply be swallowed...
|
||||
messageConsumer.sendMessage(message);
|
||||
@@ -342,7 +342,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
public void testNoRollbackOccursIfSessionIsNotTransactedAndThatExceptionsDo_NOT_Propagate() throws Exception {
|
||||
final SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
// and then the MessageConsumer gets created...
|
||||
@@ -350,13 +350,13 @@ public class SimpleMessageListenerContainerTests {
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
// and the connection is start()ed after the listener is registered...
|
||||
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
this.container.setConnectionFactory(connectionFactory);
|
||||
@@ -368,7 +368,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
this.container.start();
|
||||
|
||||
// manually trigger an Exception with the above bad MessageListener...
|
||||
final Message message = mock(Message.class);
|
||||
final Message message = mock();
|
||||
|
||||
// a Throwable from a MessageListener MUST simply be swallowed...
|
||||
messageConsumer.sendMessage(message);
|
||||
@@ -383,7 +383,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
|
||||
final SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
// and then the MessageConsumer gets created...
|
||||
@@ -391,13 +391,13 @@ public class SimpleMessageListenerContainerTests {
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(true);
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
// and the connection is start()ed after the listener is registered...
|
||||
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
this.container.setConnectionFactory(connectionFactory);
|
||||
@@ -409,7 +409,7 @@ public class SimpleMessageListenerContainerTests {
|
||||
this.container.start();
|
||||
|
||||
// manually trigger an Exception with the above bad MessageListener...
|
||||
final Message message = mock(Message.class);
|
||||
final Message message = mock();
|
||||
|
||||
// a Throwable from a MessageListener MUST simply be swallowed...
|
||||
messageConsumer.sendMessage(message);
|
||||
@@ -422,20 +422,20 @@ public class SimpleMessageListenerContainerTests {
|
||||
|
||||
@Test
|
||||
public void testDestroyClosesConsumersSessionsAndConnectionInThatOrder() throws Exception {
|
||||
MessageConsumer messageConsumer = mock(MessageConsumer.class);
|
||||
Session session = mock(Session.class);
|
||||
MessageConsumer messageConsumer = mock();
|
||||
Session session = mock();
|
||||
// Queue gets created in order to create MessageConsumer for that Destination...
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
// and then the MessageConsumer gets created...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
Connection connection = mock();
|
||||
// session gets created in order to register MessageListener...
|
||||
given(connection.createSession(this.container.isSessionTransacted(),
|
||||
this.container.getSessionAcknowledgeMode())).willReturn(session);
|
||||
// and the connection is start()ed after the listener is registered...
|
||||
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
this.container.setConnectionFactory(connectionFactory);
|
||||
|
||||
@@ -35,16 +35,16 @@ public class JmsResponseTests {
|
||||
|
||||
@Test
|
||||
public void destinationDoesNotUseDestinationResolver() throws JMSException {
|
||||
Destination destination = mock(Destination.class);
|
||||
Destination destination = mock();
|
||||
Destination actual = JmsResponse.forDestination("foo", destination).resolveDestination(null, null);
|
||||
assertThat(actual).isSameAs(destination);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveDestinationForQueue() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
DestinationResolver destinationResolver = mock(DestinationResolver.class);
|
||||
Destination destination = mock(Destination.class);
|
||||
Session session = mock();
|
||||
DestinationResolver destinationResolver = mock();
|
||||
Destination destination = mock();
|
||||
|
||||
given(destinationResolver.resolveDestinationName(session, "myQueue", false)).willReturn(destination);
|
||||
JmsResponse<String> jmsResponse = JmsResponse.forQueue("foo", "myQueue");
|
||||
|
||||
@@ -64,11 +64,11 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithMessageContentsDelegateForTextMessage() throws Exception {
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
TextMessage textMessage = mock();
|
||||
// TextMessage contents must be unwrapped...
|
||||
given(textMessage.getText()).willReturn(TEXT);
|
||||
|
||||
MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
|
||||
MessageContentsDelegate delegate = mock();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
|
||||
adapter.onMessage(textMessage);
|
||||
@@ -78,7 +78,7 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithMessageContentsDelegateForBytesMessage() throws Exception {
|
||||
BytesMessage bytesMessage = mock(BytesMessage.class);
|
||||
BytesMessage bytesMessage = mock();
|
||||
// BytesMessage contents must be unwrapped...
|
||||
given(bytesMessage.getBodyLength()).willReturn(Long.valueOf(TEXT.getBytes().length));
|
||||
given(bytesMessage.readBytes(any(byte[].class))).willAnswer((Answer<Integer>) invocation -> {
|
||||
@@ -87,7 +87,7 @@ class MessageListenerAdapterTests {
|
||||
return inputStream.read(bytes);
|
||||
});
|
||||
|
||||
MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
|
||||
MessageContentsDelegate delegate = mock();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
|
||||
adapter.onMessage(bytesMessage);
|
||||
@@ -97,10 +97,10 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithMessageContentsDelegateForObjectMessage() throws Exception {
|
||||
ObjectMessage objectMessage = mock(ObjectMessage.class);
|
||||
ObjectMessage objectMessage = mock();
|
||||
given(objectMessage.getObject()).willReturn(NUMBER);
|
||||
|
||||
MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
|
||||
MessageContentsDelegate delegate = mock();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
|
||||
adapter.onMessage(objectMessage);
|
||||
@@ -110,10 +110,10 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithMessageContentsDelegateForObjectMessageWithPlainObject() throws Exception {
|
||||
ObjectMessage objectMessage = mock(ObjectMessage.class);
|
||||
ObjectMessage objectMessage = mock();
|
||||
given(objectMessage.getObject()).willReturn(OBJECT);
|
||||
|
||||
MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
|
||||
MessageContentsDelegate delegate = mock();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
|
||||
adapter.onMessage(objectMessage);
|
||||
@@ -123,9 +123,9 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithMessageDelegate() throws Exception {
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
TextMessage textMessage = mock();
|
||||
|
||||
MessageDelegate delegate = mock(MessageDelegate.class);
|
||||
MessageDelegate delegate = mock();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
|
||||
// we DON'T want the default SimpleMessageConversion happening...
|
||||
@@ -137,7 +137,7 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWhenTheAdapterItselfIsTheDelegate() throws Exception {
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
TextMessage textMessage = mock();
|
||||
// TextMessage contents must be unwrapped...
|
||||
given(textMessage.getText()).willReturn(TEXT);
|
||||
|
||||
@@ -148,7 +148,7 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testRainyDayWithNoApplicableHandlingMethods() throws Exception {
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
TextMessage textMessage = mock();
|
||||
// TextMessage contents must be unwrapped...
|
||||
given(textMessage.getText()).willReturn(TEXT);
|
||||
|
||||
@@ -162,8 +162,8 @@ class MessageListenerAdapterTests {
|
||||
void testThatAnExceptionThrownFromTheHandlingMethodIsSimplySwallowedByDefault() throws Exception {
|
||||
final IllegalArgumentException exception = new IllegalArgumentException();
|
||||
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
MessageDelegate delegate = mock(MessageDelegate.class);
|
||||
TextMessage textMessage = mock();
|
||||
MessageDelegate delegate = mock();
|
||||
willThrow(exception).given(delegate).handleMessage(textMessage);
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
@@ -205,8 +205,8 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception {
|
||||
TextMessage textMessage = mock(TextMessage.class);
|
||||
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
|
||||
TextMessage textMessage = mock();
|
||||
ResponsiveMessageDelegate delegate = mock();
|
||||
given(delegate.handleMessage(textMessage)).willReturn(TEXT);
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
|
||||
@@ -217,22 +217,22 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
|
||||
Queue destination = mock(Queue.class);
|
||||
TextMessage sentTextMessage = mock(TextMessage.class);
|
||||
Queue destination = mock();
|
||||
TextMessage sentTextMessage = mock();
|
||||
// correlation ID is queried when response is being created...
|
||||
given(sentTextMessage.getJMSCorrelationID()).willReturn(
|
||||
CORRELATION_ID);
|
||||
// Reply-To is queried when response is being created...
|
||||
given(sentTextMessage.getJMSReplyTo()).willReturn(null); // we want to fall back to the default...
|
||||
|
||||
TextMessage responseTextMessage = mock(TextMessage.class);
|
||||
TextMessage responseTextMessage = mock();
|
||||
|
||||
QueueSender queueSender = mock(QueueSender.class);
|
||||
Session session = mock(Session.class);
|
||||
QueueSender queueSender = mock();
|
||||
Session session = mock();
|
||||
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
|
||||
given(session.createProducer(destination)).willReturn(queueSender);
|
||||
|
||||
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
|
||||
ResponsiveMessageDelegate delegate = mock();
|
||||
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
@@ -252,21 +252,21 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
|
||||
Queue destination = mock(Queue.class);
|
||||
TextMessage sentTextMessage = mock(TextMessage.class);
|
||||
Queue destination = mock();
|
||||
TextMessage sentTextMessage = mock();
|
||||
// correlation ID is queried when response is being created...
|
||||
given(sentTextMessage.getJMSCorrelationID()).willReturn(null);
|
||||
given(sentTextMessage.getJMSMessageID()).willReturn(CORRELATION_ID);
|
||||
// Reply-To is queried when response is being created...
|
||||
given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
|
||||
|
||||
TextMessage responseTextMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
Session session = mock(Session.class);
|
||||
TextMessage responseTextMessage = mock();
|
||||
MessageProducer messageProducer = mock();
|
||||
Session session = mock();
|
||||
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
|
||||
given(session.createProducer(destination)).willReturn(messageProducer);
|
||||
|
||||
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
|
||||
ResponsiveMessageDelegate delegate = mock();
|
||||
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
@@ -285,17 +285,17 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
|
||||
final TextMessage sentTextMessage = mock(TextMessage.class);
|
||||
final TextMessage sentTextMessage = mock();
|
||||
// correlation ID is queried when response is being created...
|
||||
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
|
||||
// Reply-To is queried when response is being created...
|
||||
given(sentTextMessage.getJMSReplyTo()).willReturn(null);
|
||||
|
||||
TextMessage responseTextMessage = mock(TextMessage.class);
|
||||
final QueueSession session = mock(QueueSession.class);
|
||||
TextMessage responseTextMessage = mock();
|
||||
final QueueSession session = mock();
|
||||
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
|
||||
|
||||
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
|
||||
ResponsiveMessageDelegate delegate = mock();
|
||||
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
|
||||
|
||||
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
@@ -314,23 +314,23 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
|
||||
Queue destination = mock(Queue.class);
|
||||
Queue destination = mock();
|
||||
|
||||
final TextMessage sentTextMessage = mock(TextMessage.class);
|
||||
final TextMessage sentTextMessage = mock();
|
||||
// correlation ID is queried when response is being created...
|
||||
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
|
||||
// Reply-To is queried when response is being created...
|
||||
given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
|
||||
|
||||
TextMessage responseTextMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseTextMessage = mock();
|
||||
MessageProducer messageProducer = mock();
|
||||
willThrow(new JMSException("Doe!")).given(messageProducer).send(responseTextMessage);
|
||||
|
||||
final QueueSession session = mock(QueueSession.class);
|
||||
final QueueSession session = mock();
|
||||
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
|
||||
given(session.createProducer(destination)).willReturn(messageProducer);
|
||||
|
||||
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
|
||||
ResponsiveMessageDelegate delegate = mock();
|
||||
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
|
||||
|
||||
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
@@ -350,10 +350,10 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegateDoesNotSendReturnTextMessageWhenSessionSupplied_AndListenerMethodThrowsException() throws Exception {
|
||||
final TextMessage message = mock(TextMessage.class);
|
||||
final QueueSession session = mock(QueueSession.class);
|
||||
final TextMessage message = mock();
|
||||
final QueueSession session = mock();
|
||||
|
||||
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
|
||||
ResponsiveMessageDelegate delegate = mock();
|
||||
willThrow(new IllegalArgumentException("Doe!")).given(delegate).handleMessage(message);
|
||||
|
||||
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
@@ -368,9 +368,9 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
|
||||
final TextMessage sentTextMessage = mock(TextMessage.class);
|
||||
final Session session = mock(Session.class);
|
||||
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
|
||||
final TextMessage sentTextMessage = mock();
|
||||
final Session session = mock();
|
||||
ResponsiveMessageDelegate delegate = mock();
|
||||
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
|
||||
|
||||
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
@@ -387,20 +387,20 @@ class MessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
|
||||
Queue destination = mock(Queue.class);
|
||||
final TextMessage sentTextMessage = mock(TextMessage.class);
|
||||
Queue destination = mock();
|
||||
final TextMessage sentTextMessage = mock();
|
||||
// correlation ID is queried when response is being created...
|
||||
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
|
||||
// Reply-To is queried when response is being created...
|
||||
given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
|
||||
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
QueueSender queueSender = mock(QueueSender.class);
|
||||
TextMessage responseMessage = mock();
|
||||
QueueSender queueSender = mock();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
given(session.createProducer(destination)).willReturn(queueSender);
|
||||
|
||||
ResponsiveJmsTextMessageReturningMessageDelegate delegate = mock(ResponsiveJmsTextMessageReturningMessageDelegate.class);
|
||||
ResponsiveJmsTextMessageReturningMessageDelegate delegate = mock();
|
||||
given(delegate.handleMessage(sentTextMessage)).willReturn(responseMessage);
|
||||
|
||||
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
|
||||
|
||||
@@ -60,7 +60,7 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
private static final Destination sharedReplyDestination = mock(Destination.class);
|
||||
private static final Destination sharedReplyDestination = mock();
|
||||
|
||||
private final DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
|
||||
|
||||
@@ -81,7 +81,7 @@ public class MessagingMessageListenerAdapterTests {
|
||||
.setHeader(JmsHeaders.REPLY_TO, replyTo)
|
||||
.build();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
|
||||
MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
|
||||
jakarta.jms.Message replyMessage = listener.buildMessage(session, result);
|
||||
@@ -97,7 +97,7 @@ public class MessagingMessageListenerAdapterTests {
|
||||
@Test
|
||||
public void exceptionInListener() {
|
||||
jakarta.jms.Message message = new StubTextMessage("foo");
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class);
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class)
|
||||
.isThrownBy(() -> listener.onMessage(message, session))
|
||||
@@ -109,7 +109,7 @@ public class MessagingMessageListenerAdapterTests {
|
||||
@Test
|
||||
public void exceptionInInvocation() {
|
||||
jakarta.jms.Message message = new StubTextMessage("foo");
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
MessagingMessageListenerAdapter listener = getSimpleInstance("wrongParam", Integer.class);
|
||||
|
||||
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
|
||||
@@ -119,8 +119,8 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void payloadConversionLazilyInvoked() throws JMSException {
|
||||
jakarta.jms.Message jmsMessage = mock(jakarta.jms.Message.class);
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
jakarta.jms.Message jmsMessage = mock();
|
||||
MessageConverter messageConverter = mock();
|
||||
given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
|
||||
MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
|
||||
listener.setMessageConverter(messageConverter);
|
||||
@@ -132,7 +132,7 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void headerConversionLazilyInvoked() throws JMSException {
|
||||
jakarta.jms.Message jmsMessage = mock(jakarta.jms.Message.class);
|
||||
jakarta.jms.Message jmsMessage = mock();
|
||||
given(jmsMessage.getPropertyNames()).willThrow(new IllegalArgumentException("Header failure"));
|
||||
MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
|
||||
Message<?> message = listener.toMessagingMessage(jmsMessage);
|
||||
@@ -145,9 +145,9 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void incomingMessageUsesMessageConverter() throws JMSException {
|
||||
jakarta.jms.Message jmsMessage = mock(jakarta.jms.Message.class);
|
||||
Session session = mock(Session.class);
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
jakarta.jms.Message jmsMessage = mock();
|
||||
Session session = mock();
|
||||
MessageConverter messageConverter = mock();
|
||||
given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
|
||||
MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
|
||||
listener.setMessageConverter(messageConverter);
|
||||
@@ -159,8 +159,8 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void replyUsesMessageConverterForPayload() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
MessageConverter messageConverter = mock(MessageConverter.class);
|
||||
Session session = mock();
|
||||
MessageConverter messageConverter = mock();
|
||||
given(messageConverter.toMessage("Response", session)).willReturn(new StubTextMessage("Response"));
|
||||
|
||||
Message<String> result = MessageBuilder.withPayload("Response").build();
|
||||
@@ -175,17 +175,17 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void replyPayloadToQueue() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
Queue replyDestination = mock(Queue.class);
|
||||
Session session = mock();
|
||||
Queue replyDestination = mock();
|
||||
given(session.createQueue("queueOut")).willReturn(replyDestination);
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage responseMessage = mock();
|
||||
given(session.createTextMessage("Response")).willReturn(responseMessage);
|
||||
given(session.createProducer(replyDestination)).willReturn(messageProducer);
|
||||
|
||||
MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToQueue", Message.class);
|
||||
listener.onMessage(mock(jakarta.jms.Message.class), session);
|
||||
listener.onMessage(mock(), session);
|
||||
|
||||
verify(session).createQueue("queueOut");
|
||||
verify(session).createTextMessage("Response");
|
||||
@@ -195,12 +195,12 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void replyWithCustomTimeToLive() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
Queue replyDestination = mock(Queue.class);
|
||||
Session session = mock();
|
||||
Queue replyDestination = mock();
|
||||
given(session.createQueue("queueOut")).willReturn(replyDestination);
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage responseMessage = mock();
|
||||
given(session.createTextMessage("Response")).willReturn(responseMessage);
|
||||
given(session.createProducer(replyDestination)).willReturn(messageProducer);
|
||||
|
||||
@@ -208,7 +208,7 @@ public class MessagingMessageListenerAdapterTests {
|
||||
QosSettings settings = new QosSettings();
|
||||
settings.setTimeToLive(6000);
|
||||
listener.setResponseQosSettings(settings);
|
||||
listener.onMessage(mock(jakarta.jms.Message.class), session);
|
||||
listener.onMessage(mock(), session);
|
||||
verify(session).createQueue("queueOut");
|
||||
verify(session).createTextMessage("Response");
|
||||
verify(messageProducer).send(responseMessage, jakarta.jms.Message.DEFAULT_DELIVERY_MODE,
|
||||
@@ -218,19 +218,19 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void replyWithFullQoS() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
Queue replyDestination = mock(Queue.class);
|
||||
Session session = mock();
|
||||
Queue replyDestination = mock();
|
||||
given(session.createQueue("queueOut")).willReturn(replyDestination);
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage responseMessage = mock();
|
||||
given(session.createTextMessage("Response")).willReturn(responseMessage);
|
||||
given(session.createProducer(replyDestination)).willReturn(messageProducer);
|
||||
|
||||
MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToQueue", Message.class);
|
||||
QosSettings settings = new QosSettings(DeliveryMode.NON_PERSISTENT, 6, 6000);
|
||||
listener.setResponseQosSettings(settings);
|
||||
listener.onMessage(mock(jakarta.jms.Message.class), session);
|
||||
listener.onMessage(mock(), session);
|
||||
verify(session).createQueue("queueOut");
|
||||
verify(session).createTextMessage("Response");
|
||||
verify(messageProducer).send(responseMessage, DeliveryMode.NON_PERSISTENT, 6, 6000);
|
||||
@@ -239,17 +239,17 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void replyPayloadToTopic() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
Topic replyDestination = mock(Topic.class);
|
||||
Session session = mock();
|
||||
Topic replyDestination = mock();
|
||||
given(session.createTopic("topicOut")).willReturn(replyDestination);
|
||||
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage responseMessage = mock();
|
||||
given(session.createTextMessage("Response")).willReturn(responseMessage);
|
||||
given(session.createProducer(replyDestination)).willReturn(messageProducer);
|
||||
|
||||
MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToTopic", Message.class);
|
||||
listener.onMessage(mock(jakarta.jms.Message.class), session);
|
||||
listener.onMessage(mock(), session);
|
||||
|
||||
verify(session).createTopic("topicOut");
|
||||
verify(session).createTextMessage("Response");
|
||||
@@ -259,14 +259,14 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void replyPayloadToDestination() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
Session session = mock();
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage responseMessage = mock();
|
||||
given(session.createTextMessage("Response")).willReturn(responseMessage);
|
||||
given(session.createProducer(sharedReplyDestination)).willReturn(messageProducer);
|
||||
|
||||
MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToDestination", Message.class);
|
||||
listener.onMessage(mock(jakarta.jms.Message.class), session);
|
||||
listener.onMessage(mock(), session);
|
||||
|
||||
verify(session, times(0)).createQueue(anyString());
|
||||
verify(session).createTextMessage("Response");
|
||||
@@ -276,18 +276,18 @@ public class MessagingMessageListenerAdapterTests {
|
||||
|
||||
@Test
|
||||
public void replyPayloadNoDestination() throws JMSException {
|
||||
Queue replyDestination = mock(Queue.class);
|
||||
Queue replyDestination = mock();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
Session session = mock();
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage responseMessage = mock();
|
||||
given(session.createTextMessage("Response")).willReturn(responseMessage);
|
||||
given(session.createProducer(replyDestination)).willReturn(messageProducer);
|
||||
|
||||
MessagingMessageListenerAdapter listener =
|
||||
getPayloadInstance("Response", "replyPayloadNoDestination", Message.class);
|
||||
listener.setDefaultResponseDestination(replyDestination);
|
||||
listener.onMessage(mock(jakarta.jms.Message.class), session);
|
||||
listener.onMessage(mock(), session);
|
||||
|
||||
verify(session, times(0)).createQueue(anyString());
|
||||
verify(session).createTextMessage("Response");
|
||||
@@ -317,11 +317,11 @@ public class MessagingMessageListenerAdapterTests {
|
||||
}
|
||||
|
||||
public TextMessage testReplyWithJackson(String methodName, String replyContent) throws JMSException {
|
||||
Queue replyDestination = mock(Queue.class);
|
||||
Queue replyDestination = mock();
|
||||
|
||||
Session session = mock(Session.class);
|
||||
MessageProducer messageProducer = mock(MessageProducer.class);
|
||||
TextMessage responseMessage = mock(TextMessage.class);
|
||||
Session session = mock();
|
||||
MessageProducer messageProducer = mock();
|
||||
TextMessage responseMessage = mock();
|
||||
given(session.createTextMessage(replyContent)).willReturn(responseMessage);
|
||||
given(session.createProducer(replyDestination)).willReturn(messageProducer);
|
||||
|
||||
@@ -330,7 +330,7 @@ public class MessagingMessageListenerAdapterTests {
|
||||
messageConverter.setTargetType(MessageType.TEXT);
|
||||
listener.setMessageConverter(messageConverter);
|
||||
listener.setDefaultResponseDestination(replyDestination);
|
||||
listener.onMessage(mock(jakarta.jms.Message.class), session);
|
||||
listener.onMessage(mock(), session);
|
||||
|
||||
verify(session, times(0)).createQueue(anyString());
|
||||
verify(session).createTextMessage(replyContent);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DefaultJmsActivationSpecFactoryTests {
|
||||
public void webSphereResourceAdapterSetup() throws Exception {
|
||||
Destination destination = new StubQueue();
|
||||
|
||||
DestinationResolver destinationResolver = mock(DestinationResolver.class);
|
||||
DestinationResolver destinationResolver = mock();
|
||||
given(destinationResolver.resolveDestinationName(null, "destinationname", false)).willReturn(destination);
|
||||
|
||||
DefaultJmsActivationSpecFactory activationSpecFactory = new DefaultJmsActivationSpecFactory();
|
||||
|
||||
@@ -51,8 +51,8 @@ public class SimpleMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testStringConversion() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
TextMessage message = mock(TextMessage.class);
|
||||
Session session = mock();
|
||||
TextMessage message = mock();
|
||||
|
||||
String content = "test";
|
||||
|
||||
@@ -66,8 +66,8 @@ public class SimpleMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testByteArrayConversion() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
BytesMessage message = mock(BytesMessage.class);
|
||||
Session session = mock();
|
||||
BytesMessage message = mock();
|
||||
|
||||
byte[] content = "test".getBytes();
|
||||
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content);
|
||||
@@ -86,8 +86,8 @@ public class SimpleMessageConverterTests {
|
||||
@Test
|
||||
public void testMapConversion() throws JMSException {
|
||||
|
||||
Session session = mock(Session.class);
|
||||
MapMessage message = mock(MapMessage.class);
|
||||
Session session = mock();
|
||||
MapMessage message = mock();
|
||||
|
||||
Map<String, String> content = new HashMap<>(2);
|
||||
content.put("key1", "value1");
|
||||
@@ -108,8 +108,8 @@ public class SimpleMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testSerializableConversion() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
ObjectMessage message = mock(ObjectMessage.class);
|
||||
Session session = mock();
|
||||
ObjectMessage message = mock();
|
||||
|
||||
Integer content = 5;
|
||||
|
||||
@@ -135,8 +135,8 @@ public class SimpleMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
|
||||
Session session = mock(Session.class);
|
||||
ObjectMessage message = mock(ObjectMessage.class);
|
||||
Session session = mock();
|
||||
ObjectMessage message = mock();
|
||||
|
||||
SimpleMessageConverter converter = new SimpleMessageConverter();
|
||||
Message msg = converter.toMessage(message, session);
|
||||
@@ -145,7 +145,7 @@ public class SimpleMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testFromMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
|
||||
Message message = mock(Message.class);
|
||||
Message message = mock();
|
||||
|
||||
SimpleMessageConverter converter = new SimpleMessageConverter();
|
||||
Object msg = converter.fromMessage(message);
|
||||
@@ -154,8 +154,8 @@ public class SimpleMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
|
||||
MapMessage message = mock(MapMessage.class);
|
||||
Session session = mock(Session.class);
|
||||
MapMessage message = mock();
|
||||
Session session = mock();
|
||||
given(session.createMapMessage()).willReturn(message);
|
||||
|
||||
Map<Integer, String> content = new HashMap<>(1);
|
||||
@@ -168,8 +168,8 @@ public class SimpleMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
|
||||
MapMessage message = mock(MapMessage.class);
|
||||
Session session = mock(Session.class);
|
||||
MapMessage message = mock();
|
||||
Session session = mock();
|
||||
given(session.createMapMessage()).willReturn(message);
|
||||
|
||||
Map<Object, String> content = new HashMap<>(1);
|
||||
|
||||
@@ -49,15 +49,13 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
class MappingJackson2MessageConverterTests {
|
||||
|
||||
private MappingJackson2MessageConverter converter;
|
||||
private MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
|
||||
private Session sessionMock;
|
||||
private Session sessionMock = mock();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
sessionMock = mock(Session.class);
|
||||
converter = new MappingJackson2MessageConverter();
|
||||
converter.setEncodingPropertyName("__encoding__");
|
||||
converter.setTypeIdPropertyName("__typeid__");
|
||||
}
|
||||
@@ -65,7 +63,7 @@ class MappingJackson2MessageConverterTests {
|
||||
|
||||
@Test
|
||||
void toBytesMessage() throws Exception {
|
||||
BytesMessage bytesMessageMock = mock(BytesMessage.class);
|
||||
BytesMessage bytesMessageMock = mock();
|
||||
Date toBeMarshalled = new Date();
|
||||
|
||||
given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock);
|
||||
@@ -79,7 +77,7 @@ class MappingJackson2MessageConverterTests {
|
||||
|
||||
@Test
|
||||
void fromBytesMessage() throws Exception {
|
||||
BytesMessage bytesMessageMock = mock(BytesMessage.class);
|
||||
BytesMessage bytesMessageMock = mock();
|
||||
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
|
||||
|
||||
byte[] bytes = "{\"foo\":\"bar\"}".getBytes();
|
||||
@@ -98,7 +96,7 @@ class MappingJackson2MessageConverterTests {
|
||||
@Test
|
||||
void toTextMessageWithObject() throws Exception {
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
Date toBeMarshalled = new Date();
|
||||
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
|
||||
@@ -110,7 +108,7 @@ class MappingJackson2MessageConverterTests {
|
||||
@Test
|
||||
void toTextMessageWithMap() throws Exception {
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
Map<String, String> toBeMarshalled = new HashMap<>();
|
||||
toBeMarshalled.put("foo", "bar");
|
||||
|
||||
@@ -122,7 +120,7 @@ class MappingJackson2MessageConverterTests {
|
||||
|
||||
@Test
|
||||
void fromTextMessage() throws Exception {
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
MyBean unmarshalled = new MyBean("bar");
|
||||
|
||||
String text = "{\"foo\":\"bar\"}";
|
||||
@@ -135,7 +133,7 @@ class MappingJackson2MessageConverterTests {
|
||||
|
||||
@Test
|
||||
void fromTextMessageWithUnknownProperty() throws Exception {
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
MyBean unmarshalled = new MyBean("bar");
|
||||
|
||||
String text = "{\"foo\":\"bar\", \"unknownProperty\":\"value\"}";
|
||||
@@ -148,7 +146,7 @@ class MappingJackson2MessageConverterTests {
|
||||
|
||||
@Test
|
||||
void fromTextMessageAsObject() throws Exception {
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
|
||||
|
||||
String text = "{\"foo\":\"bar\"}";
|
||||
@@ -161,7 +159,7 @@ class MappingJackson2MessageConverterTests {
|
||||
|
||||
@Test
|
||||
void fromTextMessageAsMap() throws Exception {
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
|
||||
|
||||
String text = "{\"foo\":\"bar\"}";
|
||||
@@ -206,7 +204,7 @@ class MappingJackson2MessageConverterTests {
|
||||
|
||||
private void testToTextMessageWithReturnType(MethodParameter returnType) throws JMSException, NoSuchMethodException {
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
|
||||
MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
|
||||
@@ -217,7 +215,7 @@ class MappingJackson2MessageConverterTests {
|
||||
@Test
|
||||
void toTextMessageWithJsonViewClass() throws JMSException {
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
|
||||
MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
|
||||
@@ -231,7 +229,7 @@ class MappingJackson2MessageConverterTests {
|
||||
@Test
|
||||
void toTextMessageWithAnotherJsonViewClass() throws JMSException {
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
|
||||
MyAnotherBean bean = new MyAnotherBean("test", "lengthy description");
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
|
||||
|
||||
@@ -22,7 +22,6 @@ import javax.xml.transform.Source;
|
||||
import jakarta.jms.BytesMessage;
|
||||
import jakarta.jms.Session;
|
||||
import jakarta.jms.TextMessage;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.oxm.Marshaller;
|
||||
@@ -40,27 +39,18 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class MarshallingMessageConverterTests {
|
||||
|
||||
private MarshallingMessageConverter converter;
|
||||
private Marshaller marshallerMock = mock();
|
||||
|
||||
private Marshaller marshallerMock;
|
||||
private Unmarshaller unmarshallerMock = mock();
|
||||
|
||||
private Unmarshaller unmarshallerMock;
|
||||
private Session sessionMock = mock();
|
||||
|
||||
private Session sessionMock;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
marshallerMock = mock(Marshaller.class);
|
||||
unmarshallerMock = mock(Unmarshaller.class);
|
||||
sessionMock = mock(Session.class);
|
||||
converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock);
|
||||
}
|
||||
private MarshallingMessageConverter converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock);
|
||||
|
||||
|
||||
@Test
|
||||
public void toBytesMessage() throws Exception {
|
||||
BytesMessage bytesMessageMock = mock(BytesMessage.class);
|
||||
BytesMessage bytesMessageMock = mock();
|
||||
Object toBeMarshalled = new Object();
|
||||
given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock);
|
||||
|
||||
@@ -72,7 +62,7 @@ public class MarshallingMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void fromBytesMessage() throws Exception {
|
||||
BytesMessage bytesMessageMock = mock(BytesMessage.class);
|
||||
BytesMessage bytesMessageMock = mock();
|
||||
Object unmarshalled = new Object();
|
||||
|
||||
given(bytesMessageMock.getBodyLength()).willReturn(10L);
|
||||
@@ -86,7 +76,7 @@ public class MarshallingMessageConverterTests {
|
||||
@Test
|
||||
public void toTextMessage() throws Exception {
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
Object toBeMarshalled = new Object();
|
||||
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
|
||||
@@ -98,7 +88,7 @@ public class MarshallingMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void fromTextMessage() throws Exception {
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
TextMessage textMessageMock = mock();
|
||||
Object unmarshalled = new Object();
|
||||
|
||||
String text = "foo";
|
||||
|
||||
@@ -45,14 +45,14 @@ public class MessagingMessageConverterTests {
|
||||
@Test
|
||||
public void onlyHandlesMessage() throws JMSException {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.converter.toMessage(new Object(), mock(Session.class)));
|
||||
this.converter.toMessage(new Object(), mock()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleObject() throws Exception {
|
||||
Session session = mock(Session.class);
|
||||
Serializable payload = mock(Serializable.class);
|
||||
ObjectMessage jmsMessage = mock(ObjectMessage.class);
|
||||
Session session = mock();
|
||||
Serializable payload = mock();
|
||||
ObjectMessage jmsMessage = mock();
|
||||
given(session.createObjectMessage(payload)).willReturn(jmsMessage);
|
||||
|
||||
this.converter.toMessage(MessageBuilder.withPayload(payload).build(), session);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class DynamicDestinationResolverTests {
|
||||
@Test
|
||||
public void resolveWithPubSubTopicSession() throws Exception {
|
||||
Topic expectedDestination = new StubTopic();
|
||||
TopicSession session = mock(TopicSession.class);
|
||||
TopicSession session = mock();
|
||||
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||
testResolveDestination(session, expectedDestination, true);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class DynamicDestinationResolverTests {
|
||||
@Test
|
||||
public void resolveWithPubSubVanillaSession() throws Exception {
|
||||
Topic expectedDestination = new StubTopic();
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||
testResolveDestination(session, expectedDestination, true);
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class DynamicDestinationResolverTests {
|
||||
@Test
|
||||
public void resolveWithPointToPointQueueSession() throws Exception {
|
||||
Queue expectedDestination = new StubQueue();
|
||||
Session session = mock(QueueSession.class);
|
||||
QueueSession session = mock();
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||
testResolveDestination(session, expectedDestination, false);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class DynamicDestinationResolverTests {
|
||||
@Test
|
||||
public void resolveWithPointToPointVanillaSession() throws Exception {
|
||||
Queue expectedDestination = new StubQueue();
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
|
||||
testResolveDestination(session, expectedDestination, false);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class JmsDestinationAccessorTests {
|
||||
|
||||
@Test
|
||||
public void testChokesIfDestinationResolverIsetToNullExplicitly() throws Exception {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = mock();
|
||||
|
||||
JmsDestinationAccessor accessor = new StubJmsDestinationAccessor();
|
||||
accessor.setConnectionFactory(connectionFactory);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class JndiDestinationResolverTests {
|
||||
@Test
|
||||
public void testHitsCacheSecondTimeThrough() throws Exception {
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
JndiDestinationResolver resolver = new OneTimeLookupJndiDestinationResolver();
|
||||
Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
|
||||
@@ -54,7 +54,7 @@ public class JndiDestinationResolverTests {
|
||||
@Test
|
||||
public void testDoesNotUseCacheIfCachingIsTurnedOff() throws Exception {
|
||||
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
CountingCannedJndiDestinationResolver resolver
|
||||
= new CountingCannedJndiDestinationResolver();
|
||||
@@ -72,9 +72,9 @@ public class JndiDestinationResolverTests {
|
||||
|
||||
@Test
|
||||
public void testDelegatesToFallbackIfNotResolvedInJndi() throws Exception {
|
||||
Session session = mock(Session.class);
|
||||
Session session = mock();
|
||||
|
||||
DestinationResolver dynamicResolver = mock(DestinationResolver.class);
|
||||
DestinationResolver dynamicResolver = mock();
|
||||
given(dynamicResolver.resolveDestinationName(session, DESTINATION_NAME,
|
||||
true)).willReturn(DESTINATION);
|
||||
|
||||
@@ -94,8 +94,8 @@ public class JndiDestinationResolverTests {
|
||||
|
||||
@Test
|
||||
public void testDoesNotDelegateToFallbackIfNotResolvedInJndi() throws Exception {
|
||||
final Session session = mock(Session.class);
|
||||
DestinationResolver dynamicResolver = mock(DestinationResolver.class);
|
||||
final Session session = mock();
|
||||
DestinationResolver dynamicResolver = mock();
|
||||
|
||||
final JndiDestinationResolver resolver = new JndiDestinationResolver() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user