Polishing
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.jms.listener;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link AbstractMessageListenerContainer} class.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public abstract class AbstractMessageListenerContainerTests {
|
||||
|
||||
protected abstract AbstractMessageListenerContainer getContainer();
|
||||
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSettingMessageListenerToANullType() throws Exception {
|
||||
getContainer().setMessageListener(null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSettingMessageListenerToAnUnsupportedType() throws Exception {
|
||||
getContainer().setMessageListener("Bingo");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,7 +78,7 @@ public class DefaultMessageListenerContainerTests {
|
||||
public void recoverResetBackOff() {
|
||||
BackOff backOff = mock(BackOff.class);
|
||||
BackOffExecution execution = mock(BackOffExecution.class);
|
||||
given(execution.nextBackOff()).willReturn(50L, 50L, 50L); // 3 attempts max
|
||||
given(execution.nextBackOff()).willReturn(50L, 50L, 50L); // 3 attempts max
|
||||
given(backOff.start()).willReturn(execution);
|
||||
|
||||
DefaultMessageListenerContainer container = createContainer(createRecoverableContainerFactory(1));
|
||||
@@ -88,7 +88,7 @@ public class DefaultMessageListenerContainerTests {
|
||||
|
||||
assertEquals(true, container.isRunning());
|
||||
verify(backOff).start();
|
||||
verify(execution, times(1)).nextBackOff(); // only on attempt as the second one lead to a recovery
|
||||
verify(execution, times(1)).nextBackOff(); // only on attempt as the second one lead to a recovery
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,11 +123,8 @@ public class DefaultMessageListenerContainerTests {
|
||||
private ConnectionFactory createFailingContainerFactory() {
|
||||
try {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).will(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
throw new JMSException("Test exception");
|
||||
}
|
||||
given(connectionFactory.createConnection()).will(invocation -> {
|
||||
throw new JMSException("Test exception");
|
||||
});
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,6 @@ import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageListener;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
@@ -44,7 +43,7 @@ import static org.mockito.BDDMockito.*;
|
||||
* @author Chris Beams
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class SimpleMessageListenerContainerTests extends AbstractMessageListenerContainerTests {
|
||||
public class SimpleMessageListenerContainerTests {
|
||||
|
||||
private static final String DESTINATION_NAME = "foo";
|
||||
|
||||
@@ -52,39 +51,38 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
|
||||
private static final StubQueue QUEUE_DESTINATION = new StubQueue();
|
||||
|
||||
|
||||
private SimpleMessageListenerContainer container;
|
||||
private final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.container = (SimpleMessageListenerContainer) getContainer();
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSettingMessageListenerToANullType() {
|
||||
this.container.setMessageListener(null);
|
||||
assertNull(this.container.getMessageListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractMessageListenerContainer getContainer() {
|
||||
return new SimpleMessageListenerContainer();
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSettingMessageListenerToAnUnsupportedType() {
|
||||
this.container.setMessageListener("Bingo");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSessionTransactedModeReallyDoesDefaultToFalse() throws Exception {
|
||||
public void testSessionTransactedModeReallyDoesDefaultToFalse() {
|
||||
assertFalse("The [pubSubLocal] property of SimpleMessageListenerContainer " +
|
||||
"must default to false. Change this test (and the " +
|
||||
"attendant Javadoc) if you have changed the default.",
|
||||
container.isPubSubNoLocal());
|
||||
this.container.isPubSubNoLocal());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSettingConcurrentConsumersToZeroIsNotAllowed() throws Exception {
|
||||
container.setConcurrentConsumers(0);
|
||||
container.afterPropertiesSet();
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSettingConcurrentConsumersToZeroIsNotAllowed() {
|
||||
this.container.setConcurrentConsumers(0);
|
||||
this.container.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testSettingConcurrentConsumersToANegativeValueIsNotAllowed() throws Exception {
|
||||
container.setConcurrentConsumers(-198);
|
||||
container.afterPropertiesSet();
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSettingConcurrentConsumersToANegativeValueIsNotAllowed() {
|
||||
this.container.setConcurrentConsumers(-198);
|
||||
this.container.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +92,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
// 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...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
// session gets created in order to register MessageListener...
|
||||
@@ -124,7 +122,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
// 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...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
// session gets created in order to register MessageListener...
|
||||
@@ -156,7 +154,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
// 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...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
given(session.getAcknowledgeMode()).willReturn(Session.AUTO_ACKNOWLEDGE);
|
||||
@@ -170,7 +168,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
|
||||
final Set<String> failure = new HashSet<String>(1);
|
||||
final Set<String> failure = new HashSet<>(1);
|
||||
|
||||
this.container.setConnectionFactory(connectionFactory);
|
||||
this.container.setDestinationName(DESTINATION_NAME);
|
||||
@@ -207,7 +205,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
|
||||
final Session session = mock(Session.class);
|
||||
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
given(session.getAcknowledgeMode()).willReturn(Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
@@ -253,7 +251,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
// 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...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
|
||||
@@ -304,7 +302,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
// 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...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
|
||||
@@ -351,7 +349,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
// 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...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
// an exception is thrown, so the rollback logic is being applied here...
|
||||
given(session.getTransacted()).willReturn(false);
|
||||
|
||||
@@ -438,7 +436,7 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
// 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...
|
||||
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
|
||||
|
||||
Connection connection = mock(Connection.class);
|
||||
// session gets created in order to register MessageListener...
|
||||
@@ -482,42 +480,42 @@ public class SimpleMessageListenerContainerTests extends AbstractMessageListener
|
||||
|
||||
private MessageListener messageListener;
|
||||
|
||||
public void sendMessage(Message message) throws JMSException {
|
||||
public void sendMessage(Message message) {
|
||||
this.messageListener.onMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessageSelector() throws JMSException {
|
||||
public String getMessageSelector() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageListener getMessageListener() throws JMSException {
|
||||
public MessageListener getMessageListener() {
|
||||
return this.messageListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessageListener(MessageListener messageListener) throws JMSException {
|
||||
public void setMessageListener(MessageListener messageListener) {
|
||||
this.messageListener = messageListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message receive() throws JMSException {
|
||||
public Message receive() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message receive(long l) throws JMSException {
|
||||
public Message receive(long l) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message receiveNoWait() throws JMSException {
|
||||
public Message receiveNoWait() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws JMSException {
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user