Polish tests

See gh-27248
This commit is contained in:
Syuziko
2021-08-07 16:10:08 +04:00
committed by Stephane Nicoll
parent ce6217be85
commit eaf9deedfd
36 changed files with 1115 additions and 1121 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -51,7 +51,7 @@ import static org.mockito.Mockito.verify;
* @author Juergen Hoeller
* @author Chris Beams
*/
public class MessageListenerAdapterTests {
class MessageListenerAdapterTests {
private static final String TEXT = "I fancy a good cuppa right now";
@@ -65,7 +65,7 @@ public class MessageListenerAdapterTests {
@Test
public void testWithMessageContentsDelegateForTextMessage() throws Exception {
void testWithMessageContentsDelegateForTextMessage() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
@@ -79,17 +79,14 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageContentsDelegateForBytesMessage() throws Exception {
void testWithMessageContentsDelegateForBytesMessage() throws Exception {
BytesMessage bytesMessage = mock(BytesMessage.class);
// BytesMessage contents must be unwrapped...
given(bytesMessage.getBodyLength()).willReturn(new Long(TEXT.getBytes().length));
given(bytesMessage.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
byte[] bytes = (byte[]) invocation.getArguments()[0];
ByteArrayInputStream inputStream = new ByteArrayInputStream(TEXT.getBytes());
return inputStream.read(bytes);
}
given(bytesMessage.getBodyLength()).willReturn(Long.valueOf(TEXT.getBytes().length));
given(bytesMessage.readBytes(any(byte[].class))).willAnswer((Answer<Integer>) invocation -> {
byte[] bytes = (byte[]) invocation.getArguments()[0];
ByteArrayInputStream inputStream = new ByteArrayInputStream(TEXT.getBytes());
return inputStream.read(bytes);
});
MessageContentsDelegate delegate = mock(MessageContentsDelegate.class);
@@ -101,7 +98,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageContentsDelegateForObjectMessage() throws Exception {
void testWithMessageContentsDelegateForObjectMessage() throws Exception {
ObjectMessage objectMessage = mock(ObjectMessage.class);
given(objectMessage.getObject()).willReturn(NUMBER);
@@ -114,7 +111,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageContentsDelegateForObjectMessageWithPlainObject() throws Exception {
void testWithMessageContentsDelegateForObjectMessageWithPlainObject() throws Exception {
ObjectMessage objectMessage = mock(ObjectMessage.class);
given(objectMessage.getObject()).willReturn(OBJECT);
@@ -127,7 +124,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithMessageDelegate() throws Exception {
void testWithMessageDelegate() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
MessageDelegate delegate = mock(MessageDelegate.class);
@@ -141,7 +138,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWhenTheAdapterItselfIsTheDelegate() throws Exception {
void testWhenTheAdapterItselfIsTheDelegate() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
@@ -152,7 +149,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testRainyDayWithNoApplicableHandlingMethods() throws Exception {
void testRainyDayWithNoApplicableHandlingMethods() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
@@ -164,7 +161,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testThatAnExceptionThrownFromTheHandlingMethodIsSimplySwallowedByDefault() throws Exception {
void testThatAnExceptionThrownFromTheHandlingMethodIsSimplySwallowedByDefault() throws Exception {
final IllegalArgumentException exception = new IllegalArgumentException();
TextMessage textMessage = mock(TextMessage.class);
@@ -189,7 +186,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testThatTheDefaultMessageConverterisIndeedTheSimpleMessageConverter() throws Exception {
void testThatTheDefaultMessageConverterisIndeedTheSimpleMessageConverter() throws Exception {
MessageListenerAdapter adapter = new MessageListenerAdapter();
assertThat(adapter.getMessageConverter()).as("The default [MessageConverter] must never be null.").isNotNull();
boolean condition = adapter.getMessageConverter() instanceof SimpleMessageConverter;
@@ -197,19 +194,19 @@ public class MessageListenerAdapterTests {
}
@Test
public void testThatWhenNoDelegateIsSuppliedTheDelegateIsAssumedToBeTheMessageListenerAdapterItself() throws Exception {
void testThatWhenNoDelegateIsSuppliedTheDelegateIsAssumedToBeTheMessageListenerAdapterItself() throws Exception {
MessageListenerAdapter adapter = new MessageListenerAdapter();
assertThat(adapter.getDelegate()).isSameAs(adapter);
}
@Test
public void testThatTheDefaultMessageHandlingMethodNameIsTheConstantDefault() throws Exception {
void testThatTheDefaultMessageHandlingMethodNameIsTheConstantDefault() throws Exception {
MessageListenerAdapter adapter = new MessageListenerAdapter();
assertThat(adapter.getDefaultListenerMethod()).isEqualTo(MessageListenerAdapter.ORIGINAL_DEFAULT_LISTENER_METHOD);
}
@Test
public void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
given(delegate.handleMessage(textMessage)).willReturn(TEXT);
@@ -221,7 +218,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
Queue destination = mock(Queue.class);
TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
@@ -256,7 +253,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
Queue destination = mock(Queue.class);
TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
@@ -289,7 +286,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
void testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
@@ -318,7 +315,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
Queue destination = mock(Queue.class);
final TextMessage sentTextMessage = mock(TextMessage.class);
@@ -354,7 +351,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateDoesNotSendReturnTextMessageWhenSessionSupplied_AndListenerMethodThrowsException() throws Exception {
void testWithResponsiveMessageDelegateDoesNotSendReturnTextMessageWhenSessionSupplied_AndListenerMethodThrowsException() throws Exception {
final TextMessage message = mock(TextMessage.class);
final QueueSession session = mock(QueueSession.class);
@@ -372,7 +369,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
final Session session = mock(Session.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
@@ -391,7 +388,7 @@ public class MessageListenerAdapterTests {
}
@Test
public void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
Queue destination = mock(Queue.class);
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -49,7 +49,7 @@ import static org.mockito.Mockito.verify;
* @author Dave Syer
* @author Stephane Nicoll
*/
public class MappingJackson2MessageConverterTests {
class MappingJackson2MessageConverterTests {
private MappingJackson2MessageConverter converter;
@@ -66,7 +66,7 @@ public class MappingJackson2MessageConverterTests {
@Test
public void toBytesMessage() throws Exception {
void toBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Date toBeMarshalled = new Date();
@@ -80,7 +80,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromBytesMessage() throws Exception {
void fromBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
@@ -89,21 +89,16 @@ public class MappingJackson2MessageConverterTests {
given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false);
given(bytesMessageMock.getBodyLength()).willReturn(new Long(bytes.length));
given(bytesMessageMock.getBodyLength()).willReturn(Long.valueOf(bytes.length));
given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer(
new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return byteStream.read((byte[]) invocation.getArguments()[0]);
}
});
(Answer<Integer>) invocation -> byteStream.read((byte[]) invocation.getArguments()[0]));
Object result = converter.fromMessage(bytesMessageMock);
assertThat(unmarshalled).as("Invalid result").isEqualTo(result);
}
@Test
public void toTextMessageWithObject() throws Exception {
void toTextMessageWithObject() throws Exception {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
Date toBeMarshalled = new Date();
@@ -115,7 +110,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithMap() throws Exception {
void toTextMessageWithMap() throws Exception {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> toBeMarshalled = new HashMap<>();
@@ -128,7 +123,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessage() throws Exception {
void fromTextMessage() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
MyBean unmarshalled = new MyBean("bar");
@@ -141,7 +136,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessageWithUnknownProperty() throws Exception {
void fromTextMessageWithUnknownProperty() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
MyBean unmarshalled = new MyBean("bar");
@@ -154,7 +149,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessageAsObject() throws Exception {
void fromTextMessageAsObject() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
@@ -167,7 +162,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void fromTextMessageAsMap() throws Exception {
void fromTextMessageAsMap() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
@@ -180,7 +175,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithReturnType() throws JMSException, NoSuchMethodException {
void toTextMessageWithReturnType() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("summary");
MethodParameter returnType = new MethodParameter(method, -1);
testToTextMessageWithReturnType(returnType);
@@ -188,13 +183,13 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithNullReturnType() throws JMSException, NoSuchMethodException {
void toTextMessageWithNullReturnType() throws JMSException, NoSuchMethodException {
testToTextMessageWithReturnType(null);
verify(sessionMock).createTextMessage("{\"name\":\"test\",\"description\":\"lengthy description\"}");
}
@Test
public void toTextMessageWithReturnTypeAndNoJsonView() throws JMSException, NoSuchMethodException {
void toTextMessageWithReturnTypeAndNoJsonView() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("none");
MethodParameter returnType = new MethodParameter(method, -1);
@@ -203,7 +198,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithReturnTypeAndMultipleJsonViews() throws JMSException, NoSuchMethodException {
void toTextMessageWithReturnTypeAndMultipleJsonViews() throws JMSException, NoSuchMethodException {
Method method = this.getClass().getDeclaredMethod("invalid");
MethodParameter returnType = new MethodParameter(method, -1);
@@ -222,7 +217,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithJsonViewClass() throws JMSException {
void toTextMessageWithJsonViewClass() throws JMSException {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
@@ -236,7 +231,7 @@ public class MappingJackson2MessageConverterTests {
}
@Test
public void toTextMessageWithAnotherJsonViewClass() throws JMSException {
void toTextMessageWithAnotherJsonViewClass() throws JMSException {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);