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 2026/09/14 08:48:09 UTC

(qpid-broker-j) branch main updated: QPID-8756: [Broker-J] AMQP-1.0 unsigned classes should use java 8+ APIs (#434)

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 7049ac46e1 QPID-8756: [Broker-J] AMQP-1.0 unsigned classes should use java 8+ APIs (#434)
7049ac46e1 is described below

commit 7049ac46e16a61ca57e9492fbd4c6d5e121a6d38
Author: Daniil Kirilyuk <da...@apache.org>
AuthorDate: Mon Sep 14 10:48:03 2026 +0200

    QPID-8756: [Broker-J] AMQP-1.0 unsigned classes should use java 8+ APIs (#434)
---
 .../protocol/v1_0/codec/UnsignedIntegerWriter.java |   2 +-
 .../server/protocol/v1_0/type/UnsignedByte.java    |   4 +-
 .../server/protocol/v1_0/type/UnsignedInteger.java |  17 +--
 .../server/protocol/v1_0/type/UnsignedLong.java    |  25 ++---
 .../server/protocol/v1_0/type/UnsignedShort.java   |   4 +-
 .../v1_0/type/messaging/TerminusDurability.java    |   2 +-
 .../qpid/server/protocol/v1_0/Session_1_0Test.java |   6 +-
 .../v1_0/StandardReceivingLinkEndpointTest.java    |   2 +-
 .../v1_0/codec/UnsignedIntegerWriterTest.java      |  47 ++++++++
 .../protocol/v1_0/store/LinkStoreTestCase.java     |   4 +-
 .../protocol/v1_0/type/UnsignedNumberTest.java     | 120 +++++++++++++++++++++
 .../SoleConnectionDetectionPolicyTest.java         |  10 +-
 .../SoleConnectionEnforcementPolicyTest.java       |  10 +-
 13 files changed, 207 insertions(+), 46 deletions(-)

diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UnsignedIntegerWriter.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UnsignedIntegerWriter.java
index 2470cdff1d..4c2a4856b0 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UnsignedIntegerWriter.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/codec/UnsignedIntegerWriter.java
@@ -57,7 +57,7 @@ public class UnsignedIntegerWriter
         {
             return ZERO_BYTE_WRITER;
         }
-        else if(uint.compareTo(UnsignedInteger.valueOf(256))<0)
+        else if(uint.longValue() < 256L)
         {
             return new UnsignedIntegerFixedOneWriter(uint);
         }
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedByte.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedByte.java
index 564ec317a9..d7c01f7984 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedByte.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedByte.java
@@ -36,6 +36,8 @@ public final class UnsignedByte extends Number implements Comparable<UnsignedByt
         }
     }
 
+    /** Deprecated, use {@link UnsignedByte#valueOf(byte)}, planned for removal in version 12.0.0 */
+    @Deprecated(forRemoval = true)
     public UnsignedByte(byte underlying)
     {
         _underlying = underlying;
@@ -97,7 +99,7 @@ public final class UnsignedByte extends Number implements Comparable<UnsignedByt
     @Override
     public int compareTo(UnsignedByte o)
     {
-        return Integer.signum(intValue() - o.intValue());
+        return Byte.compareUnsigned(_underlying, o._underlying);
     }
 
     @Override
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedInteger.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedInteger.java
index 1afabbd108..85d97b0d42 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedInteger.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedInteger.java
@@ -40,7 +40,8 @@ public final class UnsignedInteger extends Number implements Comparable<Unsigned
     public static final UnsignedInteger ONE = cachedValues[1];
     public static final UnsignedInteger MAX_VALUE = new UnsignedInteger(0xffffffff);
 
-
+    /** Deprecated, use {@link UnsignedInteger#valueOf(int)}, planned for removal in version 12.0.0 */
+    @Deprecated(forRemoval = true)
     public UnsignedInteger(int underlying)
     {
         _underlying = underlying;
@@ -90,7 +91,7 @@ public final class UnsignedInteger extends Number implements Comparable<Unsigned
     @Override
     public int compareTo(UnsignedInteger o)
     {
-        return Long.signum(longValue() - o.longValue());
+        return Integer.compareUnsigned(_underlying, o._underlying);
     }
 
     @Override
@@ -102,12 +103,16 @@ public final class UnsignedInteger extends Number implements Comparable<Unsigned
     @Override
     public String toString()
     {
-        return String.valueOf(longValue());
+        return Integer.toUnsignedString(_underlying);
     }
 
     public static UnsignedInteger valueOf(int underlying)
     {
-        if((underlying & 0xFFFFFF00) == 0)
+        if (underlying == -1)
+        {
+            return MAX_VALUE;
+        }
+        else if (0 == (underlying & 0xFFFFFF00))
         {
             return cachedValues[underlying];
         }
@@ -131,8 +136,8 @@ public final class UnsignedInteger extends Number implements Comparable<Unsigned
 
     public static UnsignedInteger valueOf(final String value)
     {
-        long longVal = Long.parseLong(value);
-        return valueOf(longVal);
+        final int parsed = Integer.parseUnsignedInt(value);
+        return valueOf(parsed);
     }
 
     public static UnsignedInteger valueOf(final long longVal)
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedLong.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedLong.java
index 975c0a1413..ed01f7f898 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedLong.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedLong.java
@@ -28,7 +28,6 @@ public final class UnsignedLong extends Number implements Comparable<UnsignedLon
     private static final long serialVersionUID = 1L;
 
     private static final BigInteger TWO_TO_THE_SIXTY_FOUR = new BigInteger( new byte[] { (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 });
-    private static final BigInteger LONG_MAX_VALUE = BigInteger.valueOf(Long.MAX_VALUE);
 
     private static final UnsignedLong[] cachedValues = new UnsignedLong[256];
 
@@ -45,8 +44,8 @@ public final class UnsignedLong extends Number implements Comparable<UnsignedLon
 
     private final long _underlying;
 
-
-
+    /** Deprecated, use {@link UnsignedLong#valueOf(long)}, planned for removal in version 12.0.0 */
+    @Deprecated(forRemoval = true)
     public UnsignedLong(long underlying)
     {
         _underlying = underlying;
@@ -108,7 +107,7 @@ public final class UnsignedLong extends Number implements Comparable<UnsignedLon
     @Override
     public int compareTo(UnsignedLong o)
     {
-        return bigIntegerValue().compareTo(o.bigIntegerValue());
+        return Long.compareUnsigned(_underlying, o._underlying);
     }
 
     @Override
@@ -120,7 +119,7 @@ public final class UnsignedLong extends Number implements Comparable<UnsignedLon
     @Override
     public String toString()
     {
-        return String.valueOf(bigIntegerValue());
+        return Long.toUnsignedString(_underlying);
     }
 
     public static UnsignedLong valueOf(long underlying)
@@ -137,20 +136,8 @@ public final class UnsignedLong extends Number implements Comparable<UnsignedLon
 
     public static UnsignedLong valueOf(final String value)
     {
-        BigInteger bigInt = new BigInteger(value);
-        if(bigInt.signum() == -1 || bigInt.bitCount()>64)
-        {
-            throw new NumberFormatException("Value \""+value+"\" lies outside the range [" + 0L + "- 2^64).");
-        }
-        else if(bigInt.compareTo(LONG_MAX_VALUE)>=0)
-        {
-            return UnsignedLong.valueOf(bigInt.longValue());
-        }
-        else
-        {
-            return UnsignedLong.valueOf(TWO_TO_THE_SIXTY_FOUR.subtract(bigInt).negate().longValue());
-        }
-
+        final long parsed = Long.parseUnsignedLong(value);
+        return valueOf(parsed);
     }
 
     public UnsignedLong add(UnsignedLong unsignedLong)
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedShort.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedShort.java
index 074ff53a40..da4d014ac2 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedShort.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedShort.java
@@ -93,7 +93,7 @@ public final class UnsignedShort extends Number implements Comparable<UnsignedSh
     @Override
     public int compareTo(UnsignedShort o)
     {
-        return Integer.signum(intValue() - o.intValue());
+        return Short.compareUnsigned(_underlying, o._underlying);
     }
 
     @Override
@@ -105,7 +105,7 @@ public final class UnsignedShort extends Number implements Comparable<UnsignedSh
     @Override
     public String toString()
     {
-        return String.valueOf(longValue());
+        return Integer.toString(intValue());
     }
 
     public static UnsignedShort valueOf(short underlying)
diff --git a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/TerminusDurability.java b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/TerminusDurability.java
index 38466ed5cf..dcc63e396c 100644
--- a/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/TerminusDurability.java
+++ b/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/type/messaging/TerminusDurability.java
@@ -101,6 +101,6 @@ public class TerminusDurability implements RestrictedType<UnsignedInteger>
     {
         int durabilitAValue = durabilityA != null ? durabilityA._val.intValue() : 0;
         int durabilityBValue = durabilityB != null ? durabilityB._val.intValue() : 0;
-        return TerminusDurability.valueOf(new UnsignedInteger(Math.min(durabilitAValue, durabilityBValue)));
+        return TerminusDurability.valueOf(UnsignedInteger.valueOf(Math.min(durabilitAValue, durabilityBValue)));
     }
 }
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java
index e054295d10..e520d4f735 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/Session_1_0Test.java
@@ -1598,7 +1598,7 @@ class Session_1_0Test extends UnitTestBase
         final Attach attach = new Attach();
         final Target target = new Target();
         attach.setTarget(target);
-        attach.setHandle(new UnsignedInteger(_handle++));
+        attach.setHandle(UnsignedInteger.valueOf(_handle++));
         attach.setIncompleteUnsettled(false);
         attach.setName(linkName);
         attach.setRole(Role.RECEIVER);
@@ -1658,7 +1658,7 @@ class Session_1_0Test extends UnitTestBase
                                           final long incomingWindow)
     {
         final Begin begin = mock(Begin.class);
-        when(begin.getNextOutgoingId()).thenReturn(new UnsignedInteger(channelId));
+        when(begin.getNextOutgoingId()).thenReturn(UnsignedInteger.valueOf(channelId));
         return new Session_1_0(connection, begin, channelId, channelId, incomingWindow);
     }
 
@@ -1694,7 +1694,7 @@ class Session_1_0Test extends UnitTestBase
                                           final java.util.concurrent.Executor executor)
     {
         final Begin begin = mock(Begin.class);
-        when(begin.getNextOutgoingId()).thenReturn(new UnsignedInteger(channelId));
+        when(begin.getNextOutgoingId()).thenReturn(UnsignedInteger.valueOf(channelId));
         return new Session_1_0(connection, begin, channelId, channelId, incomingWindow, echoFlowCoalesceIntervalMs,
                 clock, scheduler, executor);
     }
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/StandardReceivingLinkEndpointTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/StandardReceivingLinkEndpointTest.java
index 6060f3bb7a..0e2899b61a 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/StandardReceivingLinkEndpointTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/StandardReceivingLinkEndpointTest.java
@@ -171,7 +171,7 @@ public class StandardReceivingLinkEndpointTest extends UnitTestBase
                 .getContextValue(Integer.class, AMQPConnection_1_0.ECHO_FLOW_COALESCE_INTERVAL_MS);
 
         final Begin begin = mock(Begin.class);
-        doReturn(new UnsignedInteger(0)).when(begin).getNextOutgoingId();
+        doReturn(UnsignedInteger.valueOf(0)).when(begin).getNextOutgoingId();
         final Session_1_0 session = spy(new Session_1_0(connection, begin, 0, 0, 1000L));
 
         final Link_1_0<Source, Target> link = mock(Link_1_0.class);
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/UnsignedIntegerWriterTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/UnsignedIntegerWriterTest.java
new file mode 100644
index 0000000000..2988e21112
--- /dev/null
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/codec/UnsignedIntegerWriterTest.java
@@ -0,0 +1,47 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.server.protocol.v1_0.codec;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger;
+import org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry;
+
+class UnsignedIntegerWriterTest
+{
+    private static final AMQPDescribedTypeRegistry TYPE_REGISTRY = AMQPDescribedTypeRegistry.newInstance();
+
+    @Test
+    void encodingChangesAtSmallUnsignedIntegerBoundary()
+    {
+        assertEquals(2, getEncodedSize(255));
+        assertEquals(5, getEncodedSize(256));
+    }
+
+    private static int getEncodedSize(final int value)
+    {
+        final ValueWriter<UnsignedInteger> writer = TYPE_REGISTRY.getValueWriter(UnsignedInteger.valueOf(value));
+        return writer.getEncodedSize();
+    }
+}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java
index ceb22124d7..e05a1c6684 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/store/LinkStoreTestCase.java
@@ -74,9 +74,9 @@ public abstract class LinkStoreTestCase extends UnitTestBase
         _source.setFilter(Map.of(Symbol.valueOf("foo"), NoLocalFilter.INSTANCE));
         _source.setOutcomes(new Accepted().getSymbol());
         _source.setDynamicNodeProperties(Map.of(Symbol.valueOf("dynamicProperty"), "dynamicPropertyValue"));
-        _source.setTimeout(new UnsignedInteger(1));
+        _source.setTimeout(UnsignedInteger.valueOf(1));
 
-        _target.setTimeout(new UnsignedInteger(2));
+        _target.setTimeout(UnsignedInteger.valueOf(2));
         _target.setDynamicNodeProperties(Map.of(Symbol.valueOf("targetDynamicProperty"), "targetDynamicPropertyValue"));
         _target.setDynamic(Boolean.TRUE);
         _target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedNumberTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedNumberTest.java
new file mode 100644
index 0000000000..eefe197749
--- /dev/null
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/UnsignedNumberTest.java
@@ -0,0 +1,120 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.server.protocol.v1_0.type;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.qpid.test.utils.UnitTestBase;
+
+class UnsignedNumberTest extends UnitTestBase
+{
+    private static final String TWO_TO_THE_THIRTY_ONE_MINUS_ONE = "2147483647";
+    private static final String TWO_TO_THE_THIRTY_ONE = "2147483648";
+    private static final String TWO_TO_THE_THIRTY_TWO_MINUS_ONE = "4294967295";
+    private static final String TWO_TO_THE_THIRTY_TWO = "4294967296";
+    private static final String TWO_TO_THE_SIXTY_THREE_MINUS_ONE = "9223372036854775807";
+    private static final String TWO_TO_THE_SIXTY_THREE = "9223372036854775808";
+    private static final String TWO_TO_THE_SIXTY_FOUR_MINUS_ONE = "18446744073709551615";
+    private static final String TWO_TO_THE_SIXTY_FOUR = "18446744073709551616";
+
+    @Test
+    void unsignedIntegerParsingAcceptsBoundaryValues()
+    {
+        assertUnsignedIntegerRoundTrip("0", 0);
+        assertUnsignedIntegerRoundTrip(TWO_TO_THE_THIRTY_ONE_MINUS_ONE, Integer.MAX_VALUE);
+        assertUnsignedIntegerRoundTrip(TWO_TO_THE_THIRTY_ONE, Integer.MIN_VALUE);
+        assertUnsignedIntegerRoundTrip(TWO_TO_THE_THIRTY_TWO_MINUS_ONE, -1);
+    }
+
+    @Test
+    void unsignedIntegerParsingRejectsOutOfRangeValues()
+    {
+        assertThrows(NumberFormatException.class, () -> UnsignedInteger.valueOf(TWO_TO_THE_THIRTY_TWO));
+        assertThrows(NumberFormatException.class, () -> UnsignedInteger.valueOf("-1"));
+    }
+
+    @Test
+    void unsignedLongParsingAcceptsBoundaryValues()
+    {
+        assertUnsignedLongRoundTrip("0", 0L);
+        assertUnsignedLongRoundTrip(TWO_TO_THE_SIXTY_THREE_MINUS_ONE, Long.MAX_VALUE);
+        assertUnsignedLongRoundTrip(TWO_TO_THE_SIXTY_THREE, Long.MIN_VALUE);
+        assertUnsignedLongRoundTrip(TWO_TO_THE_SIXTY_FOUR_MINUS_ONE, -1L);
+    }
+
+    @Test
+    void unsignedLongParsingRejectsOutOfRangeValues()
+    {
+        assertThrows(NumberFormatException.class, () -> UnsignedLong.valueOf(TWO_TO_THE_SIXTY_FOUR));
+        assertThrows(NumberFormatException.class, () -> UnsignedLong.valueOf("-1"));
+    }
+
+    @Test
+    void unsignedByteComparisonCrossesSignedBoundary()
+    {
+        assertUnsignedOrder(UnsignedByte.valueOf(Byte.MAX_VALUE), UnsignedByte.valueOf(Byte.MIN_VALUE));
+    }
+
+    @Test
+    void unsignedShortComparisonCrossesSignedBoundary()
+    {
+        assertUnsignedOrder(UnsignedShort.valueOf(Short.MAX_VALUE), UnsignedShort.valueOf(Short.MIN_VALUE));
+    }
+
+    @Test
+    void unsignedIntegerComparisonCrossesSignedBoundary()
+    {
+        assertUnsignedOrder(UnsignedInteger.valueOf(Integer.MAX_VALUE), UnsignedInteger.valueOf(Integer.MIN_VALUE));
+    }
+
+    @Test
+    void unsignedLongComparisonCrossesSignedBoundary()
+    {
+        assertUnsignedOrder(UnsignedLong.valueOf(Long.MAX_VALUE), UnsignedLong.valueOf(Long.MIN_VALUE));
+    }
+
+    private static void assertUnsignedIntegerRoundTrip(final String encoded, final int underlying)
+    {
+        final UnsignedInteger value = UnsignedInteger.valueOf(encoded);
+
+        assertEquals(underlying, value.intValue());
+        assertEquals(encoded, value.toString());
+    }
+
+    private static void assertUnsignedLongRoundTrip(final String encoded, final long underlying)
+    {
+        final UnsignedLong value = UnsignedLong.valueOf(encoded);
+
+        assertEquals(underlying, value.longValue());
+        assertEquals(encoded, value.toString());
+    }
+
+    private static <T extends Comparable<T>> void assertUnsignedOrder(final T lower, final T higher)
+    {
+        assertTrue(lower.compareTo(higher) < 0);
+        assertTrue(higher.compareTo(lower) > 0);
+    }
+}
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java
index d54110bf30..1b35c0e13f 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionDetectionPolicyTest.java
@@ -32,20 +32,20 @@ class SoleConnectionDetectionPolicyTest extends UnitTestBase
     @Test
     void value()
     {
-        assertEquals(new UnsignedInteger(0), SoleConnectionDetectionPolicy.STRONG.getValue());
-        assertEquals(new UnsignedInteger(1), SoleConnectionDetectionPolicy.WEAK.getValue());
+        assertEquals(UnsignedInteger.valueOf(0), SoleConnectionDetectionPolicy.STRONG.getValue());
+        assertEquals(UnsignedInteger.valueOf(1), SoleConnectionDetectionPolicy.WEAK.getValue());
     }
 
     @Test
     void valueOf()
     {
         assertEquals(SoleConnectionDetectionPolicy.STRONG,
-                SoleConnectionDetectionPolicy.valueOf(new UnsignedInteger(0)));
+                SoleConnectionDetectionPolicy.valueOf(UnsignedInteger.valueOf(0)));
         assertEquals(SoleConnectionDetectionPolicy.WEAK,
-                SoleConnectionDetectionPolicy.valueOf(new UnsignedInteger(1)));
+                SoleConnectionDetectionPolicy.valueOf(UnsignedInteger.valueOf(1)));
 
         final RuntimeException thrown = assertThrows(RuntimeException.class,
-                () -> SoleConnectionDetectionPolicy.valueOf(new UnsignedInteger(2)),
+                () -> SoleConnectionDetectionPolicy.valueOf(UnsignedInteger.valueOf(2)),
                 "An exception is expected");
         assertNotNull(thrown.getMessage());
     }
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java
index 61371ccf9f..e6df579047 100644
--- a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/type/extensions/soleconn/SoleConnectionEnforcementPolicyTest.java
@@ -32,20 +32,20 @@ class SoleConnectionEnforcementPolicyTest extends UnitTestBase
     @Test
     void value()
     {
-        assertEquals(new UnsignedInteger(0), SoleConnectionEnforcementPolicy.REFUSE_CONNECTION.getValue());
-        assertEquals(new UnsignedInteger(1), SoleConnectionEnforcementPolicy.CLOSE_EXISTING.getValue());
+        assertEquals(UnsignedInteger.valueOf(0), SoleConnectionEnforcementPolicy.REFUSE_CONNECTION.getValue());
+        assertEquals(UnsignedInteger.valueOf(1), SoleConnectionEnforcementPolicy.CLOSE_EXISTING.getValue());
     }
 
     @Test
     void valueOf()
     {
         assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION,
-                SoleConnectionEnforcementPolicy.valueOf(new UnsignedInteger(0)));
+                SoleConnectionEnforcementPolicy.valueOf(UnsignedInteger.valueOf(0)));
         assertEquals(SoleConnectionEnforcementPolicy.CLOSE_EXISTING,
-                SoleConnectionEnforcementPolicy.valueOf(new UnsignedInteger(1)));
+                SoleConnectionEnforcementPolicy.valueOf(UnsignedInteger.valueOf(1)));
 
         final RuntimeException thrown = assertThrows(RuntimeException.class,
-                () -> SoleConnectionEnforcementPolicy.valueOf(new UnsignedInteger(2)),
+                () -> SoleConnectionEnforcementPolicy.valueOf(UnsignedInteger.valueOf(2)),
                 "An exception is expected");
         assertNotNull(thrown.getMessage());
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org