From 7cc01bd05bbed32636ce81c1ee1a9bc82738c90b Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Wed, 15 Nov 2023 23:23:46 +0100 Subject: [PATCH] Fix warnings in tests --- .../client2/internal/collections/ImmutableListTest.java | 7 +++---- .../mqtt/codec/decoder/mqtt5/Mqtt5ConnAckDecoderTest.java | 2 +- .../codec/decoder/mqtt5/Mqtt5DisconnectDecoderTest.java | 2 +- .../mqtt/codec/decoder/mqtt5/Mqtt5PubAckDecoderTest.java | 2 +- .../mqtt/codec/decoder/mqtt5/Mqtt5PubCompDecoderTest.java | 2 +- .../mqtt/codec/decoder/mqtt5/Mqtt5PubRecDecoderTest.java | 6 +++--- .../mqtt/codec/decoder/mqtt5/Mqtt5PubRelDecoderTest.java | 6 +++--- .../mqtt/codec/decoder/mqtt5/Mqtt5SubAckDecoderTest.java | 6 +++--- .../mqtt/codec/encoder/mqtt5/Mqtt5AuthEncoderTest.java | 4 ++-- .../mqtt/codec/encoder/mqtt5/Mqtt5ConnectEncoderTest.java | 4 ++-- .../codec/encoder/mqtt5/Mqtt5DisconnectEncoderTest.java | 2 +- .../mqtt/codec/encoder/mqtt5/Mqtt5PubAckEncoderTest.java | 2 +- .../codec/encoder/mqtt5/Mqtt5SubscribeEncoderTest.java | 4 ++-- .../codec/encoder/mqtt5/Mqtt5UnsubscribeEncoderTest.java | 6 +++--- .../mqtt/datatypes/MqttUserPropertiesImplBuilderTest.java | 7 ++++--- .../mqtt/message/subscribe/MqttSubscribeBuilderTest.java | 5 +++-- .../subscribe/mqtt3/Mqtt3SubscribeViewBuilderTest.java | 5 +++-- 17 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/test/java/com/hivemq/client2/internal/collections/ImmutableListTest.java b/src/test/java/com/hivemq/client2/internal/collections/ImmutableListTest.java index 6681cbb06..30d0f03cc 100644 --- a/src/test/java/com/hivemq/client2/internal/collections/ImmutableListTest.java +++ b/src/test/java/com/hivemq/client2/internal/collections/ImmutableListTest.java @@ -290,7 +290,6 @@ void modifyMethods_throwUOE() { @ParameterizedTest @MethodSource("numberedList") - @SuppressWarnings("ResultOfMethodCallIgnored") void get(final @NotNull ImmutableList list) { assertThrows(IndexOutOfBoundsException.class, () -> list.get(-1)); for (int i = 0; i < list.size(); i++) { @@ -388,10 +387,10 @@ void contains(final @NotNull ImmutableList list) { @SuppressWarnings("CollectionAddedToSelf") void containsAll(final @NotNull ImmutableList list) { assertTrue(list.containsAll(list)); - assertTrue(list.containsAll(ImmutableList.of())); - assertTrue(list.containsAll(ImmutableList.builder().addAll(list).build())); + assertTrue(list.containsAll(ImmutableList.of())); + assertTrue(list.containsAll(ImmutableList.builder().addAll(list).build())); assertFalse(list.containsAll(ImmutableList.of("x"))); - assertFalse(list.containsAll(ImmutableList.builder().addAll(list).add("x").build())); + assertFalse(list.containsAll(ImmutableList.builder().addAll(list).add("x").build())); } @ParameterizedTest diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5ConnAckDecoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5ConnAckDecoderTest.java index 6ac398695..9d5a58992 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5ConnAckDecoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5ConnAckDecoderTest.java @@ -1874,7 +1874,7 @@ private void testDisconnect(final @NotNull Mqtt5DisconnectReasonCode reasonCode) } private static final byte PROPERTIES_VALID_LENGTH = 119; - private static final @NotNull byte[] PROPERTIES_VALID = { + private static final byte @NotNull [] PROPERTIES_VALID = { // session expiry interval 0x11, 0, 0, 0, 10, // receive maximum diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5DisconnectDecoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5DisconnectDecoderTest.java index a1d2ab211..a3f7bb607 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5DisconnectDecoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5DisconnectDecoderTest.java @@ -785,7 +785,7 @@ private void testDisconnect(final @NotNull Mqtt5DisconnectReasonCode reasonCode) } private final int PROPERTIES_VALID_LENGTH = 71; - private final @NotNull byte[] PROPERTIES_VALID = { + private final byte @NotNull [] PROPERTIES_VALID = { // session expiry interval 0x11, 0, 0, 0, 10, // reason string diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubAckDecoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubAckDecoderTest.java index 0ee60f842..4a00f81a7 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubAckDecoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubAckDecoderTest.java @@ -745,7 +745,7 @@ private void testDisconnect(final @NotNull Mqtt5DisconnectReasonCode reasonCode) } private static final int PROPERTIES_VALID_LENGTH = 54; - private static final @NotNull byte[] PROPERTIES_VALID = { + private static final byte @NotNull [] PROPERTIES_VALID = { // reason string 0x1F, 0, 7, 's', 'u', 'c', 'c', 'e', 's', 's', // user properties diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubCompDecoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubCompDecoderTest.java index be2703d63..1861dab17 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubCompDecoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubCompDecoderTest.java @@ -745,7 +745,7 @@ private void testDisconnect(final @NotNull Mqtt5DisconnectReasonCode reasonCode) } private static final int PROPERTIES_VALID_LENGTH = 54; - private static final @NotNull byte[] PROPERTIES_VALID = { + private static final byte @NotNull [] PROPERTIES_VALID = { // reason string 0x1F, 0, 7, 's', 'u', 'c', 'c', 'e', 's', 's', // user properties diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRecDecoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRecDecoderTest.java index c613b6412..17543e80f 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRecDecoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRecDecoderTest.java @@ -401,13 +401,13 @@ void decode_nullUserProperty_returnsNull() { decodeNok(encoded, Mqtt5DisconnectReasonCode.MALFORMED_PACKET); } - private @NotNull MqttPubRec decodeOk(final @NotNull byte[] encoded) { + private @NotNull MqttPubRec decodeOk(final byte @NotNull [] encoded) { final MqttPubRec pubRec = decode(encoded); assertNotNull(pubRec); return pubRec; } - private void decodeNok(final @NotNull byte[] encoded, final @NotNull Mqtt5DisconnectReasonCode reasonCode) { + private void decodeNok(final byte @NotNull [] encoded, final @NotNull Mqtt5DisconnectReasonCode reasonCode) { final MqttPubRec pubRec = decode(encoded); assertNull(pubRec); @@ -418,7 +418,7 @@ private void decodeNok(final @NotNull byte[] encoded, final @NotNull Mqtt5Discon createChannel(); } - private @Nullable MqttPubRec decode(final @NotNull byte[] encoded) { + private @Nullable MqttPubRec decode(final byte @NotNull [] encoded) { final ByteBuf byteBuf = channel.alloc().buffer(); byteBuf.writeBytes(encoded); channel.writeInbound(byteBuf); diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRelDecoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRelDecoderTest.java index 7a3a9a495..2bd7d71c0 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRelDecoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRelDecoderTest.java @@ -341,13 +341,13 @@ void decode_nullReasonString_returnsNull() { decodeNok(encoded, MALFORMED_PACKET); } - private @NotNull MqttPubRel decodeOk(final @NotNull byte[] encoded) { + private @NotNull MqttPubRel decodeOk(final byte @NotNull [] encoded) { final MqttPubRel pubRel = decode(encoded); assertNotNull(pubRel); return pubRel; } - private void decodeNok(final @NotNull byte[] encoded, final @NotNull Mqtt5DisconnectReasonCode reasonCode) { + private void decodeNok(final byte @NotNull [] encoded, final @NotNull Mqtt5DisconnectReasonCode reasonCode) { final MqttPubRel pubRel = decode(encoded); assertNull(pubRel); @@ -358,7 +358,7 @@ private void decodeNok(final @NotNull byte[] encoded, final @NotNull Mqtt5Discon createChannel(); } - private @Nullable MqttPubRel decode(final @NotNull byte[] encoded) { + private @Nullable MqttPubRel decode(final byte @NotNull [] encoded) { final ByteBuf byteBuf = channel.alloc().buffer(); byteBuf.writeBytes(encoded); channel.writeInbound(byteBuf); diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5SubAckDecoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5SubAckDecoderTest.java index ca77c6cda..c51411233 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5SubAckDecoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/decoder/mqtt5/Mqtt5SubAckDecoderTest.java @@ -448,13 +448,13 @@ void encode_propertyIdentifierLessThanZero_returnsNull() { } @NotNull - private MqttSubAck decodeOk(final @NotNull byte[] encoded) { + private MqttSubAck decodeOk(final byte @NotNull [] encoded) { final MqttSubAck subAck = decode(encoded); assertNotNull(subAck); return subAck; } - private void decodeNok(final @NotNull byte[] encoded, final @NotNull Mqtt5DisconnectReasonCode reasonCode) { + private void decodeNok(final byte @NotNull [] encoded, final @NotNull Mqtt5DisconnectReasonCode reasonCode) { final MqttSubAck subAck = decode(encoded); assertNull(subAck); @@ -466,7 +466,7 @@ private void decodeNok(final @NotNull byte[] encoded, final @NotNull Mqtt5Discon } @Nullable - private MqttSubAck decode(final @NotNull byte[] encoded) { + private MqttSubAck decode(final byte @NotNull [] encoded) { final ByteBuf byteBuf = channel.alloc().buffer(); byteBuf.writeBytes(encoded); channel.writeInbound(byteBuf); diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5AuthEncoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5AuthEncoderTest.java index 923b08439..a61b30eb2 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5AuthEncoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5AuthEncoderTest.java @@ -235,7 +235,7 @@ void encode_maximumPacketSizeExceededByUserProperties_omitUserPropertiesAndReaso encode(maxPacket.getWithOmittedUserPropertiesAndReasonString(), auth); } - private void encode(final @NotNull byte[] expected, final @NotNull MqttAuth auth) { + private void encode(final byte @NotNull [] expected, final @NotNull MqttAuth auth) { encode(auth, expected); } @@ -249,7 +249,7 @@ private void encodeNok( } @SuppressWarnings("NullabilityAnnotations") - private class MaximumPacketBuilder { + private static class MaximumPacketBuilder { private ImmutableList.Builder userPropertiesBuilder; final MqttUserPropertyImpl userProperty = diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5ConnectEncoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5ConnectEncoderTest.java index 61d14b34f..a9848e04a 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5ConnectEncoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5ConnectEncoderTest.java @@ -514,7 +514,7 @@ void encode_propertyLengthExceedsMax_throwsEncoderException() { encodeNok(connectWrapper, EncoderException.class, "variable byte integer size exceeded for property length"); } - private void encode(final @NotNull byte[] expected, final @NotNull MqttStatefulConnect connectWrapper) { + private void encode(final byte @NotNull [] expected, final @NotNull MqttStatefulConnect connectWrapper) { encode(connectWrapper, expected); } @@ -528,7 +528,7 @@ private void encodeNok( } @SuppressWarnings("NullabilityAnnotations") - private class MaximumPacketBuilder { + private static class MaximumPacketBuilder { private ImmutableList.Builder userPropertiesBuilder; final @NotNull MqttUserPropertyImpl userProperty = diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5DisconnectEncoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5DisconnectEncoderTest.java index 540d4dd10..84bf5d7db 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5DisconnectEncoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5DisconnectEncoderTest.java @@ -363,7 +363,7 @@ void encode_propertyLengthExceeded_omitReasonString() { expected.release(); } - private void encode(final @NotNull byte[] expected, final @NotNull MqttDisconnect disconnect) { + private void encode(final byte @NotNull [] expected, final @NotNull MqttDisconnect disconnect) { encode(disconnect, expected); } diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5PubAckEncoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5PubAckEncoderTest.java index 68a2352e3..fcd30ab19 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5PubAckEncoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5PubAckEncoderTest.java @@ -452,7 +452,7 @@ void encode_reasonCodes(final @NotNull Mqtt5PubAckReasonCode reasonCode) { encode(expected, pubAck); } - private void encode(final @NotNull byte[] expected, final @NotNull MqttPubAck pubAck) { + private void encode(final byte @NotNull [] expected, final @NotNull MqttPubAck pubAck) { encode(pubAck, expected); } diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5SubscribeEncoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5SubscribeEncoderTest.java index c5f3ed191..72476ce63 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5SubscribeEncoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5SubscribeEncoderTest.java @@ -371,14 +371,14 @@ void encode_maximumPacketSizeExceeded_throws() { "SUBSCRIBE exceeded maximum packet size, minimal possible encoded length: 268435461, maximum: 268435460")); } - private void encode(final @NotNull byte[] expected, final MqttSubscribe subscribe, final int packetIdentifier) { + private void encode(final byte @NotNull [] expected, final MqttSubscribe subscribe, final int packetIdentifier) { final MqttStatefulSubscribe subscribeInternal = subscribe.createStateful(packetIdentifier, MqttStatefulSubscribe.DEFAULT_NO_SUBSCRIPTION_IDENTIFIER); encodeInternal(expected, subscribeInternal); } private void encodeInternal( - final @NotNull byte[] expected, final @NotNull MqttStatefulSubscribe subscribeInternal) { + final byte @NotNull [] expected, final @NotNull MqttStatefulSubscribe subscribeInternal) { encode(subscribeInternal, expected); } diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5UnsubscribeEncoderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5UnsubscribeEncoderTest.java index fd1f92021..d09bd2ff6 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5UnsubscribeEncoderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/codec/encoder/mqtt5/Mqtt5UnsubscribeEncoderTest.java @@ -167,7 +167,7 @@ void encode_propertyLengthExceeded_omitUserProperties() { } private void encodeUnsubscribe( - final @NotNull byte[] expected, + final byte @NotNull [] expected, final @NotNull MqttUserPropertiesImpl userProperties, final @NotNull ImmutableList topicFilters) { final MqttUnsubscribe unsubscribe = new MqttUnsubscribe(topicFilters, userProperties); @@ -178,12 +178,12 @@ private void encodeUnsubscribe( } private void encodeInternal( - final @NotNull byte[] expected, final @NotNull MqttStatefulUnsubscribe unsubscribeInternal) { + final byte @NotNull [] expected, final @NotNull MqttStatefulUnsubscribe unsubscribeInternal) { encode(unsubscribeInternal, expected); } @SuppressWarnings("NullabilityAnnotations") - private class MaximumPacketBuilder { + private static class MaximumPacketBuilder { private static final String TOPIC = "topic"; private StringBuilder reasonStringBuilder; diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/datatypes/MqttUserPropertiesImplBuilderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/datatypes/MqttUserPropertiesImplBuilderTest.java index 26f3f8a9b..9b5f1054c 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/datatypes/MqttUserPropertiesImplBuilderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/datatypes/MqttUserPropertiesImplBuilderTest.java @@ -69,7 +69,7 @@ void addAll_empty_stream_allowed() { @Test void addAll_empty_array_allowed() { - final Mqtt5UserProperties properties = Mqtt5UserProperties.builder().addAll(new Mqtt5UserProperty[0]).build(); + final Mqtt5UserProperties properties = Mqtt5UserProperties.builder().addAll().build(); assertTrue(properties.asList().isEmpty()); } @@ -191,7 +191,8 @@ void addAll_correct_use_and_correct_order_immutable_list() { } void compareProperties( - final @NotNull Mqtt5UserProperty[] expected, final @NotNull List actual) { + final @NotNull Mqtt5UserProperty @NotNull [] expected, + final @NotNull List actual) { assertEquals(expected.length, actual.size()); @@ -204,7 +205,7 @@ void compareProperties( } void compareProperties( - final @NotNull Collection expected, + final @NotNull Collection<@NotNull Mqtt5UserProperty> expected, final @NotNull List actual) { compareProperties(expected.toArray(new Mqtt5UserProperty[0]), actual); } diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/MqttSubscribeBuilderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/MqttSubscribeBuilderTest.java index f18c60974..94a890d8a 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/MqttSubscribeBuilderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/MqttSubscribeBuilderTest.java @@ -389,7 +389,8 @@ void addSubscriptions_fluent_subscription_and_addSubscription() { } void compareSubscriptions( - final @NotNull Mqtt5Subscription[] expected, final @NotNull List actual) { + final @NotNull Mqtt5Subscription @NotNull [] expected, + final @NotNull List actual) { assertEquals(expected.length, actual.size()); @@ -399,7 +400,7 @@ void compareSubscriptions( } void compareSubscriptions( - final @NotNull Collection expected, + final @NotNull Collection<@NotNull Mqtt5Subscription> expected, final @NotNull List actual) { assertEquals(expected.size(), actual.size()); diff --git a/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilderTest.java b/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilderTest.java index 4d5d3dd70..4bb79a094 100644 --- a/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilderTest.java +++ b/src/test/java/com/hivemq/client2/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilderTest.java @@ -373,7 +373,8 @@ void addSubscriptions_fluent_subscription_and_addSubscription() { } void compareSubscriptions( - final @NotNull Mqtt3Subscription[] expected, final @NotNull List actual) { + final @NotNull Mqtt3Subscription @NotNull [] expected, + final @NotNull List actual) { assertEquals(expected.length, actual.size()); @@ -383,7 +384,7 @@ void compareSubscriptions( } void compareSubscriptions( - final @NotNull Collection expected, + final @NotNull Collection<@NotNull Mqtt3Subscription> expected, final @NotNull List actual) { assertEquals(expected.size(), actual.size());