You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by va...@apache.org on 2023/05/24 06:46:07 UTC
[qpid-broker-j] branch main updated: QPID-8645: [Broker-J] JUnit 5 tests refactoring for broker-plugins/amqp-0-8-protocol (#183)
This is an automated email from the ASF dual-hosted git repository.
vavrtom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
The following commit(s) were added to refs/heads/main by this push:
new 00b8e0d05c QPID-8645: [Broker-J] JUnit 5 tests refactoring for broker-plugins/amqp-0-8-protocol (#183)
00b8e0d05c is described below
commit 00b8e0d05cf747a2f1af7895a5ebabf0b44d3255
Author: Daniil Kirilyuk <da...@gmail.com>
AuthorDate: Wed May 24 08:46:03 2023 +0200
QPID-8645: [Broker-J] JUnit 5 tests refactoring for broker-plugins/amqp-0-8-protocol (#183)
---
.../org/apache/qpid/server/QpidExceptionTest.java | 44 ++--
.../qpid/server/protocol/v0_8/AMQChannelTest.java | 81 +++---
.../qpid/server/protocol/v0_8/AMQDecoderTest.java | 116 +++++----
.../protocol/v0_8/AMQMessageMutatorTest.java | 33 ++-
.../protocol/v0_8/AMQPConnection_0_8Test.java | 74 +++---
.../server/protocol/v0_8/AMQShortStringTest.java | 111 ++++-----
.../qpid/server/protocol/v0_8/AMQTypeTest.java | 9 +-
.../qpid/server/protocol/v0_8/ClientDecoder.java | 33 +--
.../server/protocol/v0_8/EncodingUtilsTest.java | 24 +-
.../qpid/server/protocol/v0_8/FieldTableTest.java | 273 ++++++++------------
.../v0_8/MessageConverter_0_8_to_InternalTest.java | 109 ++++----
.../v0_8/MessageConverter_Internal_to_0_8Test.java | 87 ++++---
.../protocol/v0_8/MessageMetaDataFactoryTest.java | 14 +-
.../protocol/v0_8/Pre0_10CreditManagerTest.java | 21 +-
.../PropertyConverter_Internal_to_v0_8Test.java | 275 +++++++++------------
.../PropertyConverter_v0_8_to_InternalTest.java | 139 ++++++-----
.../protocol/v0_8/ReferenceCountingTest.java | 45 ++--
.../v0_8/UnacknowledgedMessageMapTest.java | 38 +--
.../BasicContentHeaderPropertiesTest.java | 89 ++++---
.../v0_8/transport/MessagePublishInfoImplTest.java | 23 +-
20 files changed, 731 insertions(+), 907 deletions(-)
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/QpidExceptionTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/QpidExceptionTest.java
index 07c565f7f8..091c2d3a5a 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/QpidExceptionTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/QpidExceptionTest.java
@@ -30,7 +30,6 @@ import org.apache.qpid.server.protocol.v0_8.AMQFrameDecodingException;
import org.apache.qpid.server.protocol.v0_8.AMQShortString;
import org.apache.qpid.test.utils.UnitTestBase;
-
/**
* This test is to ensure that when an AMQException is rethrown that the specified exception is correctly wrapped up.
* <p>
@@ -40,17 +39,17 @@ import org.apache.qpid.test.utils.UnitTestBase;
* Re-throwing a Subclass of AMQException that does not have the default AMQException constructor which will force the
* creation of an AMQException.
*/
-public class QpidExceptionTest extends UnitTestBase
+class QpidExceptionTest extends UnitTestBase
{
/**
* Test that an AMQException will be correctly created and rethrown.
*/
@Test
- public void testRethrowGeneric()
+ void rethrowGeneric()
{
- QpidException test = new QpidException("refused", new RuntimeException());
+ final QpidException test = new QpidException("refused", new RuntimeException());
- QpidException e = reThrowException(test);
+ final QpidException e = reThrowException(test);
assertEquals(QpidException.class, e.getClass(), "Exception not of correct class");
}
@@ -59,12 +58,10 @@ public class QpidExceptionTest extends UnitTestBase
* Test that a subclass of AMQException that has the default constructor will be correctly created and rethrown.
*/
@Test
- public void testRethrowAMQESubclass()
+ void rethrowAMQESubclass()
{
- AMQFrameDecodingException test = new AMQFrameDecodingException(
- "Error",
- new Exception());
- QpidException e = reThrowException(test);
+ final AMQFrameDecodingException test = new AMQFrameDecodingException("Error", new Exception());
+ final QpidException e = reThrowException(test);
assertEquals(AMQFrameDecodingException.class, e.getClass(), "Exception not of correct class");
}
@@ -74,11 +71,11 @@ public class QpidExceptionTest extends UnitTestBase
* AMQException
*/
@Test
- public void testRethrowAMQESubclassNoConstructor()
+ void rethrowAMQESubclassNoConstructor()
{
- AMQExceptionSubclass test = new AMQExceptionSubclass("Invalid Argument Exception");
+ final AMQExceptionSubclass test = new AMQExceptionSubclass("Invalid Argument Exception");
- QpidException e = reThrowException(test);
+ final QpidException e = reThrowException(test);
assertEquals(QpidException.class, e.getClass(), "Exception not of correct class");
}
@@ -86,16 +83,14 @@ public class QpidExceptionTest extends UnitTestBase
/**
* Private method to rethrown and validate the basic values of the rethrown
* @param test Exception to rethrow
- * @throws QpidException the rethrown exception
*/
- private QpidException reThrowException(QpidException test)
+ private QpidException reThrowException(final QpidException test)
{
- QpidException amqe = test.cloneForCurrentThread();
- if(test instanceof AMQException)
+ final QpidException amqe = test.cloneForCurrentThread();
+ if (test instanceof AMQException)
{
assertEquals(((AMQException) test).getErrorCode(), (long) ((AMQException) amqe).getErrorCode(),
"Error code does not match.");
-
}
assertTrue(amqe.getMessage().startsWith(test.getMessage()), "Exception message does not start as expected.");
assertEquals(test, amqe.getCause(), "Test Exception is not set as the cause");
@@ -105,15 +100,15 @@ public class QpidExceptionTest extends UnitTestBase
}
@Test
- public void testGetMessageAsString()
+ void getMessageAsString()
{
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
for (int i = 0; i < 25; i++)
{
- sb.append("message [" + i + "]");
+ sb.append("message [").append(i).append("]");
}
- AMQException e = new AMQException(ErrorCodes.INTERNAL_ERROR, sb.toString(), null);
- AMQShortString message = AMQShortString.validValueOf(e.getMessage());
+ final AMQException e = new AMQException(ErrorCodes.INTERNAL_ERROR, sb.toString(), null);
+ final AMQShortString message = AMQShortString.validValueOf(e.getMessage());
assertEquals(sb.substring(0, AMQShortString.MAX_LENGTH - 3) + "...", message.toString());
}
@@ -122,8 +117,7 @@ public class QpidExceptionTest extends UnitTestBase
*/
private static class AMQExceptionSubclass extends QpidException
{
-
- public AMQExceptionSubclass(String msg)
+ public AMQExceptionSubclass(final String msg)
{
super(msg, null);
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQChannelTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQChannelTest.java
index e7d656aef8..2501a98af2 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQChannelTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQChannelTest.java
@@ -34,7 +34,6 @@ import static org.mockito.Mockito.when;
import java.security.AccessControlException;
import java.security.Principal;
-import java.util.Collections;
import java.util.Set;
import javax.security.auth.Subject;
@@ -69,7 +68,8 @@ import org.apache.qpid.server.store.StoredMemoryMessage;
import org.apache.qpid.server.virtualhost.QueueManagingVirtualHost;
import org.apache.qpid.test.utils.UnitTestBase;
-public class AMQChannelTest extends UnitTestBase
+@SuppressWarnings({"rawtypes", "unchecked"})
+class AMQChannelTest extends UnitTestBase
{
public static final AMQShortString ROUTING_KEY = AMQShortString.valueOf("routingKey");
@@ -79,12 +79,11 @@ public class AMQChannelTest extends UnitTestBase
private MessageDestination _messageDestination;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
+ final TaskExecutor taskExecutor = mock(TaskExecutor.class);
- TaskExecutor taskExecutor = mock(TaskExecutor.class);
-
- Broker<?> broker = mock(Broker.class);
+ final Broker<?> broker = mock(Broker.class);
when(broker.getEventLogger()).thenReturn(mock(EventLogger.class));
when(broker.getContextValue(Long.class, Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT)).thenReturn(1L);
@@ -97,16 +96,16 @@ public class AMQChannelTest extends UnitTestBase
when(_virtualHost.getPrincipal()).thenReturn(mock(Principal.class));
when(_virtualHost.getEventLogger()).thenReturn(mock(EventLogger.class));
- AmqpPort<?> port = mock(AmqpPort.class);
+ final AmqpPort<?> port = mock(AmqpPort.class);
when(port.getChildExecutor()).thenReturn(taskExecutor);
when(port.getModel()).thenReturn(BrokerModel.getInstance());
when(port.getContextValue(Integer.class, Connection.MAX_MESSAGE_SIZE)).thenReturn(1);
- AuthenticatedPrincipal authenticatedPrincipal = new AuthenticatedPrincipal(new UsernamePrincipal("user", null));
- Set<Principal> authenticatedUser = Collections.singleton(authenticatedPrincipal);
- Subject authenticatedSubject = new Subject(true, authenticatedUser, Collections.<Principal>emptySet(), Collections.<Principal>emptySet());
+ final AuthenticatedPrincipal authenticatedPrincipal = new AuthenticatedPrincipal(new UsernamePrincipal("user", null));
+ final Set<Principal> authenticatedUser = Set.of(authenticatedPrincipal);
+ final Subject authenticatedSubject = new Subject(true, authenticatedUser, Set.of(), Set.of());
- ProtocolOutputConverter protocolOutputConverter = mock(ProtocolOutputConverter.class);
+ final ProtocolOutputConverter protocolOutputConverter = mock(ProtocolOutputConverter.class);
_amqConnection = mock(AMQPConnection_0_8.class);
when(_amqConnection.getSubject()).thenReturn(authenticatedSubject);
@@ -132,75 +131,72 @@ public class AMQChannelTest extends UnitTestBase
}
@Test
- public void testReceiveExchangeDeleteWhenIfUsedIsSetAndExchangeHasBindings()
+ void receiveExchangeDeleteWhenIfUsedIsSetAndExchangeHasBindings()
{
- String testExchangeName = getTestName();
- Exchange<?> exchange = mock(Exchange.class);
+ final String testExchangeName = getTestName();
+ final Exchange<?> exchange = mock(Exchange.class);
when(exchange.hasBindings()).thenReturn(true);
doReturn(exchange).when(_virtualHost).getAttainedMessageDestination(eq(testExchangeName), anyBoolean());
- AMQChannel channel = new AMQChannel(_amqConnection, 1, _messageStore);
+ final AMQChannel channel = new AMQChannel(_amqConnection, 1, _messageStore);
channel.receiveExchangeDelete(AMQShortString.valueOf(testExchangeName), true, false);
- verify(_amqConnection).closeChannelAndWriteFrame(eq(channel),
- eq(ErrorCodes.IN_USE),
- eq("Exchange has bindings"));
+ verify(_amqConnection).closeChannelAndWriteFrame(channel, ErrorCodes.IN_USE, "Exchange has bindings");
}
@Test
- public void testReceiveExchangeDeleteWhenIfUsedIsSetAndExchangeHasNoBinding()
+ void receiveExchangeDeleteWhenIfUsedIsSetAndExchangeHasNoBinding()
{
- Exchange<?> exchange = mock(Exchange.class);
+ final Exchange<?> exchange = mock(Exchange.class);
when(exchange.hasBindings()).thenReturn(false);
doReturn(exchange).when(_virtualHost).getAttainedMessageDestination(eq(getTestName()), anyBoolean());
- AMQChannel channel = new AMQChannel(_amqConnection, 1, _messageStore);
+ final AMQChannel channel = new AMQChannel(_amqConnection, 1, _messageStore);
channel.receiveExchangeDelete(AMQShortString.valueOf(getTestName()), true, false);
verify(exchange).delete();
}
@Test
- public void testOversizedMessageClosesChannel()
+ void oversizedMessageClosesChannel()
{
when(_virtualHost.getDefaultDestination()).thenReturn(mock(MessageDestination.class));
- long maximumMessageSize = 1024L;
+ final long maximumMessageSize = 1024L;
when(_amqConnection.getMaxMessageSize()).thenReturn(maximumMessageSize);
- AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
+ final AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
- BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, AMQShortString.EMPTY_STRING, false, false);
channel.receiveMessageHeader(properties, maximumMessageSize + 1);
- verify(_amqConnection).closeChannelAndWriteFrame(eq(channel),
- eq(ErrorCodes.MESSAGE_TOO_LARGE),
- eq("Message size of 1025 greater than allowed maximum of 1024"));
+ verify(_amqConnection).closeChannelAndWriteFrame(channel,
+ ErrorCodes.MESSAGE_TOO_LARGE,
+ "Message size of 1025 greater than allowed maximum of 1024");
}
@Test
- public void testPublishContentHeaderWhenMessageAuthorizationFails()
+ void publishContentHeaderWhenMessageAuthorizationFails()
{
final String impostorId = "impostor";
- doThrow(new AccessControlException("fail")).when(_amqConnection).checkAuthorizedMessagePrincipal(eq(impostorId));
+ doThrow(new AccessControlException("fail")).when(_amqConnection).checkAuthorizedMessagePrincipal(impostorId);
when(_virtualHost.getDefaultDestination()).thenReturn(mock(MessageDestination.class));
when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore()
{
@Override
public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData)
{
- MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
- return messageHandle;
+ return (MessageHandle) new StoredMemoryMessage(1, metaData);
}
});
- int channelId = 1;
- AMQChannel channel = new AMQChannel(_amqConnection, channelId, _virtualHost.getMessageStore());
+ final int channelId = 1;
+ final AMQChannel channel = new AMQChannel(_amqConnection, channelId, _virtualHost.getMessageStore());
- BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
properties.setUserId(impostorId);
channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, AMQShortString.EMPTY_STRING, false, false);
channel.receiveMessageHeader(properties, 0);
@@ -210,7 +206,7 @@ public class AMQChannelTest extends UnitTestBase
}
@Test
- public void testPublishContentHeaderWhenMessageAuthorizationSucceeds()
+ void publishContentHeaderWhenMessageAuthorizationSucceeds()
{
when(_virtualHost.getDefaultDestination()).thenReturn(_messageDestination);
when(_virtualHost.getMessageStore()).thenReturn(new NullMessageStore()
@@ -218,25 +214,22 @@ public class AMQChannelTest extends UnitTestBase
@Override
public <T extends StorableMessageMetaData> MessageHandle<T> addMessage(final T metaData)
{
- MessageHandle messageHandle = new StoredMemoryMessage(1, metaData);
- return messageHandle;
+ return (MessageHandle) new StoredMemoryMessage(1, metaData);
}
});
final ArgumentCaptor<ServerMessage> messageCaptor = ArgumentCaptor.forClass(ServerMessage.class);
doAnswer(invocation ->
{
- ServerMessage message = messageCaptor.getValue();
+ final ServerMessage message = messageCaptor.getValue();
return new RoutingResult(message);
}).when(_messageDestination).route(messageCaptor.capture(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
- AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
+ final AMQChannel channel = new AMQChannel(_amqConnection, 1, _virtualHost.getMessageStore());
- BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
properties.setUserId(_amqConnection.getAuthorizedPrincipal().getName());
channel.receiveBasicPublish(AMQShortString.EMPTY_STRING, ROUTING_KEY, false, false);
channel.receiveMessageHeader(properties, 0);
- verify(_messageDestination).route((ServerMessage) any(),
- eq(ROUTING_KEY.toString()),
- any(InstanceProperties.class));
+ verify(_messageDestination).route((ServerMessage) any(), eq(ROUTING_KEY.toString()), any(InstanceProperties.class));
}
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQDecoderTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQDecoderTest.java
index 8f7daf3045..c3648b88c2 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQDecoderTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQDecoderTest.java
@@ -25,12 +25,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import java.nio.ByteBuffer;
+import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Random;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -49,38 +48,36 @@ import org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody;
import org.apache.qpid.server.transport.ByteBufferSender;
import org.apache.qpid.test.utils.UnitTestBase;
-public class AMQDecoderTest extends UnitTestBase
+class AMQDecoderTest extends UnitTestBase
{
private static final ByteBuffer EMPTY_BYTE_BUFFER = ByteBuffer.allocate(0);
private ClientDecoder _decoder;
private FrameCreatingMethodProcessor _methodProcessor;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
_methodProcessor = new FrameCreatingMethodProcessor(ProtocolVersion.v0_91);
_decoder = new ClientDecoder(_methodProcessor);
}
-
private ByteBuffer getHeartbeatBodyBuffer()
{
- TestSender sender = new TestSender();
+ final TestSender sender = new TestSender();
HeartbeatBody.FRAME.writePayload(sender);
return combine(sender.getSentBuffers());
}
@Test
- public void testSingleFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
+ void singleFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
{
- ByteBuffer msg = getHeartbeatBodyBuffer();
+ final ByteBuffer msg = getHeartbeatBodyBuffer();
_decoder.decodeBuffer(msg);
- List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
+ final List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
if (frames.get(0) instanceof AMQFrame)
{
assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(),
(long) ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
-
}
else
{
@@ -88,29 +85,27 @@ public class AMQDecoderTest extends UnitTestBase
}
}
-
@Test
- public void testContentHeaderPropertiesFrame() throws AMQProtocolVersionException, AMQFrameDecodingException
+ void contentHeaderPropertiesFrame() throws AMQProtocolVersionException, AMQFrameDecodingException
{
final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
- Map<String, Object> headersMap = new LinkedHashMap<>();
- headersMap.put("hello","world");
- headersMap.put("1+1=",2);
+ final Map<String, Object> headersMap = Map.of("hello", "world",
+ "1+1=", 2);
final FieldTable table = FieldTableFactory.createFieldTable(headersMap);
props.setHeaders(table);
final AMQBody body = new ContentHeaderBody(props);
- AMQFrame frame = new AMQFrame(1, body);
- TestSender sender = new TestSender();
+ final AMQFrame frame = new AMQFrame(1, body);
+ final TestSender sender = new TestSender();
frame.writePayload(sender);
- ByteBuffer msg = combine(sender.getSentBuffers());
+ final ByteBuffer msg = combine(sender.getSentBuffers());
_decoder.decodeBuffer(msg);
- List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
- AMQDataBlock firstFrame = frames.get(0);
+ final List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
+ final AMQDataBlock firstFrame = frames.get(0);
if (firstFrame instanceof AMQFrame)
{
assertEquals(ContentHeaderBody.TYPE, (long) ((AMQFrame) firstFrame).getBodyFrame().getFrameType());
- BasicContentHeaderProperties decodedProps = ((ContentHeaderBody)((AMQFrame)firstFrame).getBodyFrame()).getProperties();
+ final BasicContentHeaderProperties decodedProps = ((ContentHeaderBody)((AMQFrame)firstFrame).getBodyFrame()).getProperties();
final Map<String, Object> headers = decodedProps.getHeadersAsMap();
assertEquals("world", headers.get("hello"));
}
@@ -122,32 +117,31 @@ public class AMQDecoderTest extends UnitTestBase
@Test
- public void testDecodeWithManyBuffers() throws AMQProtocolVersionException, AMQFrameDecodingException
+ void decodeWithManyBuffers() throws AMQProtocolVersionException, AMQFrameDecodingException
{
- Random random = new Random();
+ final SecureRandom random = new SecureRandom();
final byte[] payload = new byte[2048];
random.nextBytes(payload);
final AMQBody body = new ContentBody(ByteBuffer.wrap(payload));
- AMQFrame frame = new AMQFrame(1, body);
- TestSender sender = new TestSender();
+ final AMQFrame frame = new AMQFrame(1, body);
+ final TestSender sender = new TestSender();
frame.writePayload(sender);
- ByteBuffer allData = combine(sender.getSentBuffers());
+ final ByteBuffer allData = combine(sender.getSentBuffers());
-
- for(int i = 0 ; i < allData.remaining(); i++)
+ for (int i = 0 ; i < allData.remaining(); i++)
{
- byte[] minibuf = new byte[1];
+ final byte[] minibuf = new byte[1];
minibuf[0] = allData.get(i);
_decoder.decodeBuffer(ByteBuffer.wrap(minibuf));
}
- List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
+ final List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
if (frames.get(0) instanceof AMQFrame)
{
assertEquals(ContentBody.TYPE, (long) ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
- ContentBody decodedBody = (ContentBody) ((AMQFrame) frames.get(0)).getBodyFrame();
+ final ContentBody decodedBody = (ContentBody) ((AMQFrame) frames.get(0)).getBodyFrame();
byte[] bodyBytes;
- try (QpidByteBuffer payloadBuffer = decodedBody.getPayload())
+ try (final QpidByteBuffer payloadBuffer = decodedBody.getPayload())
{
bodyBytes = new byte[payloadBuffer.remaining()];
payloadBuffer.get(bodyBytes);
@@ -161,18 +155,18 @@ public class AMQDecoderTest extends UnitTestBase
}
@Test
- public void testPartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
+ void partialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
{
- ByteBuffer msg = getHeartbeatBodyBuffer();
- ByteBuffer msgA = msg.slice();
- int msgbPos = msg.remaining() / 2;
- int msgaLimit = msg.remaining() - msgbPos;
+ final ByteBuffer msg = getHeartbeatBodyBuffer();
+ final ByteBuffer msgA = msg.slice();
+ final int msgbPos = msg.remaining() / 2;
+ final int msgaLimit = msg.remaining() - msgbPos;
msgA.limit(msgaLimit);
msg.position(msgbPos);
- ByteBuffer msgB = msg.slice();
+ final ByteBuffer msgB = msg.slice();
_decoder.decodeBuffer(msgA);
- List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
+ final List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
assertEquals(0, (long) frames.size());
_decoder.decodeBuffer(msgB);
@@ -189,18 +183,18 @@ public class AMQDecoderTest extends UnitTestBase
}
@Test
- public void testMultipleFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
+ void multipleFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
{
- ByteBuffer msgA = getHeartbeatBodyBuffer();
- ByteBuffer msgB = getHeartbeatBodyBuffer();
- ByteBuffer msg = ByteBuffer.allocate(msgA.remaining() + msgB.remaining());
+ final ByteBuffer msgA = getHeartbeatBodyBuffer();
+ final ByteBuffer msgB = getHeartbeatBodyBuffer();
+ final ByteBuffer msg = ByteBuffer.allocate(msgA.remaining() + msgB.remaining());
msg.put(msgA);
msg.put(msgB);
msg.flip();
_decoder.decodeBuffer(msg);
- List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
+ final List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
assertEquals(2, (long) frames.size());
- for (AMQDataBlock frame : frames)
+ for (final AMQDataBlock frame : frames)
{
if (frame instanceof AMQFrame)
{
@@ -215,23 +209,23 @@ public class AMQDecoderTest extends UnitTestBase
}
@Test
- public void testMultiplePartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
+ void multiplePartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException
{
- ByteBuffer msgA = getHeartbeatBodyBuffer();
- ByteBuffer msgB = getHeartbeatBodyBuffer();
- ByteBuffer msgC = getHeartbeatBodyBuffer();
+ final ByteBuffer msgA = getHeartbeatBodyBuffer();
+ final ByteBuffer msgB = getHeartbeatBodyBuffer();
+ final ByteBuffer msgC = getHeartbeatBodyBuffer();
- ByteBuffer sliceA = ByteBuffer.allocate(msgA.remaining() + msgB.remaining() / 2);
+ final ByteBuffer sliceA = ByteBuffer.allocate(msgA.remaining() + msgB.remaining() / 2);
sliceA.put(msgA);
- int limit = msgB.limit();
- int pos = msgB.remaining() / 2;
+ final int limit = msgB.limit();
+ final int pos = msgB.remaining() / 2;
msgB.limit(pos);
sliceA.put(msgB);
sliceA.flip();
msgB.limit(limit);
msgB.position(pos);
- ByteBuffer sliceB = ByteBuffer.allocate(msgB.remaining() + pos);
+ final ByteBuffer sliceB = ByteBuffer.allocate(msgB.remaining() + pos);
sliceB.put(msgB);
msgC.limit(pos);
sliceB.put(msgC);
@@ -239,7 +233,7 @@ public class AMQDecoderTest extends UnitTestBase
msgC.limit(limit);
_decoder.decodeBuffer(sliceA);
- List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
+ final List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
assertEquals(1, (long) frames.size());
frames.clear();
_decoder.decodeBuffer(sliceB);
@@ -247,7 +241,7 @@ public class AMQDecoderTest extends UnitTestBase
frames.clear();
_decoder.decodeBuffer(msgC);
assertEquals(1, (long) frames.size());
- for (AMQDataBlock frame : frames)
+ for (final AMQDataBlock frame : frames)
{
if (frame instanceof AMQFrame)
{
@@ -263,8 +257,8 @@ public class AMQDecoderTest extends UnitTestBase
private static class TestSender implements ByteBufferSender
{
-
private final Collection<QpidByteBuffer> _sentBuffers = new ArrayList<>();
+
@Override
public boolean isDirectBufferPreferred()
{
@@ -297,9 +291,9 @@ public class AMQDecoderTest extends UnitTestBase
}
- private static ByteBuffer combine(Collection<QpidByteBuffer> bufs)
+ private static ByteBuffer combine(final Collection<QpidByteBuffer> bufs)
{
- if(bufs == null || bufs.isEmpty())
+ if (bufs == null || bufs.isEmpty())
{
return EMPTY_BYTE_BUFFER;
}
@@ -307,14 +301,14 @@ public class AMQDecoderTest extends UnitTestBase
{
int size = 0;
boolean isDirect = false;
- for(QpidByteBuffer buf : bufs)
+ for (final QpidByteBuffer buf : bufs)
{
size += buf.remaining();
isDirect = isDirect || buf.isDirect();
}
- ByteBuffer combined = isDirect ? ByteBuffer.allocateDirect(size) : ByteBuffer.allocate(size);
+ final ByteBuffer combined = isDirect ? ByteBuffer.allocateDirect(size) : ByteBuffer.allocate(size);
- for(QpidByteBuffer buf : bufs)
+ for (final QpidByteBuffer buf : bufs)
{
buf.copyTo(combined);
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQMessageMutatorTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQMessageMutatorTest.java
index 114559488f..e6f7cba9c6 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQMessageMutatorTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQMessageMutatorTest.java
@@ -25,7 +25,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import java.util.Collections;
+import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -40,56 +40,56 @@ import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.store.TestMemoryMessageStore;
import org.apache.qpid.test.utils.UnitTestBase;
-public class AMQMessageMutatorTest extends UnitTestBase
+class AMQMessageMutatorTest extends UnitTestBase
{
private static final byte TEST_PRIORITY = (byte) 1;
private static final String TEST_HEADER_NAME = "foo";
private static final String TEST_HEADER_VALUE = "bar";
private static final String TEST_CONTENT_TYPE = "text/plain";
private static final String TEST_CONTENT = "testContent";
+
private MessageStore _messageStore;
private AMQMessageMutator _messageMutator;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
_messageStore = new TestMemoryMessageStore();
final AMQMessage message = createTestMessage();
_messageMutator = new AMQMessageMutator(message, _messageStore);
}
-
@AfterEach
- public void tearDown()
+ void tearDown()
{
_messageStore.closeMessageStore();
}
@Test
- public void setPriority()
+ void setPriority()
{
_messageMutator.setPriority((byte) (TEST_PRIORITY + 1));
assertThat(_messageMutator.getPriority(), is(equalTo((byte) (TEST_PRIORITY + 1))));
}
@Test
- public void getPriority()
+ void getPriority()
{
assertThat((int) _messageMutator.getPriority(), is(equalTo((int) TEST_PRIORITY)));
}
@Test
- public void create()
+ void create()
{
_messageMutator.setPriority((byte) (TEST_PRIORITY + 1));
- AMQMessage newMessage = _messageMutator.create();
+ final AMQMessage newMessage = _messageMutator.create();
assertThat(newMessage.getMessageHeader().getPriority(), is(equalTo((byte) (TEST_PRIORITY + 1))));
assertThat(newMessage.getMessageHeader().getMimeType(), is(equalTo(TEST_CONTENT_TYPE)));
assertThat(newMessage.getMessageHeader().getHeader(TEST_HEADER_NAME), is(equalTo(TEST_HEADER_VALUE)));
- QpidByteBuffer content = newMessage.getContent();
+ final QpidByteBuffer content = newMessage.getContent();
final byte[] bytes = new byte[content.remaining()];
content.copyTo(bytes);
@@ -100,18 +100,17 @@ public class AMQMessageMutatorTest extends UnitTestBase
{
final BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
basicContentHeaderProperties.setPriority(TEST_PRIORITY);
- basicContentHeaderProperties.setHeaders(FieldTableFactory.createFieldTable(Collections.singletonMap(
- TEST_HEADER_NAME,
- TEST_HEADER_VALUE)));
+ basicContentHeaderProperties
+ .setHeaders(FieldTableFactory.createFieldTable(Map.of(TEST_HEADER_NAME, TEST_HEADER_VALUE)));
basicContentHeaderProperties.setContentType(TEST_CONTENT_TYPE);
- QpidByteBuffer content = QpidByteBuffer.wrap(TEST_CONTENT.getBytes(UTF_8));
+ final QpidByteBuffer content = QpidByteBuffer.wrap(TEST_CONTENT.getBytes(UTF_8));
final ContentHeaderBody contentHeader = new ContentHeaderBody(basicContentHeaderProperties, content.remaining());
final MessagePublishInfo publishInfo = new MessagePublishInfo(AMQShortString.valueOf("testExchange"),
- true,
- true,
- AMQShortString.valueOf("testRoutingKey"));
+ true,
+ true,
+ AMQShortString.valueOf("testRoutingKey"));
final MessageMetaData messageMetaData =
new MessageMetaData(publishInfo, contentHeader, System.currentTimeMillis());
final MessageHandle<MessageMetaData> handle = _messageStore.addMessage(messageMetaData);
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Test.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Test.java
index 8833699d07..a7912a3b72 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Test.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQPConnection_0_8Test.java
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.InetSocketAddress;
-import java.util.Collections;
+import java.util.List;
import java.util.Map;
import javax.security.auth.Subject;
@@ -73,7 +73,8 @@ import org.apache.qpid.server.virtualhost.QueueManagingVirtualHost;
import org.apache.qpid.server.virtualhost.VirtualHostPrincipal;
import org.apache.qpid.test.utils.UnitTestBase;
-public class AMQPConnection_0_8Test extends UnitTestBase
+@SuppressWarnings({"rawtypes"})
+class AMQPConnection_0_8Test extends UnitTestBase
{
private static final String VIRTUAL_HOST_NAME = "vhost";
private static final byte[] SASL_RESPONSE = "response".getBytes();
@@ -82,7 +83,6 @@ public class AMQPConnection_0_8Test extends UnitTestBase
private TaskExecutorImpl _taskExecutor;
private Broker _broker;
- private VirtualHostNode _virtualHostNode;
private QueueManagingVirtualHost _virtualHost;
private AmqpPort _port;
private ServerNetworkConnection _network;
@@ -91,18 +91,17 @@ public class AMQPConnection_0_8Test extends UnitTestBase
private AggregateTicker _ticker;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
+ final EventLogger value = new EventLogger();
- EventLogger value = new EventLogger();
-
- SystemConfig systemConfig = mock(SystemConfig.class);
+ final SystemConfig systemConfig = mock(SystemConfig.class);
when(systemConfig.getEventLogger()).thenReturn(mock(EventLogger.class));
_taskExecutor = new TaskExecutorImpl();
_taskExecutor.start();
- Model model = BrokerModel.getInstance();
+ final Model model = BrokerModel.getInstance();
_broker = mock(Broker.class);
when(_broker.getParent()).thenReturn(systemConfig);
@@ -111,18 +110,18 @@ public class AMQPConnection_0_8Test extends UnitTestBase
when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
when(_broker.getChildExecutor()).thenReturn(_taskExecutor);
when(_broker.getEventLogger()).thenReturn(value);
- when(_broker.getContextValue(eq(Long.class), eq(Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT))).thenReturn(0L);
+ when(_broker.getContextValue(Long.class, Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT)).thenReturn(0L);
- _virtualHostNode = mock(VirtualHostNode.class);
- when(_virtualHostNode.getParent()).thenReturn(_broker);
- when(_virtualHostNode.getModel()).thenReturn(model);
- when(_virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
- when(_virtualHostNode.getTaskExecutor()).thenReturn(_taskExecutor);
- when(_virtualHostNode.getChildExecutor()).thenReturn(_taskExecutor);
+ final VirtualHostNode virtualHostNode = mock(VirtualHostNode.class);
+ when(virtualHostNode.getParent()).thenReturn(_broker);
+ when(virtualHostNode.getModel()).thenReturn(model);
+ when(virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
+ when(virtualHostNode.getTaskExecutor()).thenReturn(_taskExecutor);
+ when(virtualHostNode.getChildExecutor()).thenReturn(_taskExecutor);
_virtualHost = mock(QueueManagingVirtualHost.class);
- VirtualHostPrincipal virtualHostPrincipal = new VirtualHostPrincipal(_virtualHost);
- when(_virtualHost.getParent()).thenReturn(_virtualHostNode);
+ final VirtualHostPrincipal virtualHostPrincipal = new VirtualHostPrincipal(_virtualHost);
+ when(_virtualHost.getParent()).thenReturn(virtualHostNode);
when(_virtualHost.getModel()).thenReturn(model);
when(_virtualHost.getCategoryClass()).thenReturn(VirtualHost.class);
when(_virtualHost.getState()).thenReturn(State.ACTIVE);
@@ -136,16 +135,15 @@ public class AMQPConnection_0_8Test extends UnitTestBase
when(_virtualHost.authoriseCreateConnection(any(AMQPConnection.class))).thenReturn(true);
when(_virtualHost.getEventLogger()).thenReturn(value);
- SubjectCreator subjectCreator = mock(SubjectCreator.class);
-
+ final SubjectCreator subjectCreator = mock(SubjectCreator.class);
- SaslNegotiator saslNegotiator = mock(SaslNegotiator.class);
+ final SaslNegotiator saslNegotiator = mock(SaslNegotiator.class);
when(subjectCreator.createSaslNegotiator(eq(SASL_MECH.toString()), any(SaslSettings.class))).thenReturn(saslNegotiator);
when(subjectCreator.authenticate(saslNegotiator, SASL_RESPONSE)).thenReturn(new SubjectAuthenticationResult(
new AuthenticationResult(new AuthenticatedPrincipal(new UsernamePrincipal("username", null))), new Subject()));
- AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
- when(authenticationProvider.getAvailableMechanisms(anyBoolean())).thenReturn(Collections.singletonList(SASL_MECH.toString()));
+ final AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
+ when(authenticationProvider.getAvailableMechanisms(anyBoolean())).thenReturn(List.of(SASL_MECH.toString()));
_port = mock(AmqpPort.class);
when(_port.getParent()).thenReturn(_broker);
@@ -158,7 +156,7 @@ public class AMQPConnection_0_8Test extends UnitTestBase
when(_port.getContextValue(Integer.class, Connection.MAX_MESSAGE_SIZE)).thenReturn(Connection.DEFAULT_MAX_MESSAGE_SIZE);
when(_port.getSubjectCreator(eq(false), anyString())).thenReturn(subjectCreator);
- ByteBufferSender sender = mock(ByteBufferSender.class);
+ final ByteBufferSender sender = mock(ByteBufferSender.class);
_network = mock(ServerNetworkConnection.class);
when(_network.getSender()).thenReturn(sender);
@@ -171,57 +169,55 @@ public class AMQPConnection_0_8Test extends UnitTestBase
}
@AfterEach
- public void tearDown() throws Exception
+ void tearDown()
{
_taskExecutor.stopImmediately();
}
@Test
- public void testCloseOnNoRoute()
+ void closeOnNoRoute()
{
{
- AMQPConnection_0_8Impl
+ final AMQPConnection_0_8Impl
conn = new AMQPConnection_0_8Impl(_broker, _network, _port, _transport, _protocol, 0, _ticker);
conn.create();
conn.receiveProtocolHeader(new ProtocolInitiation(ProtocolVersion.v0_8));
- FieldTable startFieldTable = FieldTable.convertToFieldTable(Collections.singletonMap(
- ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE,
- Boolean.TRUE));
+ final FieldTable startFieldTable = FieldTable
+ .convertToFieldTable(Map.of(ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE, Boolean.TRUE));
conn.receiveConnectionStartOk(startFieldTable, SASL_MECH, SASL_RESPONSE, LOCALE);
assertTrue(conn.isCloseWhenNoRoute(), "Unexpected closeWhenNoRoute value");
}
{
- AMQPConnection_0_8Impl
+ final AMQPConnection_0_8Impl
conn = new AMQPConnection_0_8Impl(_broker, _network, _port, _transport, _protocol, 0, _ticker);
conn.create();
conn.receiveProtocolHeader(new ProtocolInitiation(ProtocolVersion.v0_8));
- FieldTable startFieldTable = FieldTable.convertToFieldTable(Collections.singletonMap(
- ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE,
- Boolean.FALSE));
+ final FieldTable startFieldTable = FieldTable
+ .convertToFieldTable(Map.of(ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE, Boolean.FALSE));
conn.receiveConnectionStartOk(startFieldTable, SASL_MECH, SASL_RESPONSE, LOCALE);
assertFalse(conn.isCloseWhenNoRoute(), "Unexpected closeWhenNoRoute value");
}
}
@Test
- public void testConnectionEnforcesMaxSessions()
+ void connectionEnforcesMaxSessions()
{
- AMQPConnection_0_8Impl
+ final AMQPConnection_0_8Impl
conn = new AMQPConnection_0_8Impl(_broker, _network, _port, _transport, _protocol, 0, _ticker);
conn.create();
conn.receiveProtocolHeader(new ProtocolInitiation(ProtocolVersion.v0_8));
- conn.receiveConnectionStartOk(FieldTableFactory.createFieldTable(Collections.emptyMap()), SASL_MECH, SASL_RESPONSE, LOCALE);
- int maxChannels = 10;
+ conn.receiveConnectionStartOk(FieldTableFactory.createFieldTable(Map.of()), SASL_MECH, SASL_RESPONSE, LOCALE);
+ final int maxChannels = 10;
conn.receiveConnectionTuneOk(maxChannels, 65535, 0);
conn.receiveConnectionOpen(AMQShortString.createAMQShortString(VIRTUAL_HOST_NAME), AMQShortString.EMPTY_STRING, false);
// check the channel count is correct
- int channelCount = conn.getSessionModels().size();
+ final int channelCount = conn.getSessionModels().size();
assertEquals(0, (long) channelCount, "Initial channel count wrong");
assertEquals(maxChannels, (long) conn.getSessionCountLimit(), "Number of channels not correctly set.");
@@ -240,7 +236,7 @@ public class AMQPConnection_0_8Test extends UnitTestBase
}
@Test
- public void resetStatistics()
+ void resetStatistics()
{
final AMQPConnection_0_8Impl connection =
new AMQPConnection_0_8Impl(_broker, _network, _port, _transport, _protocol, 0, _ticker);
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQShortStringTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQShortStringTest.java
index 1238877888..a6db0d5bd5 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQShortStringTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQShortStringTest.java
@@ -22,8 +22,9 @@ package org.apache.qpid.server.protocol.v0_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
@@ -36,12 +37,12 @@ import org.junit.jupiter.api.Test;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.test.utils.UnitTestBase;
-public class AMQShortStringTest extends UnitTestBase
+class AMQShortStringTest extends UnitTestBase
{
private static final AMQShortString GOODBYE = AMQShortString.createAMQShortString("Goodbye");
@Test
- public void testEquals()
+ void testEquals()
{
assertEquals(GOODBYE, AMQShortString.createAMQShortString("Goodbye"));
assertEquals(AMQShortString.createAMQShortString("A"), AMQShortString.createAMQShortString("A"));
@@ -53,12 +54,11 @@ public class AMQShortStringTest extends UnitTestBase
* {@link AMQShortString#AMQShortString(byte[])}.
*/
@Test
- public void testCreateAMQShortStringByteArray()
+ void createAMQShortStringByteArray()
{
- byte[] bytes = "test".getBytes(StandardCharsets.UTF_8);
- AMQShortString string = AMQShortString.createAMQShortString(bytes);
+ final byte[] bytes = "test".getBytes(StandardCharsets.UTF_8);
+ final AMQShortString string = AMQShortString.createAMQShortString(bytes);
assertEquals(4, (long) string.length(), "constructed amq short string length differs from expected");
-
assertEquals("test", string.toString(), "constructed amq short string differs from expected");
}
@@ -66,11 +66,10 @@ public class AMQShortStringTest extends UnitTestBase
* Tests short string construction from string with length less than 255.
*/
@Test
- public void testCreateAMQShortStringString()
+ void createAMQShortStringString()
{
- AMQShortString string = AMQShortString.createAMQShortString("test");
+ final AMQShortString string = AMQShortString.createAMQShortString("test");
assertEquals(4, (long) string.length(), "constructed amq short string length differs from expected");
-
assertEquals("test", string.toString(), "constructed amq short string differs from expected");
}
@@ -81,90 +80,79 @@ public class AMQShortStringTest extends UnitTestBase
* Tests an attempt to create an AMQP short string from byte array with length over 255.
*/
@Test
- public void testCreateAMQShortStringByteArrayOver255()
+ void createAMQShortStringByteArrayOver255()
{
- String test = buildString('a', 256);
- byte[] bytes = test.getBytes(StandardCharsets.UTF_8);
- try
- {
- AMQShortString.createAMQShortString(bytes);
- fail("It should not be possible to create AMQShortString with length over 255");
- }
- catch (IllegalArgumentException e)
- {
- assertEquals("Cannot create AMQShortString with number of octets over 255!", e.getMessage(),
- "Exception message differs from expected");
-
- }
+ final String test = buildString(256);
+ final byte[] bytes = test.getBytes(StandardCharsets.UTF_8);
+ final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
+ () -> AMQShortString.createAMQShortString(bytes),
+ "It should not be possible to create AMQShortString with length over 255");
+ assertEquals("Cannot create AMQShortString with number of octets over 255!", thrown.getMessage(),
+ "Exception message differs from expected");
}
/**
* Tests an attempt to create an AMQP short string from string with length over 255
*/
@Test
- public void testCreateAMQShortStringStringOver255()
+ void createAMQShortStringStringOver255()
{
- String test = buildString('a', 256);
- try
- {
- AMQShortString.createAMQShortString(test);
- fail("It should not be possible to create AMQShortString with length over 255");
- }
- catch (IllegalArgumentException e)
- {
- assertEquals("Cannot create AMQShortString with number of octets over 255!", e.getMessage(),
- "Exception message differs from expected");
- }
+ final String test = buildString(256);
+ final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
+ () -> AMQShortString.createAMQShortString(test),
+ "It should not be possible to create AMQShortString with length over 255");
+ assertEquals("Cannot create AMQShortString with number of octets over 255!", thrown.getMessage(),
+ "Exception message differs from expected");
}
@Test
- public void testValueOf()
+ void valueOf()
{
- String string = buildString('a', 255);
- AMQShortString shortString = AMQShortString.valueOf(string, true, true);
+ final String string = buildString(255);
+ final AMQShortString shortString = AMQShortString.valueOf(string, true, true);
assertEquals(string, shortString.toString(), "Unexpected string from valueOf");
}
@Test
- public void testValueOfTruncated()
+ void valueOfTruncated()
{
- String string = buildString('a', 256);
- AMQShortString shortString = AMQShortString.valueOf(string, true, true);
+ final String string = buildString(256);
+ final AMQShortString shortString = AMQShortString.valueOf(string, true, true);
assertEquals(string.substring(0, AMQShortString.MAX_LENGTH - 3) + "...", shortString.toString(),
"Unexpected truncated string from valueOf");
}
@Test
- public void testValueOfNulAsEmptyString()
+ void valueOfNulAsEmptyString()
{
- AMQShortString shortString = AMQShortString.valueOf(null, true, true);
+ final AMQShortString shortString = AMQShortString.valueOf(null, true, true);
assertEquals(AMQShortString.EMPTY_STRING, shortString, "Unexpected empty string from valueOf");
}
@Test
- public void testValueOfNullAsNull()
+ void valueOfNullAsNull()
{
- AMQShortString shortString = AMQShortString.valueOf(null, true, false);
- assertEquals(null, shortString, "Unexpected null string from valueOf");
+ final AMQShortString shortString = AMQShortString.valueOf(null, true, false);
+ assertNull(shortString, "Unexpected null string from valueOf");
}
@Test
- public void testCaching()
+ void caching()
{
- Cache<ByteBuffer, AMQShortString> original = AMQShortString.getShortStringCache();
- Cache<ByteBuffer, AMQShortString> cache = CacheBuilder.newBuilder().maximumSize(1).build();
+ final Cache<ByteBuffer, AMQShortString> original = AMQShortString.getShortStringCache();
+ final Cache<ByteBuffer, AMQShortString> cache = CacheBuilder.newBuilder().maximumSize(1).build();
AMQShortString.setShortStringCache(cache);
try
{
- AMQShortString string = AMQShortString.createAMQShortString("hello");
- QpidByteBuffer qpidByteBuffer = QpidByteBuffer.allocate(2 * (string.length() + 1));
+ final AMQShortString string = AMQShortString.createAMQShortString("hello");
+ final QpidByteBuffer qpidByteBuffer = QpidByteBuffer.allocate(2 * (string.length() + 1));
string.writeToBuffer(qpidByteBuffer);
string.writeToBuffer(qpidByteBuffer);
qpidByteBuffer.flip();
- AMQShortString str1 = AMQShortString.readAMQShortString(qpidByteBuffer);
- AMQShortString str2 = AMQShortString.readAMQShortString(qpidByteBuffer);
+ final AMQShortString str1 = AMQShortString.readAMQShortString(qpidByteBuffer);
+ final AMQShortString str2 = AMQShortString.readAMQShortString(qpidByteBuffer);
assertEquals(str1, str2);
assertSame(str1, str2);
@@ -180,20 +168,11 @@ public class AMQShortStringTest extends UnitTestBase
* A helper method to generate a string with given length containing given
* character
*
- * @param ch
- * char to build string with
- * @param length
- * target string length
+ * @param length target string length
* @return string
*/
- private String buildString(char ch, int length)
+ private String buildString(int length)
{
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++)
- {
- sb.append(ch);
- }
- return sb.toString();
+ return String.valueOf('a').repeat(Math.max(0, length));
}
-
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java
index 79e294f19d..6b01d64ccd 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java
@@ -27,19 +27,20 @@ import org.junit.jupiter.api.Test;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.test.utils.UnitTestBase;
-public class AMQTypeTest extends UnitTestBase
+@SuppressWarnings("unchecked")
+class AMQTypeTest extends UnitTestBase
{
private static final int SIZE = 1024;
@Test
- public void testUnsignedShort()
+ void unsignedShort()
{
doTest(AMQType.UNSIGNED_SHORT, 0);
doTest(AMQType.UNSIGNED_SHORT, 65535);
}
@Test
- public void testUnsignedByte()
+ void unsignedByte()
{
doTest(AMQType.UNSIGNED_BYTE, (short)0);
doTest(AMQType.UNSIGNED_BYTE, (short)255);
@@ -51,7 +52,7 @@ public class AMQTypeTest extends UnitTestBase
AMQTypedValue.createAMQTypedValue(type, value).writeToBuffer(buf);
buf.flip();
- T read = (T) AMQTypedValue.readFromBuffer(buf).getValue();
+ final T read = (T) AMQTypedValue.readFromBuffer(buf).getValue();
assertEquals(value, read, "Unexpected round trip value");
buf.dispose();
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ClientDecoder.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ClientDecoder.java
index 8e02bbb4e0..e08d9d78f0 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ClientDecoder.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ClientDecoder.java
@@ -33,18 +33,18 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
/**
* Creates a new AMQP decoder.
*
- * @param methodProcessor method processor
+ * @param methodProcessor method processor
*/
public ClientDecoder(final ClientMethodProcessor<? extends ClientChannelMethodProcessor> methodProcessor)
{
super(false, methodProcessor);
}
- public void decodeBuffer(ByteBuffer incomingBuffer) throws AMQFrameDecodingException, AMQProtocolVersionException
+ public void decodeBuffer(final ByteBuffer incomingBuffer) throws AMQFrameDecodingException, AMQProtocolVersionException
{
if (_incompleteBuffer == null)
{
- QpidByteBuffer qpidByteBuffer = QpidByteBuffer.wrap(incomingBuffer);
+ final QpidByteBuffer qpidByteBuffer = QpidByteBuffer.wrap(incomingBuffer);
final int required = decode(qpidByteBuffer);
if (required != 0)
{
@@ -86,15 +86,13 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
}
@Override
- protected void processMethod(int channelId,
- QpidByteBuffer in)
- throws AMQFrameDecodingException
+ protected void processMethod(final int channelId, final QpidByteBuffer in) throws AMQFrameDecodingException
{
- ClientMethodProcessor<? extends ClientChannelMethodProcessor> methodProcessor = getMethodProcessor();
- ClientChannelMethodProcessor channelMethodProcessor = methodProcessor.getChannelMethodProcessor(channelId);
+ final ClientMethodProcessor<? extends ClientChannelMethodProcessor> methodProcessor = getMethodProcessor();
+ final ClientChannelMethodProcessor channelMethodProcessor = methodProcessor.getChannelMethodProcessor(channelId);
final int classAndMethod = in.getInt();
- int classId = classAndMethod >> 16;
- int methodId = classAndMethod & 0xFFFF;
+ final int classId = classAndMethod >> 16;
+ final int methodId = classAndMethod & 0xFFFF;
methodProcessor.setCurrentMethod(classId, methodId);
try
{
@@ -129,8 +127,7 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
case 0x000a0033:
if (methodProcessor.getProtocolVersion().equals(ProtocolVersion.v0_8))
{
- throw newUnknownMethodException(classId, methodId,
- methodProcessor.getProtocolVersion());
+ throw newUnknownMethodException(classId, methodId, methodProcessor.getProtocolVersion());
}
else
{
@@ -144,8 +141,7 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
}
else
{
- throw newUnknownMethodException(classId, methodId,
- methodProcessor.getProtocolVersion());
+ throw newUnknownMethodException(classId, methodId, methodProcessor.getProtocolVersion());
}
break;
case 0x000a003d:
@@ -155,8 +151,7 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
}
else
{
- throw newUnknownMethodException(classId, methodId,
- methodProcessor.getProtocolVersion());
+ throw newUnknownMethodException(classId, methodId, methodProcessor.getProtocolVersion());
}
break;
@@ -205,7 +200,6 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
ExchangeBoundOkBody.process(in, channelMethodProcessor);
break;
-
// QUEUE_CLASS:
case 0x0032000b:
@@ -230,7 +224,6 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
}
break;
-
// BASIC_CLASS:
case 0x003c000b:
@@ -307,8 +300,7 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
break;
default:
- throw newUnknownMethodException(classId, methodId,
- methodProcessor.getProtocolVersion());
+ throw newUnknownMethodException(classId, methodId, methodProcessor.getProtocolVersion());
}
}
@@ -317,5 +309,4 @@ public class ClientDecoder extends AMQDecoder<ClientMethodProcessor<? extends Cl
methodProcessor.setCurrentMethod(0, 0);
}
}
-
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/EncodingUtilsTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/EncodingUtilsTest.java
index e2d2e78d52..8fd305f4df 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/EncodingUtilsTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/EncodingUtilsTest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.protocol.v0_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.test.utils.UnitTestBase;
-public class EncodingUtilsTest extends UnitTestBase
+class EncodingUtilsTest extends UnitTestBase
{
private static final int BUFFER_SIZE = 10;
private static final int POOL_SIZE = 20;
@@ -39,7 +39,7 @@ public class EncodingUtilsTest extends UnitTestBase
private QpidByteBuffer _buffer;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
QpidByteBuffer.deinitialisePool();
QpidByteBuffer.initialisePool(BUFFER_SIZE, POOL_SIZE, SPARSITY_FRACTION);
@@ -47,14 +47,14 @@ public class EncodingUtilsTest extends UnitTestBase
}
@AfterEach
- public void tearDown() throws Exception
+ void tearDown()
{
_buffer.dispose();
QpidByteBuffer.deinitialisePool();
}
@Test
- public void testReadLongAsShortStringWhenDigitsAreSpecified() throws Exception
+ void readLongAsShortStringWhenDigitsAreSpecified() throws Exception
{
_buffer.putUnsignedByte((short)3);
_buffer.put((byte)'9');
@@ -65,20 +65,14 @@ public class EncodingUtilsTest extends UnitTestBase
}
@Test
- public void testReadLongAsShortStringWhenNonDigitCharacterIsSpecified()
+ void readLongAsShortStringWhenNonDigitCharacterIsSpecified()
{
_buffer.putUnsignedByte((short)2);
_buffer.put((byte)'1');
_buffer.put((byte)'a');
_buffer.flip();
- try
- {
- EncodingUtils.readLongAsShortString(_buffer);
- fail("Exception is expected");
- }
- catch(AMQFrameDecodingException e)
- {
- // pass
- }
+ assertThrows(AMQFrameDecodingException.class,
+ () -> EncodingUtils.readLongAsShortString(_buffer),
+ "Exception is expected");
}
}
\ No newline at end of file
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/FieldTableTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/FieldTableTest.java
index 4255fa3cd4..6298fcacc6 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/FieldTableTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/FieldTableTest.java
@@ -20,17 +20,18 @@
*/
package org.apache.qpid.server.protocol.v0_8;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
@@ -38,139 +39,137 @@ import org.junit.jupiter.api.Test;
import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
import org.apache.qpid.test.utils.UnitTestBase;
-public class FieldTableTest extends UnitTestBase
+class FieldTableTest extends UnitTestBase
{
-
/**
* Set a boolean and check that we can only get it back as a boolean and a string
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testBoolean()
+ void testBoolean()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", true));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", true));
assertTrue(table1.containsKey("value"));
assertEquals(true, table1.get("value"));
}
/**
* Set a byte and check that we can only get it back as a byte and a string
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testByte()
+ void testByte()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", Byte.MAX_VALUE));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", Byte.MAX_VALUE));
assertTrue(table1.containsKey("value"));
assertEquals(Byte.MAX_VALUE, table1.get("value"));
}
/**
* Set a short and check that we can only get it back as a short and a string
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testShort()
+ void testShort()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", Short.MAX_VALUE));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", Short.MAX_VALUE));
assertTrue(table1.containsKey("value"));
assertEquals(Short.MAX_VALUE, table1.get("value"));
}
/**
* Set a char and check that we can only get it back as a char
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testChar()
+ void testChar()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", 'c'));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", 'c'));
assertTrue(table1.containsKey("value"));
assertEquals('c', table1.get("value"));
}
/**
* Set a double and check that we can only get it back as a double
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testDouble()
+ void testDouble()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", Double.MAX_VALUE));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", Double.MAX_VALUE));
assertTrue(table1.containsKey("value"));
assertEquals(Double.MAX_VALUE, table1.get("value"));
}
/**
* Set a float and check that we can only get it back as a float
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testFloat()
+ void testFloat()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", Float.MAX_VALUE));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", Float.MAX_VALUE));
assertTrue(table1.containsKey("value"));
assertEquals(Float.MAX_VALUE, table1.get("value"));
}
/**
* Set an int and check that we can only get it back as an int
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testInt()
+ void testInt()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", Integer.MAX_VALUE));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", Integer.MAX_VALUE));
assertTrue(table1.containsKey("value"));
assertEquals(Integer.MAX_VALUE, table1.get("value"));
}
/**
* Set a long and check that we can only get it back as a long
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testLong()
+ void testLong()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", Long.MAX_VALUE));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", Long.MAX_VALUE));
assertTrue(table1.containsKey("value"));
assertEquals(Long.MAX_VALUE, table1.get("value"));
}
/**
* Set a double and check that we can only get it back as a double
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testBytes()
+ void bytes()
{
- byte[] bytes = { 99, 98, 97, 96, 95 };
+ final byte[] bytes = { 99, 98, 97, 96, 95 };
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", bytes));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", bytes));
assertTrue(table1.containsKey("value"));
assertBytesEqual(bytes, (byte[])table1.get("value"));
}
/**
* Set a String and check that we can only get it back as a String
- * Check that attempting to lookup a non existent value returns null
+ * Check that attempting to look up a non-existent value returns null
*/
@Test
- public void testString()
+ void string()
{
- FieldTable table1 = FieldTableFactory.createFieldTable(Collections.singletonMap("value", "Hello"));
+ final FieldTable table1 = FieldTableFactory.createFieldTable(Map.of("value", "Hello"));
assertTrue(table1.containsKey("value"));
-
assertEquals("Hello", table1.get("value"));
}
/** Check that a nested field table parameter correctly encodes and decodes to a byte buffer. */
@Test
- public void testNestedFieldTable()
+ void nestedFieldTable()
{
- byte[] testBytes = new byte[] { 0, 1, 2, 3, 4, 5 };
+ final byte[] testBytes = new byte[] { 0, 1, 2, 3, 4, 5 };
- Map<String, Object> innerTable = new LinkedHashMap<>();
+ final Map<String, Object> innerTable = new LinkedHashMap<>();
// Put some stuff in the inner table.
innerTable.put("bool", true);
@@ -184,24 +183,24 @@ public class FieldTableTest extends UnitTestBase
innerTable.put("short", Short.MAX_VALUE);
innerTable.put("string", "hello");
innerTable.put("null-string", null);
- innerTable.put("field-array",Arrays.asList("hello", 42, Collections.emptyList()));
+ innerTable.put("field-array", List.of("hello", 42, List.of()));
// Put the inner table in the outer one.
- FieldTable outerTable = FieldTableFactory.createFieldTable(Collections.singletonMap("innerTable",
- FieldTableFactory.createFieldTable(innerTable)));
+ final FieldTable outerTable = FieldTableFactory
+ .createFieldTable(Map.of("innerTable", FieldTableFactory.createFieldTable(innerTable)));
// Write the outer table into the buffer.
- QpidByteBuffer buf = QpidByteBuffer.allocate(EncodingUtils.encodedFieldTableLength(outerTable));
+ final QpidByteBuffer buf = QpidByteBuffer.allocate(EncodingUtils.encodedFieldTableLength(outerTable));
outerTable.writeToBuffer(buf);
buf.flip();
// Extract the table back from the buffer again.
- FieldTable extractedOuterTable = EncodingUtils.readFieldTable(buf);
+ final FieldTable extractedOuterTable = EncodingUtils.readFieldTable(buf);
assertNotNull(extractedOuterTable, "Unexpected outer table");
- FieldTable extractedTable = (FieldTable)extractedOuterTable.get("innerTable");
+ final FieldTable extractedTable = (FieldTable)extractedOuterTable.get("innerTable");
assertEquals(Boolean.TRUE, extractedTable.get("bool"));
assertEquals(Byte.MAX_VALUE, extractedTable.get("byte"));
@@ -214,35 +213,32 @@ public class FieldTableTest extends UnitTestBase
assertEquals(Short.MAX_VALUE, extractedTable.get("short"));
assertEquals("hello", extractedTable.get("string"));
assertNull(extractedTable.get("null-string"));
- Collection fieldArray = (Collection) extractedTable.get("field-array");
+ Collection<?> fieldArray = (Collection<?>) extractedTable.get("field-array");
assertEquals(3, fieldArray.size());
- Iterator iter = fieldArray.iterator();
+ Iterator<?> iter = fieldArray.iterator();
assertEquals("hello", iter.next());
assertEquals(42, iter.next());
- assertTrue(((Collection)iter.next()).isEmpty());
+ assertTrue(((Collection<?>)iter.next()).isEmpty());
}
- public void testUnsupportedObject()
+ @Test
+ void unsupportedObject()
{
- try
- {
- FieldTableFactory.createFieldTable(Collections.singletonMap("value", new Exception()));
- fail("Non primitive values are not allowed");
- }
- catch (AMQPInvalidClassException aice)
- {
- assertEquals(AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, aice.getMessage(),
- "Non primitive values are not allowed to be set");
- }
+ final Map<String, Object> map = Map.of("value", new Exception());
+ final AMQPInvalidClassException thrown = assertThrows(AMQPInvalidClassException.class,
+ () -> FieldTableFactory.createFieldTable(map),
+ "Non primitive values are not allowed");
+ assertEquals(AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, thrown.getMessage(),
+ "Non primitive values are not allowed to be set");
}
@Test
- public void testValues()
+ void values()
{
- Map<String, Object> map = new LinkedHashMap<>();
+ final Map<String, Object> map = new LinkedHashMap<>();
map.put("bool", true);
map.put("byte", Byte.MAX_VALUE);
- byte[] bytes = { 99, 98, 97, 96, 95 };
+ final byte[] bytes = { 99, 98, 97, 96, 95 };
map.put("bytes", bytes);
map.put("char", 'c');
map.put("double", Double.MAX_VALUE);
@@ -263,12 +259,12 @@ public class FieldTableTest extends UnitTestBase
map.put("object-short", Short.MAX_VALUE);
map.put("object-string", "Hello");
- FieldTable mapTable = FieldTableFactory.createFieldTable(map);
- QpidByteBuffer buf = QpidByteBuffer.allocate(EncodingUtils.encodedFieldTableLength(mapTable));
+ final FieldTable mapTable = FieldTableFactory.createFieldTable(map);
+ final QpidByteBuffer buf = QpidByteBuffer.allocate(EncodingUtils.encodedFieldTableLength(mapTable));
mapTable.writeToBuffer(buf);
buf.flip();
- FieldTable table = EncodingUtils.readFieldTable(buf);
+ final FieldTable table = EncodingUtils.readFieldTable(buf);
assertNotNull(table);
assertEquals(Boolean.TRUE, table.get("bool"));
@@ -295,11 +291,11 @@ public class FieldTableTest extends UnitTestBase
}
@Test
- public void testWriteBuffer()
+ void writeBuffer()
{
- byte[] bytes = { 99, 98, 97, 96, 95 };
+ final byte[] bytes = { 99, 98, 97, 96, 95 };
- Map<String, Object> map = new LinkedHashMap<>();
+ final Map<String, Object> map = new LinkedHashMap<>();
map.put("bool", true);
map.put("byte", Byte.MAX_VALUE);
map.put("bytes", bytes);
@@ -312,19 +308,18 @@ public class FieldTableTest extends UnitTestBase
map.put("string", "hello");
map.put("null-string", null);
- FieldTable table = FieldTableFactory.createFieldTable(map);
+ final FieldTable table = FieldTableFactory.createFieldTable(map);
- QpidByteBuffer buf = QpidByteBuffer.allocate((int) table.getEncodedSize() + 4);
+ final QpidByteBuffer buf = QpidByteBuffer.allocate((int) table.getEncodedSize() + 4);
table.writeToBuffer(buf);
buf.flip();
- long length = buf.getInt() & 0xFFFFFFFFL;
- QpidByteBuffer bufSlice = buf.slice();
+ final long length = buf.getInt() & 0xFFFFFFFFL;
+ final QpidByteBuffer bufSlice = buf.slice();
bufSlice.limit((int)length);
-
- FieldTable table2 = FieldTableFactory.createFieldTable(buf);
+ final FieldTable table2 = FieldTableFactory.createFieldTable(buf);
assertNotNull(table2);
assertEquals(true, table2.get("bool"));
@@ -345,9 +340,9 @@ public class FieldTableTest extends UnitTestBase
}
@Test
- public void testEncodingSize()
+ void encodingSize()
{
- Map<String, Object> result = new LinkedHashMap<>();
+ final Map<String, Object> result = new LinkedHashMap<>();
int size = 0;
result.put("boolean", true);
@@ -416,136 +411,84 @@ public class FieldTableTest extends UnitTestBase
* Additional test checkPropertyName doesn't accept Null
*/
@Test
- public void testCheckPropertyNameIsNull()
+ void checkPropertyNameIsNull()
{
- try
- {
- FieldTableFactory.createFieldTable(Collections.singletonMap(null, "String"));
- fail("Null property name is not allowed");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
+ final Map<String, Object> map = Collections.singletonMap(null, "String");
+ assertThrows(IllegalArgumentException.class,
+ () -> FieldTableFactory.createFieldTable(map),
+ "Null property name is not allowed");
}
/**
* Additional test checkPropertyName doesn't accept an empty String
*/
@Test
- public void testCheckPropertyNameIsEmptyString()
+ void checkPropertyNameIsEmptyString()
{
- try
- {
- FieldTableFactory.createFieldTable(Collections.singletonMap("", "String"));
- fail("empty property name is not allowed");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
+ final Map<String, Object> map =Map.of("", "String");
+ assertThrows(IllegalArgumentException.class,
+ () -> FieldTableFactory.createFieldTable(map),
+ "Empty property name is not allowed");
+
}
/**
* Additional test checkPropertyName doesn't accept an empty String
*/
@Test
- public void testCheckPropertyNameHasMaxLength()
+ void checkPropertyNameHasMaxLength()
{
- StringBuilder longPropertyName = new StringBuilder(129);
-
- for (int i = 0; i < 129; i++)
- {
- longPropertyName.append("x");
- }
-
- boolean strictAMQP = FieldTable._strictAMQP;
- try
- {
- FieldTable._strictAMQP = true;
- new FieldTable(Collections.singletonMap(longPropertyName.toString(), "String"));
- fail("property name must be < 128 characters");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
- finally
- {
- FieldTable._strictAMQP = strictAMQP;
- }
+ final boolean strictAMQP = FieldTable._strictAMQP;
+ final Map<String, Object> map = Map.of("x".repeat(129), "String");
+ FieldTable._strictAMQP = true;
+ assertThrows(IllegalArgumentException.class,
+ () -> new FieldTable(map),
+ "property name must be < 128 characters");
+ FieldTable._strictAMQP = strictAMQP;
}
/**
* Additional test checkPropertyName starts with a letter
*/
@Test
- public void testCheckPropertyNameStartCharacterIsLetter()
+ void checkPropertyNameStartCharacterIsLetter()
{
- boolean strictAMQP = FieldTable._strictAMQP;
+ final boolean strictAMQP = FieldTable._strictAMQP;
// Try a name that starts with a number
- try
- {
- FieldTable._strictAMQP = true;
- new FieldTable(Collections.singletonMap("1", "String"));
- fail("property name must start with a letter");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
- finally
- {
- FieldTable._strictAMQP = strictAMQP;
- }
+ FieldTable._strictAMQP = true;
+ final Map<String, Object> map = Map.of("1", "String");
+ assertThrows(IllegalArgumentException.class,
+ () -> new FieldTable(map),
+ "property name must start with a letter");
+ FieldTable._strictAMQP = strictAMQP;
}
/**
* Additional test checkPropertyName starts with a hash or a dollar
*/
@Test
- public void testCheckPropertyNameStartCharacterIsHashOrDollar()
+ void checkPropertyNameStartCharacterIsHashOrDollar()
{
- try
- {
- FieldTableFactory.createFieldTable(Collections.singletonMap("#", "String"));
- }
- catch (IllegalArgumentException iae)
- {
- fail("property name are allowed to start with # and $s");
- }
-
- try
- {
- FieldTableFactory.createFieldTable(Collections.singletonMap("$", "String"));
- }
- catch (IllegalArgumentException iae)
- {
- fail("property name are allowed to start with # and $s");
- }
+ assertDoesNotThrow(() -> FieldTableFactory.createFieldTable(Map.of("#", "String")),
+ "Property names are allowed to start with # and $s");
+
+ assertDoesNotThrow(() -> FieldTableFactory.createFieldTable(Map.of("$", "String")),
+ "Property names are allowed to start with # and $s");
}
@Test
- public void testValidateMalformedFieldTable()
+ void validateMalformedFieldTable()
{
final FieldTable fieldTable = buildMalformedFieldTable();
- try
- {
- fieldTable.validate();
- fail("Exception is expected");
- }
- catch (RuntimeException e)
- {
- // pass
- }
+ assertThrows(RuntimeException.class, fieldTable::validate, "Exception is expected");
}
@Test
- public void testValidateCorrectFieldTable()
+ void validateCorrectFieldTable()
{
- final FieldTable ft = new FieldTable(Collections.singletonMap("testKey", "testValue"));
+ final FieldTable ft = new FieldTable(Map.of("testKey", "testValue"));
final int encodedSize = (int)ft.getEncodedSize() + Integer.BYTES;
final QpidByteBuffer buf = QpidByteBuffer.allocate(encodedSize);
ft.writeToBuffer(buf);
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_0_8_to_InternalTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_0_8_to_InternalTest.java
index 1601c6827b..6777f8bd21 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_0_8_to_InternalTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_0_8_to_InternalTest.java
@@ -31,7 +31,6 @@ import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -56,19 +55,18 @@ import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.typedmessage.TypedBytesContentWriter;
import org.apache.qpid.test.utils.UnitTestBase;
-public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
+@SuppressWarnings({"rawtypes", "uchecked"})
+class MessageConverter_0_8_to_InternalTest extends UnitTestBase
{
private final MessageConverter_v0_8_to_Internal _converter = new MessageConverter_v0_8_to_Internal();
-
private final StoredMessage<MessageMetaData> _handle = mock(StoredMessage.class);
-
private final MessageMetaData _metaData = mock(MessageMetaData.class);
private final AMQMessageHeader _header = mock(AMQMessageHeader.class);
private final ContentHeaderBody _contentHeaderBody = mock(ContentHeaderBody.class);
private final BasicContentHeaderProperties _basicContentHeaderProperties = mock(BasicContentHeaderProperties.class);
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
when(_handle.getMetaData()).thenReturn(_metaData);
when(_metaData.getMessageHeader()).thenReturn(_header);
@@ -78,123 +76,121 @@ public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
}
@Test
- public void testConvertStringMessageBody()
+ void convertStringMessageBody()
{
doTestTextMessage("helloworld", "text/plain");
}
@Test
- public void testConvertEmptyStringMessageBody()
+ void convertEmptyStringMessageBody()
{
doTestTextMessage(null, "text/plain");
}
@Test
- public void testConvertStringXmlMessageBody()
+ void convertStringXmlMessageBody()
{
doTestTextMessage("<helloworld></helloworld>", "text/xml");
}
@Test
- public void testConvertEmptyStringXmlMessageBody()
+ void convertEmptyStringXmlMessageBody()
{
doTestTextMessage(null, "text/xml");
}
@Test
- public void testConvertEmptyStringApplicationXmlMessageBody()
+ void convertEmptyStringApplicationXmlMessageBody()
{
doTestTextMessage(null, "application/xml");
}
@Test
- public void testConvertStringWithContentTypeText()
+ void convertStringWithContentTypeText()
{
doTestTextMessage("foo","text/foobar");
}
@Test
- public void testConvertStringWithContentTypeApplicationXml()
+ void convertStringWithContentTypeApplicationXml()
{
doTestTextMessage("<helloworld></helloworld>","application/xml");
}
@Test
- public void testConvertStringWithContentTypeApplicationXmlDtd()
+ void convertStringWithContentTypeApplicationXmlDtd()
{
doTestTextMessage("<!DOCTYPE name []>","application/xml-dtd");
}
@Test
- public void testConvertStringWithContentTypeApplicationFooXml()
+ void convertStringWithContentTypeApplicationFooXml()
{
doTestTextMessage("<helloworld></helloworld>","application/foo+xml");
}
@Test
- public void testConvertStringWithContentTypeApplicationJson()
+ void convertStringWithContentTypeApplicationJson()
{
doTestTextMessage("[]","application/json");
}
@Test
- public void testConvertStringWithContentTypeApplicationFooJson()
+ void convertStringWithContentTypeApplicationFooJson()
{
doTestTextMessage("[]","application/foo+json");
}
@Test
- public void testConvertStringWithContentTypeApplicationJavascript()
+ void convertStringWithContentTypeApplicationJavascript()
{
doTestTextMessage("var foo","application/javascript");
}
@Test
- public void testConvertStringWithContentTypeApplicationEcmascript()
+ void convertStringWithContentTypeApplicationEcmascript()
{
doTestTextMessage("var foo","application/ecmascript");
}
@Test
- public void testConvertBytesMessageBody() throws Exception
+ void convertBytesMessageBody()
{
doTestBytesMessage("helloworld".getBytes());
}
@Test
- public void testConvertBytesMessageBodyNoContentType()
+ void convertBytesMessageBodyNoContentType()
{
final byte[] messageContent = "helloworld".getBytes();
doTest(messageContent, null, messageContent, null);
}
@Test
- public void testConvertMessageBodyUnknownContentType()
+ void convertMessageBodyUnknownContentType()
{
final byte[] messageContent = "helloworld".getBytes();
final String mimeType = "my/bytes";
doTest(messageContent, mimeType, messageContent, mimeType);
}
-
@Test
- public void testConvertEmptyBytesMessageBody() throws Exception
+ void convertEmptyBytesMessageBody()
{
doTestBytesMessage(new byte[0]);
}
@Test
- public void testConvertJmsStreamMessageBody() throws Exception
+ void convertJmsStreamMessageBody() throws Exception
{
final List<Object> expected = Lists.newArrayList("apple", 43, 31.42D);
final byte[] messageBytes = getJmsStreamMessageBytes(expected);
-
final String mimeType = "jms/stream-message";
doTestStreamMessage(messageBytes, mimeType, expected);
}
@Test
- public void testConvertEmptyJmsStreamMessageBody()
+ void convertEmptyJmsStreamMessageBody()
{
final List<Object> expected = Lists.newArrayList();
final String mimeType = "jms/stream-message";
@@ -202,7 +198,7 @@ public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
}
@Test
- public void testConvertAmqpListMessageBody()
+ void convertAmqpListMessageBody()
{
final List<Object> expected = Lists.newArrayList("apple", 43, 31.42D);
final byte[] messageBytes = new ListToAmqpListConverter().toMimeContent(expected);
@@ -211,107 +207,106 @@ public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
}
@Test
- public void testConvertEmptyAmqpListMessageBody()
+ void convertEmptyAmqpListMessageBody()
{
final List<Object> expected = Lists.newArrayList();
doTestStreamMessage(null, "amqp/list", expected);
}
@Test
- public void testConvertJmsMapMessageBody() throws Exception
+ void convertJmsMapMessageBody() throws Exception
{
- final Map<String, Object> expected = Collections.singletonMap("key", "value");
+ final Map<String, Object> expected = Map.of("key", "value");
final byte[] messageBytes = getJmsMapMessageBytes(expected);
doTestMapMessage(messageBytes, "jms/map-message", expected);
}
@Test
- public void testConvertEmptyJmsMapMessageBody()
+ void convertEmptyJmsMapMessageBody()
{
- doTestMapMessage(null, "jms/map-message", Collections.emptyMap());
+ doTestMapMessage(null, "jms/map-message", Map.of());
}
@Test
- public void testConvertAmqpMapMessageBody()
+ void convertAmqpMapMessageBody()
{
- final Map<String, Object> expected = Collections.singletonMap("key", "value");
+ final Map<String, Object> expected = Map.of("key", "value");
final byte[] messageBytes = new MapToAmqpMapConverter().toMimeContent(expected);
doTestMapMessage(messageBytes, "amqp/map", expected);
}
@Test
- public void testConvertEmptyAmqpMapMessageBody()
+ void convertEmptyAmqpMapMessageBody()
{
- doTestMapMessage(null, "amqp/map", Collections.emptyMap());
+ doTestMapMessage(null, "amqp/map", Map.of());
}
@Test
- public void testConvertObjectStreamMessageBody() throws Exception
+ void convertObjectStreamMessageBody() throws Exception
{
final byte[] messageBytes = getObjectStreamMessageBytes(UUID.randomUUID());
doTestObjectMessage(messageBytes, "application/java-object-stream", messageBytes);
}
@Test
- public void testConvertObjectStream2MessageBody() throws Exception
+ void convertObjectStream2MessageBody() throws Exception
{
final byte[] messageBytes = getObjectStreamMessageBytes(UUID.randomUUID());
doTestObjectMessage(messageBytes, "application/x-java-serialized-object", messageBytes);
}
@Test
- public void testConvertEmptyObjectStreamMessageBody()
+ void convertEmptyObjectStreamMessageBody()
{
doTestObjectMessage(null, "application/java-object-stream", new byte[0]);
}
@Test
- public void testConvertEmptyMessageWithoutContentType()
+ void convertEmptyMessageWithoutContentType()
{
doTest(null, null, null, null);
}
@Test
- public void testConvertEmptyMessageWithUnknownContentType()
+ void convertEmptyMessageWithUnknownContentType()
{
doTest(null, "foo/bar", new byte[0], "foo/bar");
}
@Test
- public void testConvertMessageWithoutContentType()
+ void convertMessageWithoutContentType()
{
final byte[] expectedContent = "someContent".getBytes(UTF_8);
doTest(expectedContent, null, expectedContent, null);
}
-
private byte[] getObjectStreamMessageBytes(final Serializable o) throws Exception
{
- try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos))
+ try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final ObjectOutputStream oos = new ObjectOutputStream(bos))
{
oos.writeObject(o);
return bos.toByteArray();
}
}
- private byte[] getJmsStreamMessageBytes(List<Object> objects) throws Exception
+ private byte[] getJmsStreamMessageBytes(final List<Object> objects) throws Exception
{
- TypedBytesContentWriter writer = new TypedBytesContentWriter();
- for (Object o : objects)
+ final TypedBytesContentWriter writer = new TypedBytesContentWriter();
+ for (final Object o : objects)
{
writer.writeObject(o);
}
return getBytes(writer);
}
- private byte[] getJmsMapMessageBytes(Map<String, Object> map) throws Exception
+ private byte[] getJmsMapMessageBytes(final Map<String, Object> map) throws Exception
{
- TypedBytesContentWriter writer = new TypedBytesContentWriter();
+ final TypedBytesContentWriter writer = new TypedBytesContentWriter();
writer.writeIntImpl(map.size());
- for (Map.Entry<String, Object> entry : map.entrySet())
+ for (final Map.Entry<String, Object> entry : map.entrySet())
{
writer.writeNullTerminatedStringImpl(entry.getKey());
writer.writeObject(entry.getValue());
@@ -321,7 +316,7 @@ public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
private byte[] getBytes(final TypedBytesContentWriter writer)
{
- ByteBuffer buf = writer.getData();
+ final ByteBuffer buf = writer.getData();
final byte[] expected = new byte[buf.remaining()];
buf.get(expected);
return expected;
@@ -348,18 +343,17 @@ public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
section = new byte[0];
}
final QpidByteBuffer combined = QpidByteBuffer.wrap(section);
+
when(_handle.getContentSize()).thenReturn(section.length);
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
- when(_handle.getContent(offsetCaptor.capture(),
- sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(),
- sizeCaptor.getValue()));
+ when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation ->
+ combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
}
private void doTestTextMessage(final String originalContent, final String mimeType)
{
-
final byte[] contentBytes;
final String expectedContent;
if (originalContent == null)
@@ -375,7 +369,6 @@ public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
doTest(contentBytes, mimeType, expectedContent, mimeType);
}
-
private void doTestMapMessage(final byte[] messageBytes,
final String mimeType,
final Map<String, Object> expected)
@@ -383,7 +376,7 @@ public class MessageConverter_0_8_to_InternalTest extends UnitTestBase
doTest(messageBytes, mimeType, expected, null);
}
- private void doTestBytesMessage(final byte[] messageContent) throws Exception
+ private void doTestBytesMessage(final byte[] messageContent)
{
doTest(messageContent,"application/octet-stream", messageContent, "application/octet-stream");
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java
index 2918b5a2b1..2c832c6ee6 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java
@@ -30,8 +30,8 @@ import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
+import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.io.ByteStreams;
@@ -54,97 +54,97 @@ import org.apache.qpid.server.typedmessage.mimecontentconverter.ListToJmsStreamM
import org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class MessageConverter_Internal_to_0_8Test extends UnitTestBase
+class MessageConverter_Internal_to_0_8Test extends UnitTestBase
{
private final MessageConverter_Internal_to_v0_8 _converter = new MessageConverter_Internal_to_v0_8();
private final StoredMessage<InternalMessageMetaData> _handle = mock(StoredMessage.class);
private final AMQMessageHeader _amqpHeader = mock(AMQMessageHeader.class);
@Test
- public void testStringMessage() throws Exception
+ void stringMessage() throws Exception
{
- String content = "testContent";
+ final String content = "testContent";
final String mimeType = "text/plain";
doTest(content, mimeType, content.getBytes(UTF_8), mimeType);
}
@Test
- public void testStringMessageWithUnknownMimeType() throws Exception
+ void stringMessageWithUnknownMimeType() throws Exception
{
- String content = "testContent";
+ final String content = "testContent";
final String mimeType = "foo/bar";
doTest(content, mimeType, content.getBytes(UTF_8), "text/plain");
}
@Test
- public void testStringMessageWithoutMimeType() throws Exception
+ void stringMessageWithoutMimeType() throws Exception
{
- String content = "testContent";
+ final String content = "testContent";
doTest(content, null, content.getBytes(UTF_8), "text/plain");
}
@Test
- public void testListMessageWithMimeType() throws Exception
+ void listMessageWithMimeType() throws Exception
{
- ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
+ final ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
final ListToJmsStreamMessage listToJmsStreamMessage = new ListToJmsStreamMessage();
final byte[] expectedContent = listToJmsStreamMessage.toMimeContent(content);
doTest(content, "foo/bar", expectedContent, listToJmsStreamMessage.getMimeType());
}
@Test
- public void testListMessageWithoutMimeType() throws Exception
+ void listMessageWithoutMimeType() throws Exception
{
- ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
+ final ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42);
final ListToJmsStreamMessage listToJmsStreamMessage = new ListToJmsStreamMessage();
final byte[] expectedContent = listToJmsStreamMessage.toMimeContent(content);
doTest(content, null, expectedContent, listToJmsStreamMessage.getMimeType());
}
@Test
- public void testListMessageWithoutMimeTypeWithNonJmsContent() throws Exception
+ void listMessageWithoutMimeTypeWithNonJmsContent() throws Exception
{
- ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42, Lists.newArrayList());
+ final ArrayList<?> content = Lists.newArrayList("testItem", 37.5, 42, Lists.newArrayList());
final ListToAmqpListConverter listToAmqpListConverter = new ListToAmqpListConverter();
final byte[] expectedContent = listToAmqpListConverter.toMimeContent(content);
doTest(content, null, expectedContent, listToAmqpListConverter.getMimeType());
}
@Test
- public void testListMessageWithoutMimeTypeWithNonConvertibleItem() throws Exception
+ void listMessageWithoutMimeTypeWithNonConvertibleItem() throws Exception
{
- ArrayList<?> content = Lists.newArrayList(new MySerializable());
+ final ArrayList<?> content = Lists.newArrayList(new MySerializable());
final InternalMessage sourceMessage = getAmqMessage(content, null);
doTest(content, null, getObjectStreamMessageBytes(content), "application/java-object-stream");
}
@Test
- public void testByteArrayMessageWithoutMimeType() throws Exception
+ void byteArrayMessageWithoutMimeType() throws Exception
{
- byte[] content = "testContent".getBytes(UTF_8);
+ final byte[] content = "testContent".getBytes(UTF_8);
doTest(content, null, content, "application/octet-stream");
}
@Test
- public void testByteArrayMessageWithMimeType() throws Exception
+ void byteArrayMessageWithMimeType() throws Exception
{
- byte[] content = "testContent".getBytes(UTF_8);
+ final byte[] content = "testContent".getBytes(UTF_8);
final String mimeType = "foo/bar";
doTest(content, mimeType, content, mimeType);
}
@Test
- public void testEmptyByteArrayMessageWithMimeType() throws Exception
+ void emptyByteArrayMessageWithMimeType() throws Exception
{
- byte[] content = new byte[0];
+ final byte[] content = new byte[0];
final String mimeType = "foo/bar";
doTest(content, mimeType, content, mimeType);
}
@Test
- public void testMapMessageWithMimeType() throws Exception
+ void mapMessageWithMimeType() throws Exception
{
- HashMap<Object, Object> content = new HashMap<>();
+ final HashMap<Object, Object> content = new HashMap<>();
content.put("key1", 37);
content.put("key2", "foo");
final String mimeType = "foo/bar";
@@ -154,9 +154,9 @@ public class MessageConverter_Internal_to_0_8Test extends UnitTestBase
}
@Test
- public void testMapMessageWithoutMimeType() throws Exception
+ void mapMessageWithoutMimeType() throws Exception
{
- HashMap<Object, Object> content = new HashMap<>();
+ final HashMap<Object, Object> content = new HashMap<>();
content.put("key1", 37);
content.put("key2", "foo");
final MapToJmsMapMessage mapToJmsMapMessage = new MapToJmsMapMessage();
@@ -165,10 +165,10 @@ public class MessageConverter_Internal_to_0_8Test extends UnitTestBase
}
@Test
- public void testMapMessageWithMimeTypeWithNonJmsContent() throws Exception
+ void mapMessageWithMimeTypeWithNonJmsContent() throws Exception
{
- HashMap<Object, Object> content = new HashMap<>();
- content.put("key", Collections.singletonMap("foo", "bar"));
+ final HashMap<Object, Object> content = new HashMap<>();
+ content.put("key", Map.of("foo", "bar"));
final String mimeType = "foo/bar";
final MapToAmqpMapConverter mapToAmqpMapConverter = new MapToAmqpMapConverter();
final byte[] expectedContent = mapToAmqpMapConverter.toMimeContent(content);
@@ -176,47 +176,45 @@ public class MessageConverter_Internal_to_0_8Test extends UnitTestBase
}
@Test
- public void testMapMessageWithoutMimeTypeWithNonConvertibleEntry() throws Exception
+ void mapMessageWithoutMimeTypeWithNonConvertibleEntry() throws Exception
{
- HashMap<Object, Object> content = new HashMap<>();
+ final HashMap<Object, Object> content = new HashMap<>();
content.put(37, new MySerializable());
doTest(content, null, getObjectStreamMessageBytes(content), "application/java-object-stream");
}
@Test
- public void testSerializableMessageWithMimeType() throws Exception
+ void serializableMessageWithMimeType() throws Exception
{
- Serializable content = new MySerializable();
+ final Serializable content = new MySerializable();
final String mimeType = "foo/bar";
doTest(content, mimeType, getObjectStreamMessageBytes(content), "application/java-object-stream");
}
@Test
- public void testSerializableMessageWithoutMimeType() throws Exception
+ void serializableMessageWithoutMimeType() throws Exception
{
- Serializable content = new MySerializable();
+ final Serializable content = new MySerializable();
doTest(content, null, getObjectStreamMessageBytes(content), "application/java-object-stream");
}
@Test
- public void testNullMessageWithoutMimeType() throws Exception
+ void nullMessageWithoutMimeType() throws Exception
{
doTest(null, null, null, null);
}
-
private byte[] getObjectStreamMessageBytes(final Serializable o) throws Exception
{
- try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos))
+ try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final ObjectOutputStream oos = new ObjectOutputStream(bos))
{
oos.writeObject(o);
return bos.toByteArray();
}
}
-
protected InternalMessage getAmqMessage(final Serializable content, final String mimeType) throws Exception
{
final byte[] serializedContent = getObjectStreamMessageBytes(content);
@@ -248,9 +246,8 @@ public class MessageConverter_Internal_to_0_8Test extends UnitTestBase
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
- when(_handle.getContent(offsetCaptor.capture(),
- sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(),
- sizeCaptor.getValue()));
+ when(_handle.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation ->
+ combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
}
private void doTest(final Serializable messageBytes,
@@ -268,8 +265,8 @@ public class MessageConverter_Internal_to_0_8Test extends UnitTestBase
private byte[] getBytes(final QpidByteBuffer content) throws Exception
{
- try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
- InputStream contentInputStream = content.asInputStream())
+ try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final InputStream contentInputStream = content.asInputStream())
{
ByteStreams.copy(contentInputStream, bos);
content.dispose();
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageMetaDataFactoryTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageMetaDataFactoryTest.java
index 665d650dba..543be7baa5 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageMetaDataFactoryTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageMetaDataFactoryTest.java
@@ -32,22 +32,24 @@ import org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody;
import org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo;
import org.apache.qpid.test.utils.UnitTestBase;
-public class MessageMetaDataFactoryTest extends UnitTestBase
+class MessageMetaDataFactoryTest extends UnitTestBase
{
private static final String CONTENT_TYPE = "content/type";
+
private final long _arrivalTime = System.currentTimeMillis();
private final AMQShortString _routingKey = AMQShortString.valueOf("routingkey");
private final AMQShortString _exchange = AMQShortString.valueOf("exch");
+
private MessageMetaData _mmd;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
_mmd = createTestMessageMetaData();
}
@AfterEach
- public void tearDown() throws Exception
+ void tearDown()
{
if (_mmd != null)
{
@@ -56,14 +58,14 @@ public class MessageMetaDataFactoryTest extends UnitTestBase
}
@Test
- public void testUnmarshalFromSingleBuffer()
+ void unmarshalFromSingleBuffer()
{
- try(QpidByteBuffer qpidByteBuffer = QpidByteBuffer.allocateDirect(_mmd.getStorableSize()))
+ try (final QpidByteBuffer qpidByteBuffer = QpidByteBuffer.allocateDirect(_mmd.getStorableSize()))
{
_mmd.writeToBuffer(qpidByteBuffer);
qpidByteBuffer.flip();
- MessageMetaData recreated = MessageMetaData.FACTORY.createMetaData(qpidByteBuffer);
+ final MessageMetaData recreated = MessageMetaData.FACTORY.createMetaData(qpidByteBuffer);
assertEquals(_arrivalTime, recreated.getArrivalTime(), "Unexpected arrival time");
assertEquals(_routingKey, recreated.getMessagePublishInfo().getRoutingKey(), "Unexpected routing key");
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/Pre0_10CreditManagerTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/Pre0_10CreditManagerTest.java
index bad539bd04..949d6fc6fb 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/Pre0_10CreditManagerTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/Pre0_10CreditManagerTest.java
@@ -21,26 +21,17 @@ package org.apache.qpid.server.protocol.v0_8;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.apache.qpid.server.transport.ProtocolEngine;
import org.apache.qpid.test.utils.UnitTestBase;
-public class Pre0_10CreditManagerTest extends UnitTestBase
+class Pre0_10CreditManagerTest extends UnitTestBase
{
private Pre0_10CreditManager _creditManager;
- @BeforeEach
- public void setUp() throws Exception
- {
- ProtocolEngine protocolEngine = mock(ProtocolEngine.class);
- }
-
@Test
- public void testBasicMessageCredit()
+ void basicMessageCredit()
{
_creditManager = new Pre0_10CreditManager(0, 0, 100L, 10L);
_creditManager.setCreditLimits(0, 2);
@@ -56,7 +47,7 @@ public class Pre0_10CreditManagerTest extends UnitTestBase
}
@Test
- public void testBytesLimitDoesNotPreventLargeMessage()
+ void bytesLimitDoesNotPreventLargeMessage()
{
_creditManager = new Pre0_10CreditManager(0, 0, 100L, 10L);
_creditManager.setCreditLimits(10, 0);
@@ -67,7 +58,7 @@ public class Pre0_10CreditManagerTest extends UnitTestBase
}
@Test
- public void testUseCreditWithNegativeMessageCredit()
+ void useCreditWithNegativeMessageCredit()
{
_creditManager = new Pre0_10CreditManager(0, 0, 100L, 10L);
_creditManager.setCreditLimits(0, 3);
@@ -86,7 +77,7 @@ public class Pre0_10CreditManagerTest extends UnitTestBase
}
@Test
- public void testUseCreditWithNegativeBytesCredit()
+ void useCreditWithNegativeBytesCredit()
{
_creditManager = new Pre0_10CreditManager(0, 0, 100L, 10L);
_creditManager.setCreditLimits(3, 0);
@@ -105,7 +96,7 @@ public class Pre0_10CreditManagerTest extends UnitTestBase
}
@Test
- public void testCreditAccountingWhileMessageLimitNotSet()
+ void creditAccountingWhileMessageLimitNotSet()
{
_creditManager = new Pre0_10CreditManager(0, 0, 100L, 10L);
assertTrue(_creditManager.useCreditForMessage(37), "Creditmanager should be able to useCredit");
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_Internal_to_v0_8Test.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_Internal_to_v0_8Test.java
index 453d82f2bc..7ec2c6c544 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_Internal_to_v0_8Test.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_Internal_to_v0_8Test.java
@@ -24,8 +24,8 @@ package org.apache.qpid.server.protocol.v0_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.AdditionalAnswers.returnsFirstArg;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -36,7 +36,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -58,13 +57,13 @@ import org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
+class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
{
private MessageConverter_Internal_to_v0_8 _messageConverter;
private NamedAddressSpace _addressSpace;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
_messageConverter = new MessageConverter_Internal_to_v0_8();
_addressSpace = mock(NamedAddressSpace.class);
@@ -72,12 +71,12 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testDurableTrueConversion()
+ void durableTrueConversion()
{
final AMQMessageHeader header = mock(AMQMessageHeader.class);
- InternalMessage originalMessage = createTestMessage(header, null, true);
+ final InternalMessage originalMessage = createTestMessage(header, null, true);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(BasicContentHeaderProperties.PERSISTENT,
(long) convertedMessage.getContentHeaderBody().getProperties().getDeliveryMode(),
@@ -89,12 +88,12 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testDurableFalseConversion()
+ void durableFalseConversion()
{
final AMQMessageHeader header = mock(AMQMessageHeader.class);
- InternalMessage originalMessage = createTestMessage(header, null, false);
+ final InternalMessage originalMessage = createTestMessage(header, null, false);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(BasicContentHeaderProperties.NON_PERSISTENT,
(long) convertedMessage.getContentHeaderBody().getProperties().getDeliveryMode(),
@@ -105,43 +104,43 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testPriorityConversion()
+ void priorityConversion()
{
final AMQMessageHeader header = mock(AMQMessageHeader.class);
- byte priority = (byte) 7;
+ final byte priority = (byte) 7;
when(header.getPriority()).thenReturn(priority);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(priority, (long) convertedMessage.getContentHeaderBody().getProperties().getPriority(),
"Unexpected priority");
}
@Test
- public void testExpirationConversion()
+ void expirationConversion()
{
- long ttl = 10000;
- long expiryTime = System.currentTimeMillis() + ttl;
+ final long ttl = 10000;
+ final long expiryTime = System.currentTimeMillis() + ttl;
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getExpiration()).thenReturn(expiryTime);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(expiryTime, convertedMessage.getContentHeaderBody().getProperties().getExpiration(),
"Unexpected expiration time");
}
@Test
- public void testContentEncodingConversion()
+ void contentEncodingConversion()
{
- String contentEncoding = "my-test-encoding";
+ final String contentEncoding = "my-test-encoding";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getEncoding()).thenReturn(contentEncoding);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(contentEncoding, convertedMessage.getContentHeaderBody().getProperties().getEncodingAsString(),
"Unexpected content encoding");
@@ -149,170 +148,150 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testLongContentEncodingConversion()
+ void longContentEncodingConversion()
{
- String contentEncoding = generateLongString();
+ final String contentEncoding = generateLongString();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getEncoding()).thenReturn(contentEncoding);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- try
- {
- _messageConverter.convert(originalMessage, _addressSpace);
- fail("Expected exception is not thrown");
- }
- catch (MessageConversionException e)
- {
- // pass
- }
+ assertThrows(MessageConversionException.class,
+ () -> _messageConverter.convert(originalMessage, _addressSpace),
+ "Expected exception is not thrown");
}
@Test
- public void testMessageIdConversion()
+ void messageIdConversion()
{
final String messageId = "testMessageId";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getMessageId()).thenReturn(messageId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(messageId, convertedMessage.getContentHeaderBody().getProperties().getMessageIdAsString(),
"Unexpected messageId");
}
@Test
- public void testMessageIdConversionWhenLengthExceeds255()
+ void messageIdConversionWhenLengthExceeds255()
{
final String messageId = generateLongString();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getMessageId()).thenReturn(messageId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertNull(convertedMessage.getContentHeaderBody().getProperties().getMessageId(), "Unexpected messageId");
-
}
@Test
- public void testCorrelationIdConversionWhenLengthExceeds255()
+ void correlationIdConversionWhenLengthExceeds255()
{
final String correlationId = generateLongString();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getCorrelationId()).thenReturn(correlationId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- try
- {
- _messageConverter.convert(originalMessage, _addressSpace);
- fail("Expected exception is not thrown");
- }
- catch (MessageConversionException e)
- {
- // pass
- }
+ assertThrows(MessageConversionException.class,
+ () -> _messageConverter.convert(originalMessage, _addressSpace),
+ "Expected exception is not thrown");
}
@Test
- public void testUserIdConversion()
+ void userIdConversion()
{
final String userId = "testUserId";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getUserId()).thenReturn(userId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(userId, convertedMessage.getContentHeaderBody().getProperties().getUserIdAsString(),
"Unexpected userId");
}
@Test
- public void testUserIdConversionWhenLengthExceeds255()
+ void userIdConversionWhenLengthExceeds255()
{
final String userId = generateLongString();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getUserId()).thenReturn(userId);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertNull(convertedMessage.getContentHeaderBody().getProperties().getUserId(), "Unexpected userId");
}
@Test
- public void testTimestampConversion()
+ void timestampConversion()
{
final long timestamp = System.currentTimeMillis();
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getTimestamp()).thenReturn(timestamp);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(timestamp, convertedMessage.getContentHeaderBody().getProperties().getTimestamp(),
"Unexpected timestamp");
}
@Test
- public void testHeadersConversion()
+ void headersConversion()
{
- final Map<String, Object> properties = new HashMap<>();
- properties.put("testProperty1", "testProperty1Value");
- properties.put("intProperty", 1);
+ final Map<String, Object> properties = Map.of("testProperty1", "testProperty1Value",
+ "intProperty", 1);
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getHeaderNames()).thenReturn(properties.keySet());
doAnswer(invocation ->
- {
- final String originalArgument = (String) (invocation.getArguments())[0];
- return properties.get(originalArgument);
- }).when(header).getHeader(any(String.class));
- InternalMessage originalMessage = createTestMessage(header);
+ {
+ final String originalArgument = (String) (invocation.getArguments())[0];
+ return properties.get(originalArgument);
+ }).when(header).getHeader(any(String.class));
+ final InternalMessage originalMessage = createTestMessage(header);
final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
- Map<String, Object> convertedHeaders = convertedMessage.getContentHeaderBody().getProperties().getHeadersAsMap();
+ final Map<String, Object> convertedHeaders = convertedMessage.getContentHeaderBody().getProperties().getHeadersAsMap();
assertEquals(properties, new HashMap<>(convertedHeaders), "Unexpected application properties");
}
@Test
- public void testHeadersConversionWhenKeyLengthExceeds255()
+ void headersConversionWhenKeyLengthExceeds255()
{
- final Map<String, Object> properties = Collections.singletonMap(generateLongString(), "test");
+ final Map<String, Object> properties = Map.of(generateLongString(), "test");
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getHeaderNames()).thenReturn(properties.keySet());
doAnswer(invocation ->
- {
- final String originalArgument = (String) (invocation.getArguments())[0];
- return properties.get(originalArgument);
- }).when(header).getHeader(any(String.class));
- InternalMessage originalMessage = createTestMessage(header);
-
- try
{
- _messageConverter.convert(originalMessage, _addressSpace);
- fail("Expected exception not thrown");
- }
- catch (MessageConversionException e)
- {
- // pass
- }
+ final String originalArgument = (String) (invocation.getArguments())[0];
+ return properties.get(originalArgument);
+ }).when(header).getHeader(any(String.class));
+ final InternalMessage originalMessage = createTestMessage(header);
+
+ assertThrows(MessageConversionException.class,
+ () -> _messageConverter.convert(originalMessage, _addressSpace),
+ "Expected exception not thrown");
}
@Test
- public void testReplyToConversionWhenQueueIsSpecified()
+ void replyToConversionWhenQueueIsSpecified()
{
final String replyTo = "testQueue";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getReplyTo()).thenReturn(replyTo);
- Queue queue = mock(Queue.class);
+ final Queue<?> queue = mock(Queue.class);
when(queue.getName()).thenReturn(replyTo);
doReturn(queue).when(_addressSpace).getAttainedMessageDestination(eq(replyTo), anyBoolean());
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals("direct:////" + replyTo,
convertedMessage.getContentHeaderBody().getProperties().getReplyToAsString(),
@@ -320,20 +299,20 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testReplyToConversionWhenExchangeIsSpecified()
+ void replyToConversionWhenExchangeIsSpecified()
{
final String replyTo = "testExchange";
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getReplyTo()).thenReturn(replyTo);
- Exchange exchange = mock(Exchange.class);
+ final Exchange<?> exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(replyTo);
when(exchange.getType()).thenReturn(ExchangeDefaults.FANOUT_EXCHANGE_CLASS);
doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(replyTo), anyBoolean());
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals("fanout://" + replyTo + "//",
convertedMessage.getContentHeaderBody().getProperties().getReplyToAsString(),
@@ -341,22 +320,22 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified()
+ void replyToConversionWhenExchangeAndRoutingKeyAreSpecified()
{
final String exchangeName = "testExchange";
final String routingKey = "testKey";
final String replyTo = String.format("%s/%s", exchangeName, routingKey);
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getReplyTo()).thenReturn(replyTo);
- Exchange exchange = mock(Exchange.class);
+ final Exchange<?> exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(exchangeName);
when(exchange.getType()).thenReturn(ExchangeDefaults.TOPIC_EXCHANGE_CLASS);
doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(exchangeName), anyBoolean());
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals("topic://" + exchangeName + "//?routingkey='" + routingKey + "'",
convertedMessage.getContentHeaderBody().getProperties().getReplyToAsString(),
@@ -364,7 +343,7 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testReplyToConversionWhenNonExistingExchangeAndRoutingKeyAreSpecified()
+ void replyToConversionWhenNonExistingExchangeAndRoutingKeyAreSpecified()
{
final String exchangeName = "testExchange";
final String routingKey = "testKey";
@@ -372,9 +351,9 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
final AMQMessageHeader header = mock(AMQMessageHeader.class);
when(header.getReplyTo()).thenReturn(replyTo);
- InternalMessage originalMessage = createTestMessage(header);
+ final InternalMessage originalMessage = createTestMessage(header);
- AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final AMQMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals("direct:////?routingkey='" + replyTo + "'",
convertedMessage.getContentHeaderBody().getProperties().getReplyToAsString(),
@@ -382,16 +361,16 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testToConversionWhenExchangeAndRoutingKeyIsSpecified()
+ void toConversionWhenExchangeAndRoutingKeyIsSpecified()
{
final String testExchange = "testExchange";
final String testRoutingKey = "testRoutingKey";
- String to = testExchange + "/" + testRoutingKey;
+ final String to = testExchange + "/" + testRoutingKey;
- InternalMessage message = createTestMessage(to);
+ final InternalMessage message = createTestMessage(to);
- Exchange<?> exchange = mock(Exchange.class);
+ final Exchange<?> exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(testExchange);
doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(testExchange), anyBoolean());
@@ -405,12 +384,12 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testToConversionWhenExchangeIsSpecified()
+ void toConversionWhenExchangeIsSpecified()
{
final String testExchange = "testExchange";
- InternalMessage message = createTestMessage(testExchange);
+ final InternalMessage message = createTestMessage(testExchange);
- final Exchange exchange = mock(Exchange.class);
+ final Exchange<?> exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(testExchange);
doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(testExchange), anyBoolean());
@@ -423,16 +402,16 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testConversionWhenToIsUnsetButInitialRoutingKeyIsSet()
+ void conversionWhenToIsUnsetButInitialRoutingKeyIsSet()
{
final String testExchange = "testExchange";
final String testRoutingKey = "testRoutingKey";
- InternalMessage message = createTestMessage("");
+ final InternalMessage message = createTestMessage("");
final String testInitialRoutingAddress = testExchange + "/" + testRoutingKey;
message.setInitialRoutingAddress(testInitialRoutingAddress);
- final Exchange exchange = mock(Exchange.class);
+ final Exchange<?> exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(testExchange);
doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(testExchange), anyBoolean());
@@ -445,12 +424,12 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testToConversionWhenQueueIsSpecified()
+ void toConversionWhenQueueIsSpecified()
{
final String testQueue = "testQueue";
- InternalMessage message = createTestMessage(testQueue);
+ final InternalMessage message = createTestMessage(testQueue);
- final Queue queue = mock(Queue.class);
+ final Queue<?> queue = mock(Queue.class);
when(queue.getName()).thenReturn(testQueue);
doReturn(queue).when(_addressSpace).getAttainedMessageDestination(eq(testQueue), anyBoolean());
@@ -463,15 +442,15 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testToConversionWhenGlobalAddressIsUnknown()
+ void toConversionWhenGlobalAddressIsUnknown()
{
final String globalPrefix = "/testPrefix";
final String queueName = "testQueue";
final String globalAddress = globalPrefix + "/" + queueName;
- InternalMessage message = createTestMessage(globalAddress);
+ final InternalMessage message = createTestMessage(globalAddress);
- Queue<?> queue = mock(Queue.class);
+ final Queue<?> queue = mock(Queue.class);
when(queue.getName()).thenReturn(queueName);
doReturn(queue).when(_addressSpace).getAttainedMessageDestination(eq(queueName), anyBoolean());
@@ -484,15 +463,15 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testToConversionWhenGlobalAddressIsKnown()
+ void toConversionWhenGlobalAddressIsKnown()
{
final String globalPrefix = "/testPrefix";
final String queueName = "testQueue";
final String globalAddress = globalPrefix + "/" + queueName;
- InternalMessage message = createTestMessage(globalAddress);
+ final InternalMessage message = createTestMessage(globalAddress);
- Queue<?> queue = mock(Queue.class);
+ final Queue<?> queue = mock(Queue.class);
when(queue.getName()).thenReturn(queueName);
doReturn(queue).when(_addressSpace).getAttainedMessageDestination(eq(queueName), anyBoolean());
when(_addressSpace.getLocalAddress(globalAddress)).thenReturn(queueName);
@@ -506,53 +485,41 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
@Test
- public void testToConversionWhenExchangeLengthExceeds255()
+ void toConversionWhenExchangeLengthExceeds255()
{
final String testExchange = generateLongString();
final String testRoutingKey = "testRoutingKey";
- String to = testExchange + "/" + testRoutingKey;
+ final String to = testExchange + "/" + testRoutingKey;
- InternalMessage message = createTestMessage(to);
+ final InternalMessage message = createTestMessage(to);
- try
- {
- _messageConverter.convert(message, _addressSpace);
- fail("Exception is not thrown");
- }
- catch (MessageConversionException e)
- {
- // pass
- }
+ assertThrows(MessageConversionException.class,
+ () -> _messageConverter.convert(message, _addressSpace),
+ "Exception is not thrown");
}
@Test
- public void testToConversionWhenRoutingKeyLengthExceeds255()
+ void toConversionWhenRoutingKeyLengthExceeds255()
{
final String testExchange = "testExchange";
final String testRoutingKey = generateLongString();
- String to = testExchange + "/" + testRoutingKey;
+ final String to = testExchange + "/" + testRoutingKey;
- InternalMessage message = createTestMessage(to);
+ final InternalMessage message = createTestMessage(to);
- try
- {
- _messageConverter.convert(message, _addressSpace);
- fail("Exception is not thrown");
- }
- catch (MessageConversionException e)
- {
- // pass
- }
+ assertThrows(MessageConversionException.class,
+ () -> _messageConverter.convert(message, _addressSpace),
+ "Exception is not thrown");
}
@Test
- public void testToConversionWhenDestinationIsSpecifiedButDoesNotExists()
+ void toConversionWhenDestinationIsSpecifiedButDoesNotExists()
{
final String testDestination = "testDestination";
- InternalMessage message = createTestMessage(testDestination);
+ final InternalMessage message = createTestMessage(testDestination);
final AMQMessage convertedMessage = _messageConverter.convert(message, _addressSpace);
@@ -568,7 +535,7 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
}
private InternalMessage createTestMessage(final AMQMessageHeader header,
- byte[] content,
+ final byte[] content,
final boolean persistent)
{
final InternalMessageHeader internalMessageHeader = new InternalMessageHeader(header);
@@ -591,7 +558,7 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
return storedMessage;
}
- private InternalMessage createTestMessage(String to)
+ private InternalMessage createTestMessage(final String to)
{
final InternalMessageHeader internalMessageHeader = new InternalMessageHeader(mock(AMQMessageHeader.class));
final StoredMessage<InternalMessageMetaData> handle =
@@ -606,12 +573,6 @@ public class PropertyConverter_Internal_to_v0_8Test extends UnitTestBase
private String generateLongString(int stringLength)
{
- StringBuilder buffer = new StringBuilder();
- for (int i = 0; i < stringLength; i++)
- {
- buffer.append('x');
- }
-
- return buffer.toString();
+ return "x".repeat(Math.max(0, stringLength));
}
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_v0_8_to_InternalTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_v0_8_to_InternalTest.java
index ed7cd1889c..b30d7387c5 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_v0_8_to_InternalTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/PropertyConverter_v0_8_to_InternalTest.java
@@ -42,26 +42,26 @@ import org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class PropertyConverter_v0_8_to_InternalTest extends UnitTestBase
+class PropertyConverter_v0_8_to_InternalTest extends UnitTestBase
{
private MessageConverter_v0_8_to_Internal _messageConverter;
private NamedAddressSpace _addressSpace;
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
_messageConverter = new MessageConverter_v0_8_to_Internal();
_addressSpace = mock(NamedAddressSpace.class);
}
@Test
- public void testDeliveryModePersistentConversion()
+ void deliveryModePersistentConversion()
{
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setDeliveryMode(BasicContentHeaderProperties.PERSISTENT);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertTrue(convertedMessage.isPersistent(), "Unexpected persistence of message");
assertTrue(convertedMessage.getStoredMessage().getMetaData().isPersistent(),
@@ -69,13 +69,13 @@ public class PropertyConverter_v0_8_to_InternalTest extends UnitTestBase
}
@Test
- public void testDeliveryModeNonPersistentConversion()
+ void deliveryModeNonPersistentConversion()
{
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setDeliveryMode(BasicContentHeaderProperties.NON_PERSISTENT);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertFalse(convertedMessage.isPersistent(), "Unexpected persistence of message");
assertFalse(convertedMessage.getStoredMessage().getMetaData().isPersistent(),
@@ -83,165 +83,163 @@ public class PropertyConverter_v0_8_to_InternalTest extends UnitTestBase
}
@Test
- public void testPriorityConversion()
+ void priorityConversion()
{
- byte priority = (byte) 7;
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final byte priority = (byte) 7;
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setPriority(priority);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(priority, (long) convertedMessage.getMessageHeader().getPriority(), "Unexpected priority");
-
}
@Test
- public void testExpirationConversion()
+ void expirationConversion()
{
- long ttl = 10000;
- long arrivalTime = System.currentTimeMillis();
- long expiryTime = arrivalTime + ttl;
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final long ttl = 10000;
+ final long arrivalTime = System.currentTimeMillis();
+ final long expiryTime = arrivalTime + ttl;
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setExpiration(expiryTime);
final AMQMessage originalMessage = createTestMessage(header, arrivalTime);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(expiryTime, convertedMessage.getMessageHeader().getExpiration(), "Unexpected expiration");
}
@Test
- public void testContentEncodingConversion()
+ void contentEncodingConversion()
{
- String contentEncoding = "my-test-encoding";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final String contentEncoding = "my-test-encoding";
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setEncoding(contentEncoding);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(contentEncoding, convertedMessage.getMessageHeader().getEncoding(), "Unexpected content encoding");
}
@Test
- public void testMessageIdConversion()
+ void messageIdConversion()
{
final String messageId = "testMessageId";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setMessageId(messageId);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(messageId, convertedMessage.getMessageHeader().getMessageId(), "Unexpected messageId");
}
@Test
- public void testCorrelationIdStringConversion()
+ void correlationIdStringConversion()
{
final String correlationId = "testMessageCorrelationId";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setCorrelationId(correlationId);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(correlationId, convertedMessage.getMessageHeader().getCorrelationId(), "Unexpected correlationId");
}
@Test
- public void testUserIdConversion()
+ void userIdConversion()
{
final String userId = "testUserId";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setUserId(userId);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(userId, convertedMessage.getMessageHeader().getUserId(), "Unexpected userId");
}
@Test
- public void testReplyToConversionForDirectExchangeAndRoutingKey()
+ void replyToConversionForDirectExchangeAndRoutingKey()
{
- String exchangeName = "amq.direct";
- String routingKey = "testRoutingKey";
+ final String exchangeName = "amq.direct";
+ final String routingKey = "testRoutingKey";
final String replyTo = String.format("%s://%s//?routingkey='%s'", "direct", exchangeName, routingKey);
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setReplyTo(replyTo);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(exchangeName + "/" + routingKey, convertedMessage.getMessageHeader().getReplyTo(),
"Unexpected replyTo");
}
@Test
- public void testReplyToConversionForFanoutExchange()
+ void replyToConversionForFanoutExchange()
{
- String exchangeName = "amq.fanout";
+ final String exchangeName = "amq.fanout";
final String replyTo = String.format("%s://%s//", "fanout", exchangeName);
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setReplyTo(replyTo);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(exchangeName, convertedMessage.getMessageHeader().getReplyTo(), "Unexpected replyTo");
}
@Test
- public void testReplyToConversionForDefaultDestination()
+ void replyToConversionForDefaultDestination()
{
- String exchangeName = "";
- String routingKey = "testRoutingKey";
+ final String exchangeName = "";
+ final String routingKey = "testRoutingKey";
final String replyTo = String.format("%s://%s//?routingkey='%s'", "direct", exchangeName, routingKey);
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setReplyTo(replyTo);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(routingKey, convertedMessage.getMessageHeader().getReplyTo(), "Unexpected replyTo");
}
@Test
- public void testReplyToNonBurl()
+ void replyToNonBurl()
{
final String replyTo = "test/routing";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setReplyTo(replyTo);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(replyTo, convertedMessage.getMessageHeader().getReplyTo(), "Unexpected replyTo");
}
@Test
- public void testTimestampConversion()
+ void timestampConversion()
{
final long creationTime = System.currentTimeMillis();
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setTimestamp(creationTime);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(creationTime, convertedMessage.getMessageHeader().getTimestamp(), "Unexpected timestamp");
}
@Test
- public void testHeadersConversion()
+ void headersConversion()
{
- Map<String, Object> properties = new HashMap<>();
- properties.put("testProperty1", "testProperty1Value");
- properties.put("intProperty", 1);
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final Map<String, Object> properties = Map.of("testProperty1", "testProperty1Value",
+ "intProperty", 1);
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setHeaders(FieldTable.convertToFieldTable(properties));
final AMQMessage originalMessage = createTestMessage(header);
@@ -252,46 +250,46 @@ public class PropertyConverter_v0_8_to_InternalTest extends UnitTestBase
}
@Test
- public void testContentTypeConversion()
+ void contentTypeConversion()
{
final String contentType = "text/json";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setContentType(contentType);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(contentType, convertedMessage.getMessageHeader().getMimeType(), "Unexpected content type");
}
@Test
- public void testTypeConversion()
+ void typeConversion()
{
final String type = "JMSType";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setType(type);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(type, convertedMessage.getMessageHeader().getType(), "Unexpected type");
}
@Test
- public void testApplicationIdConversion()
+ void applicationIdConversion()
{
final String applicationId = "appId";
- BasicContentHeaderProperties header = new BasicContentHeaderProperties();
+ final BasicContentHeaderProperties header = new BasicContentHeaderProperties();
header.setAppId(applicationId);
final AMQMessage originalMessage = createTestMessage(header);
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(applicationId, convertedMessage.getMessageHeader().getAppId(), "Unexpected applicationId");
}
@Test
- public void testBasicPublishConversion()
+ void basicPublishConversion()
{
final String exchangeName = "amq.direct";
final String testRoutingKey = "test-routing-key";
@@ -300,7 +298,7 @@ public class PropertyConverter_v0_8_to_InternalTest extends UnitTestBase
originalMessage.getMessagePublishInfo().setRoutingKey(AMQShortString.valueOf(testRoutingKey));
originalMessage.getMessagePublishInfo().setExchange(AMQShortString.valueOf(exchangeName));
- InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
+ final InternalMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
assertEquals(exchangeName, convertedMessage.getTo(), "Unexpected to");
@@ -313,13 +311,14 @@ public class PropertyConverter_v0_8_to_InternalTest extends UnitTestBase
}
private AMQMessage createTestMessage(final BasicContentHeaderProperties basicContentHeaderProperties,
- long arrivalTime)
+ final long arrivalTime)
{
return createTestMessage(basicContentHeaderProperties, null, arrivalTime);
}
private AMQMessage createTestMessage(final BasicContentHeaderProperties basicContentHeaderProperties,
- final byte[] content, final long arrivalTime)
+ final byte[] content,
+ final long arrivalTime)
{
final ContentHeaderBody contentHeaderBody = mock(ContentHeaderBody.class);
when(contentHeaderBody.getProperties()).thenReturn(basicContentHeaderProperties);
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java
index f87d0f375b..f45920a5e4 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/ReferenceCountingTest.java
@@ -44,13 +44,13 @@ import org.apache.qpid.test.utils.UnitTestBase;
/**
* Tests that reference counting works correctly with AMQMessage and the message store
*/
-public class ReferenceCountingTest extends UnitTestBase
+@SuppressWarnings({"rawtypes", "unchecked"})
+class ReferenceCountingTest extends UnitTestBase
{
private TestMemoryMessageStore _store;
-
@BeforeEach
- public void setUp() throws Exception
+ void setUp() throws Exception
{
_store = new TestMemoryMessageStore();
}
@@ -59,21 +59,21 @@ public class ReferenceCountingTest extends UnitTestBase
* Check that when the reference count is decremented the message removes itself from the store
*/
@Test
- public void testMessageGetsRemoved()
+ void messageGetsRemoved()
{
- ContentHeaderBody chb = createPersistentContentHeader();
+ final ContentHeaderBody chb = createPersistentContentHeader();
- MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
+ final MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
final MessageMetaData mmd = new MessageMetaData(info, chb);
- StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
- Transaction txn = _store.newTransaction();
+ final StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
+ final Transaction txn = _store.newTransaction();
txn.enqueueMessage(createTransactionLogResource("dummyQ"), createEnqueueableMessage(storedMessage));
txn.commitTran();
- AMQMessage message = new AMQMessage(storedMessage);
+ final AMQMessage message = new AMQMessage(storedMessage);
- MessageReference ref = message.newReference();
+ final MessageReference ref = message.newReference();
assertEquals(1, (long) getStoreMessageCount());
@@ -84,40 +84,37 @@ public class ReferenceCountingTest extends UnitTestBase
private int getStoreMessageCount()
{
- MessageCounter counter = new MessageCounter();
+ final MessageCounter counter = new MessageCounter();
_store.newMessageStoreReader().visitMessages(counter);
return counter.getCount();
}
private ContentHeaderBody createPersistentContentHeader()
{
- BasicContentHeaderProperties bchp = new BasicContentHeaderProperties();
- bchp.setDeliveryMode((byte)2);
- ContentHeaderBody chb = new ContentHeaderBody(bchp);
- return chb;
+ final BasicContentHeaderProperties bchp = new BasicContentHeaderProperties();
+ bchp.setDeliveryMode((byte) 2);
+ return new ContentHeaderBody(bchp);
}
@Test
- public void testMessageRemains()
+ void testMessageRemains()
{
-
- MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
+ final MessagePublishInfo info = new MessagePublishInfo(null, false, false, null);
final ContentHeaderBody chb = createPersistentContentHeader();
final MessageMetaData mmd = new MessageMetaData(info, chb);
- StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
- Transaction txn = _store.newTransaction();
+ final StoredMessage storedMessage = _store.addMessage(mmd).allContentAdded();
+ final Transaction txn = _store.newTransaction();
txn.enqueueMessage(createTransactionLogResource("dummyQ"), createEnqueueableMessage(storedMessage));
txn.commitTran();
- AMQMessage message = new AMQMessage(storedMessage);
-
+ final AMQMessage message = new AMQMessage(storedMessage);
- MessageReference ref = message.newReference();
+ final MessageReference ref = message.newReference();
assertEquals(1, (long) getStoreMessageCount());
- MessageReference ref2 = message.newReference();
+ final MessageReference ref2 = message.newReference();
ref.release();
assertEquals(1, (long) getStoreMessageCount());
}
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java
index fbe5f054f8..e7ab8cd20c 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/UnacknowledgedMessageMapTest.java
@@ -26,9 +26,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Collection;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
@@ -37,24 +36,26 @@ import org.apache.qpid.server.message.MessageInstanceConsumer;
import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.test.utils.UnitTestBase;
-public class UnacknowledgedMessageMapTest extends UnitTestBase
+@SuppressWarnings({"rawtypes", "unchecked"})
+class UnacknowledgedMessageMapTest extends UnitTestBase
{
public static final Function<MessageConsumerAssociation, MessageInstance>
- MESSAGE_INSTANCE_FUNCTION = input -> input.getMessageInstance();
+ MESSAGE_INSTANCE_FUNCTION = MessageConsumerAssociation::getMessageInstance;
private final MessageInstanceConsumer _consumer = mock(MessageInstanceConsumer.class);
@Test
- public void testDeletedMessagesCantBeAcknowledged()
+ void deletedMessagesCantBeAcknowledged()
{
UnacknowledgedMessageMap map = new UnacknowledgedMessageMapImpl(100, mock(CreditRestorer.class));
final int expectedSize = 5;
MessageInstance[] msgs = populateMap(map,expectedSize);
assertEquals(expectedSize, (long) map.size());
Collection<MessageConsumerAssociation> acknowledged = map.acknowledge(100, true);
- Collection<MessageInstance> acknowledgedMessages = Collections2.transform(acknowledged, MESSAGE_INSTANCE_FUNCTION);
+ Collection<MessageInstance> acknowledgedMessages = acknowledged.stream().map(MESSAGE_INSTANCE_FUNCTION)
+ .collect(Collectors.toList());
assertEquals(expectedSize, (long) acknowledged.size());
assertEquals(0, (long) map.size());
- for(int i = 0; i < expectedSize; i++)
+ for (int i = 0; i < expectedSize; i++)
{
assertTrue(acknowledgedMessages.contains(msgs[i]), "Message " + i + " is missing");
}
@@ -68,32 +69,33 @@ public class UnacknowledgedMessageMapTest extends UnitTestBase
assertEquals(expectedSize, (long) map.size());
acknowledged = map.acknowledge(100, true);
- acknowledgedMessages = Collections2.transform(acknowledged, MESSAGE_INSTANCE_FUNCTION);
+ acknowledgedMessages = acknowledged.stream().map(MESSAGE_INSTANCE_FUNCTION)
+ .collect(Collectors.toList());
assertEquals(expectedSize - 2, (long) acknowledged.size());
assertEquals(0, (long) map.size());
- for(int i = 0; i < expectedSize; i++)
+ for (int i = 0; i < expectedSize; i++)
{
assertEquals(i != 2 && i != 4, acknowledgedMessages.contains(msgs[i]));
}
}
- public MessageInstance[] populateMap(final UnacknowledgedMessageMap map, int size)
+ MessageInstance[] populateMap(final UnacknowledgedMessageMap map, final int size)
{
- MessageInstance[] msgs = new MessageInstance[size];
- for(int i = 0; i < size; i++)
+ final MessageInstance[] msgs = new MessageInstance[size];
+ for (int i = 0; i < size; i++)
{
- msgs[i] = createMessageInstance(i);
- map.add((long)i, msgs[i], _consumer, true);
+ msgs[i] = createMessageInstance();
+ map.add(i, msgs[i], _consumer, true);
}
return msgs;
}
- private MessageInstance createMessageInstance(final int id)
+ private MessageInstance createMessageInstance()
{
- MessageInstance instance = mock(MessageInstance.class);
+ final MessageInstance instance = mock(MessageInstance.class);
when(instance.makeAcquisitionUnstealable(_consumer)).thenReturn(Boolean.TRUE);
when(instance.getAcquiringConsumer()).thenReturn(_consumer);
- ServerMessage message = mock(ServerMessage.class);
+ final ServerMessage<?> message = mock(ServerMessage.class);
when(message.getSize()).thenReturn(0L);
when(instance.getMessage()).thenReturn(message);
return instance;
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderPropertiesTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderPropertiesTest.java
index bc8dd3876a..47d0a59762 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderPropertiesTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/BasicContentHeaderPropertiesTest.java
@@ -23,7 +23,6 @@ package org.apache.qpid.server.protocol.v0_8.transport;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
@@ -35,8 +34,12 @@ import org.apache.qpid.server.protocol.v0_8.FieldTable;
import org.apache.qpid.server.protocol.v0_8.FieldTableFactory;
import org.apache.qpid.test.utils.UnitTestBase;
-public class BasicContentHeaderPropertiesTest extends UnitTestBase
+class BasicContentHeaderPropertiesTest extends UnitTestBase
{
+ private static final int BUFFER_SIZE = 1024 * 10;
+ private static final int POOL_SIZE = 20;
+ private static final double SPARSITY_FRACTION = 0.5;
+
private final String _testString = "This is a test string";
private BasicContentHeaderProperties _testProperties;
private FieldTable _testTable;
@@ -50,11 +53,10 @@ public class BasicContentHeaderPropertiesTest extends UnitTestBase
}
@BeforeEach
- public void setUp() throws Exception
+ void setUp()
{
- Map<String, Object> headers = new LinkedHashMap<>();
- headers.put("TestString", _testString);
- headers.put("Testint", Integer.MAX_VALUE);
+ final Map<String, Object> headers = Map.of("TestString", _testString,
+ "Testint", Integer.MAX_VALUE);
_testTable = FieldTableFactory.createFieldTable(headers);
_testProperties = new BasicContentHeaderProperties();
@@ -62,7 +64,7 @@ public class BasicContentHeaderPropertiesTest extends UnitTestBase
}
@Test
- public void testGetPropertyListSize()
+ void getPropertyListSize()
{
//needs a better test but at least we're exercising the code !
// FT length is encoded in an int
@@ -76,84 +78,83 @@ public class BasicContentHeaderPropertiesTest extends UnitTestBase
// 1 is for the Encoding Letter. here an 'S'
expectedSize += 1 + EncodingUtils.encodedLongStringLength(_testString);
-
- int size = _testProperties.getPropertyListSize();
+ final int size = _testProperties.getPropertyListSize();
assertEquals(expectedSize, (long) size);
}
@Test
- public void testGetSetPropertyFlags()
+ void getSetPropertyFlags()
{
_testProperties.setPropertyFlags(99);
assertEquals(99, (long) _testProperties.getPropertyFlags());
}
@Test
- public void testPopulatePropertiesFromBuffer() throws Exception
+ void populatePropertiesFromBuffer() throws Exception
{
- QpidByteBuffer buf = QpidByteBuffer.wrap(new byte[300]);
+ final QpidByteBuffer buf = QpidByteBuffer.wrap(new byte[300]);
_testProperties.dispose();
_testProperties = new BasicContentHeaderProperties(buf, 99, 99);
}
@Test
- public void testSetGetContentType()
+ void setGetContentType()
{
- String contentType = "contentType";
+ final String contentType = "contentType";
_testProperties.setContentType(contentType);
assertEquals(contentType, _testProperties.getContentTypeAsString());
}
@Test
- public void testSetGetEncoding()
+ void setGetEncoding()
{
- String encoding = "encoding";
+ final String encoding = "encoding";
_testProperties.setEncoding(encoding);
assertEquals(encoding, _testProperties.getEncodingAsString());
}
@Test
- public void testSetGetHeaders()
+ void setGetHeaders()
{
_testProperties.setHeaders(_testTable);
assertEquals(FieldTable.convertToMap(_testTable), _testProperties.getHeadersAsMap());
}
@Test
- public void testSetGetDeliveryMode()
+ void setGetDeliveryMode()
{
- byte deliveryMode = 1;
+ final byte deliveryMode = 1;
_testProperties.setDeliveryMode(deliveryMode);
assertEquals(deliveryMode, (long) _testProperties.getDeliveryMode());
}
@Test
- public void testSetGetPriority()
+ void setGetPriority()
{
- byte priority = 1;
+ final byte priority = 1;
_testProperties.setPriority(priority);
assertEquals(priority, (long) _testProperties.getPriority());
}
@Test
- public void testSetGetCorrelationId()
+ void setGetCorrelationId()
{
- String correlationId = "correlationId";
+ final String correlationId = "correlationId";
_testProperties.setCorrelationId(correlationId);
assertEquals(correlationId, _testProperties.getCorrelationIdAsString());
}
@Test
- public void testSetGetReplyTo()
+ void setGetReplyTo()
{
- String replyTo = "replyTo";
+ final String replyTo = "replyTo";
_testProperties.setReplyTo(replyTo);
assertEquals(replyTo, _testProperties.getReplyToAsString());
}
@Test
- public void testSetGetExpiration()
+ void setGetExpiration()
{
long expiration = 999999999;
_testProperties.setExpiration(expiration);
@@ -164,65 +165,61 @@ public class BasicContentHeaderPropertiesTest extends UnitTestBase
}
@Test
- public void testSetGetMessageId()
+ void setGetMessageId()
{
- String messageId = "messageId";
+ final String messageId = "messageId";
_testProperties.setMessageId(messageId);
assertEquals(messageId, _testProperties.getMessageIdAsString());
}
@Test
- public void testSetGetTimestamp()
+ void setGetTimestamp()
{
- long timestamp = System.currentTimeMillis();
+ final long timestamp = System.currentTimeMillis();
_testProperties.setTimestamp(timestamp);
assertEquals(timestamp, _testProperties.getTimestamp());
}
@Test
- public void testSetGetType()
+ void setGetType()
{
- String type = "type";
+ final String type = "type";
_testProperties.setType(type);
assertEquals(type, _testProperties.getTypeAsString());
}
@Test
- public void testSetGetUserId()
+ void setGetUserId()
{
- String userId = "userId";
+ final String userId = "userId";
_testProperties.setUserId(userId);
assertEquals(userId, _testProperties.getUserIdAsString());
}
@Test
- public void testSetGetAppId()
+ void setGetAppId()
{
- String appId = "appId";
+ final String appId = "appId";
_testProperties.setAppId(appId);
assertEquals(appId, _testProperties.getAppIdAsString());
}
@Test
- public void testSetGetClusterId()
+ void setGetClusterId()
{
- String clusterId = "clusterId";
+ final String clusterId = "clusterId";
_testProperties.setClusterId(clusterId);
assertEquals(clusterId, _testProperties.getClusterIdAsString());
}
- private static final int BUFFER_SIZE = 1024 * 10;
- private static final int POOL_SIZE = 20;
- private static final double SPARSITY_FRACTION = 0.5;
-
@Test
- public void testReallocate() throws Exception
+ void reallocate() throws Exception
{
try
{
QpidByteBuffer.deinitialisePool();
QpidByteBuffer.initialisePool(BUFFER_SIZE, POOL_SIZE, SPARSITY_FRACTION);
- try (QpidByteBuffer buffer = QpidByteBuffer.allocateDirect(BUFFER_SIZE))
+ try (final QpidByteBuffer buffer = QpidByteBuffer.allocateDirect(BUFFER_SIZE))
{
// set some test fields
_testProperties.setContentType("text/plain");
@@ -235,12 +232,12 @@ public class BasicContentHeaderPropertiesTest extends UnitTestBase
final int pos = BUFFER_SIZE - propertyListSize * 2;
buffer.position(pos);
- try (QpidByteBuffer propertiesBuffer = buffer.view(0, propertyListSize))
+ try (final QpidByteBuffer propertiesBuffer = buffer.view(0, propertyListSize))
{
_testProperties.writePropertyListPayload(propertiesBuffer);
propertiesBuffer.flip();
- BasicContentHeaderProperties testProperties = new BasicContentHeaderProperties(propertiesBuffer, flags, propertyListSize);
+ final BasicContentHeaderProperties testProperties = new BasicContentHeaderProperties(propertiesBuffer, flags, propertyListSize);
final Map<String, Object> headersBeforeReallocation = testProperties.getHeadersAsMap();
assertEquals(headers, headersBeforeReallocation, "Unexpected headers");
diff --git a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/MessagePublishInfoImplTest.java b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/MessagePublishInfoImplTest.java
index c85ec90800..5d7f5718b4 100644
--- a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/MessagePublishInfoImplTest.java
+++ b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/transport/MessagePublishInfoImplTest.java
@@ -30,24 +30,25 @@ import org.junit.jupiter.api.Test;
import org.apache.qpid.server.protocol.v0_8.AMQShortString;
import org.apache.qpid.test.utils.UnitTestBase;
-public class MessagePublishInfoImplTest extends UnitTestBase
+class MessagePublishInfoImplTest extends UnitTestBase
{
- private MessagePublishInfo _mpi;
private final AMQShortString _exchange = AMQShortString.createAMQShortString("exchange");
private final AMQShortString _routingKey = AMQShortString.createAMQShortString("routingKey");
+ private MessagePublishInfo _mpi;
+
@BeforeEach
- public void setUp() throws Exception
+ void setUp()
{
_mpi = new MessagePublishInfo(_exchange, true, true, _routingKey);
}
/** Test that we can update the exchange value. */
@Test
- public void testExchange()
+ void exchange()
{
assertEquals(_exchange, _mpi.getExchange());
- AMQShortString newExchange = AMQShortString.createAMQShortString("newExchange");
+ final AMQShortString newExchange = AMQShortString.createAMQShortString("newExchange");
//Check we can update the exchange
_mpi.setExchange(newExchange);
assertEquals(newExchange, _mpi.getExchange());
@@ -59,12 +60,12 @@ public class MessagePublishInfoImplTest extends UnitTestBase
* Check that the immedate value is set correctly and defaulted correctly
*/
@Test
- public void testIsImmediate()
+ void isImmediate()
{
//Check that the set value is correct
assertTrue(_mpi.isImmediate(), "Set value for immediate not as expected");
- MessagePublishInfo mpi = new MessagePublishInfo();
+ final MessagePublishInfo mpi = new MessagePublishInfo();
assertFalse(mpi.isImmediate(), "Default value for immediate should be false");
@@ -77,11 +78,11 @@ public class MessagePublishInfoImplTest extends UnitTestBase
* Check that the mandatory value is set correctly and defaulted correctly
*/
@Test
- public void testIsMandatory()
+ void isMandatory()
{
assertTrue(_mpi.isMandatory(), "Set value for mandatory not as expected");
- MessagePublishInfo mpi = new MessagePublishInfo();
+ final MessagePublishInfo mpi = new MessagePublishInfo();
assertFalse(mpi.isMandatory(), "Default value for mandatory should be false");
@@ -94,10 +95,10 @@ public class MessagePublishInfoImplTest extends UnitTestBase
* Check that the routingKey value is perserved
*/
@Test
- public void testRoutingKey()
+ void routingKey()
{
assertEquals(_routingKey, _mpi.getRoutingKey());
- AMQShortString newRoutingKey = AMQShortString.createAMQShortString("newRoutingKey");
+ final AMQShortString newRoutingKey = AMQShortString.createAMQShortString("newRoutingKey");
//Check we can update the routingKey
_mpi.setRoutingKey(newRoutingKey);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org