Skip to content

Commit c176564

Browse files
committed
Removed junit 4, migrated old tests
1 parent fb01db1 commit c176564

21 files changed

+148
-173
lines changed

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,12 @@ dependencies {
9595

9696
allprojects {
9797
dependencies {
98-
def junit4Version = '4.12'
9998
def junit5Version = '5.5.1'
10099
def junitPlatformVersion = '1.5.1'
101100

102-
testImplementation group: 'junit', name: 'junit', version: junit4Version
103101
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit5Version
104102
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junit5Version
105103
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit5Version
106-
testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junit5Version
107104
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher', version: junitPlatformVersion
108105
}
109106

src/test/java/com/hivemq/client/internal/mqtt/codec/decoder/mqtt5/Mqtt5PubRecDecoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
import static com.hivemq.client.mqtt.mqtt5.message.disconnect.Mqtt5DisconnectReasonCode.MALFORMED_PACKET;
3636
import static com.hivemq.client.mqtt.mqtt5.message.publish.pubrec.Mqtt5PubRecReasonCode.SUCCESS;
37-
import static org.junit.Assert.*;
37+
import static org.junit.jupiter.api.Assertions.*;
3838

3939
/**
4040
* @author Silvio Giebl

src/test/java/com/hivemq/client/internal/mqtt/codec/encoder/mqtt5/Mqtt5PingReqEncoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import io.netty.buffer.ByteBuf;
2424
import org.junit.jupiter.api.Test;
2525

26-
import static org.junit.Assert.assertArrayEquals;
26+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2727

2828
/**
2929
* @author David Katz

src/test/java/com/hivemq/client/internal/mqtt/codec/encoder/mqtt5/Mqtt5PubCompEncoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import static com.hivemq.client.internal.mqtt.datatypes.MqttVariableByteInteger.MAXIMUM_PACKET_SIZE_LIMIT;
3636
import static com.hivemq.client.mqtt.mqtt5.message.publish.pubcomp.Mqtt5PubCompReasonCode.PACKET_IDENTIFIER_NOT_FOUND;
3737
import static com.hivemq.client.mqtt.mqtt5.message.publish.pubcomp.Mqtt5PubCompReasonCode.SUCCESS;
38-
import static org.junit.Assert.assertTrue;
3938
import static org.junit.jupiter.api.Assertions.assertThrows;
39+
import static org.junit.jupiter.api.Assertions.assertTrue;
4040
import static org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE;
4141

4242
/**

src/test/java/com/hivemq/client/internal/mqtt/codec/encoder/mqtt5/Mqtt5PublishEncoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import static com.hivemq.client.internal.mqtt.datatypes.MqttUserPropertiesImpl.NO_USER_PROPERTIES;
3939
import static com.hivemq.client.internal.mqtt.message.publish.MqttStatefulPublish.DEFAULT_NO_SUBSCRIPTION_IDENTIFIERS;
4040
import static com.hivemq.client.internal.mqtt.message.publish.MqttStatefulPublish.DEFAULT_NO_TOPIC_ALIAS;
41-
import static org.junit.Assert.assertTrue;
4241
import static org.junit.jupiter.api.Assertions.assertThrows;
42+
import static org.junit.jupiter.api.Assertions.assertTrue;
4343

4444
/**
4545
* @author David Katz

src/test/java/com/hivemq/client/internal/mqtt/datatypes/MqttBinaryDataTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
import io.netty.buffer.ByteBuf;
2121
import io.netty.buffer.Unpooled;
2222
import org.jetbrains.annotations.NotNull;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
import java.util.Random;
2626

27-
import static org.junit.Assert.*;
27+
import static org.junit.jupiter.api.Assertions.*;
2828

2929
/**
3030
* @author Silvio Giebl
3131
*/
32-
public class MqttBinaryDataTest {
32+
class MqttBinaryDataTest {
3333

3434
private final @NotNull Random random = new Random();
3535

src/test/java/com/hivemq/client/internal/mqtt/datatypes/MqttClientIdentifierImplTest.java

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,26 @@
1717

1818
package com.hivemq.client.internal.mqtt.datatypes;
1919

20-
import com.google.common.collect.ImmutableSet;
2120
import io.netty.buffer.ByteBuf;
2221
import io.netty.buffer.Unpooled;
2322
import org.jetbrains.annotations.NotNull;
2423
import org.jetbrains.annotations.Nullable;
25-
import org.junit.Test;
26-
import org.junit.runner.RunWith;
27-
import org.junit.runners.Parameterized;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.ValueSource;
2826

29-
import java.nio.charset.Charset;
30-
import java.util.Collection;
27+
import java.nio.charset.StandardCharsets;
3128

32-
import static org.junit.Assert.*;
29+
import static org.junit.jupiter.api.Assertions.*;
3330

3431
/**
3532
* @author Silvio Giebl
3633
*/
37-
@RunWith(Parameterized.class)
38-
public class MqttClientIdentifierImplTest {
34+
class MqttClientIdentifierImplTest {
3935

40-
@Parameterized.Parameters
41-
public static @NotNull Collection<Boolean> parameters() {
42-
return ImmutableSet.of(false, true);
43-
}
44-
45-
private final boolean isFromByteBuf;
46-
47-
public MqttClientIdentifierImplTest(final boolean isFromByteBuf) {
48-
this.isFromByteBuf = isFromByteBuf;
49-
}
50-
51-
private @Nullable MqttClientIdentifierImpl from(final @NotNull String string) {
52-
if (isFromByteBuf) {
36+
private @Nullable MqttClientIdentifierImpl from(final @NotNull String string, final boolean fromByteBuf) {
37+
if (fromByteBuf) {
5338
final ByteBuf byteBuf = Unpooled.buffer();
54-
final byte[] binary = string.getBytes(Charset.forName("UTF-8"));
39+
final byte[] binary = string.getBytes(StandardCharsets.UTF_8);
5540
byteBuf.writeShort(binary.length);
5641
byteBuf.writeBytes(binary);
5742
final MqttClientIdentifierImpl mqtt5ClientIdentifier = MqttClientIdentifierImpl.decode(byteBuf);
@@ -62,42 +47,47 @@ public MqttClientIdentifierImplTest(final boolean isFromByteBuf) {
6247
}
6348
}
6449

65-
@Test
66-
public void test_must_be_allowed_by_server() {
50+
@ParameterizedTest
51+
@ValueSource(booleans = {false, true})
52+
public void test_must_be_allowed_by_server(final boolean fromByteBuf) {
6753
final String string = "abc123DEF";
68-
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string);
54+
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string, fromByteBuf);
6955
assertNotNull(mqtt5ClientIdentifier);
7056
assertTrue(mqtt5ClientIdentifier.mustBeAllowedByServer());
7157
}
7258

73-
@Test
74-
public void test_must_be_allowed_by_server_length_23() {
59+
@ParameterizedTest
60+
@ValueSource(booleans = {false, true})
61+
public void test_must_be_allowed_by_server_length_23(final boolean fromByteBuf) {
7562
final String string = "abcdefghijklmnopqrstuvw";
76-
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string);
63+
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string, fromByteBuf);
7764
assertNotNull(mqtt5ClientIdentifier);
7865
assertTrue(mqtt5ClientIdentifier.mustBeAllowedByServer());
7966
}
8067

81-
@Test
82-
public void test_must_not_be_allowed_by_server_length_24() {
68+
@ParameterizedTest
69+
@ValueSource(booleans = {false, true})
70+
public void test_must_not_be_allowed_by_server_length_24(final boolean fromByteBuf) {
8371
final String string = "abcdefghijklmnopqrstuvwx";
84-
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string);
72+
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string, fromByteBuf);
8573
assertNotNull(mqtt5ClientIdentifier);
8674
assertFalse(mqtt5ClientIdentifier.mustBeAllowedByServer());
8775
}
8876

89-
@Test
90-
public void test_must_not_be_allowed_by_server_zero_length() {
77+
@ParameterizedTest
78+
@ValueSource(booleans = {false, true})
79+
public void test_must_not_be_allowed_by_server_zero_length(final boolean fromByteBuf) {
9180
final String string = "";
92-
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string);
81+
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string, fromByteBuf);
9382
assertNotNull(mqtt5ClientIdentifier);
9483
assertFalse(mqtt5ClientIdentifier.mustBeAllowedByServer());
9584
}
9685

97-
@Test
98-
public void test_must_not_be_allowed_by_server_character() {
86+
@ParameterizedTest
87+
@ValueSource(booleans = {false, true})
88+
public void test_must_not_be_allowed_by_server_character(final boolean fromByteBuf) {
9989
final String string = "abc123-DEF";
100-
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string);
90+
final MqttClientIdentifierImpl mqtt5ClientIdentifier = from(string, fromByteBuf);
10191
assertNotNull(mqtt5ClientIdentifier);
10292
assertFalse(mqtt5ClientIdentifier.mustBeAllowedByServer());
10393
}

src/test/java/com/hivemq/client/internal/mqtt/datatypes/MqttSharedTopicFilterImplTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.hivemq.client.internal.util.collections.ImmutableList;
2121
import io.netty.buffer.ByteBuf;
2222
import io.netty.buffer.Unpooled;
23-
import org.hamcrest.CoreMatchers;
2423
import org.jetbrains.annotations.NotNull;
2524
import org.jetbrains.annotations.Nullable;
2625
import org.junit.jupiter.api.Assertions;
@@ -30,12 +29,12 @@
3029
import org.junit.jupiter.params.provider.EnumSource;
3130
import org.junit.jupiter.params.provider.MethodSource;
3231

33-
import java.nio.charset.Charset;
32+
import java.nio.charset.StandardCharsets;
3433
import java.util.Arrays;
3534
import java.util.LinkedList;
3635
import java.util.List;
3736

38-
import static org.junit.Assert.*;
37+
import static org.junit.jupiter.api.Assertions.*;
3938

4039
/**
4140
* @author Silvio Giebl
@@ -65,7 +64,7 @@ enum SharedTopicFilterSource {
6564
switch (source) {
6665
case BYTE_BUF:
6766
final ByteBuf byteBuf = Unpooled.buffer();
68-
final byte[] binary = sharedSubscriptionTopicFilter.getBytes(Charset.forName("UTF-8"));
67+
final byte[] binary = sharedSubscriptionTopicFilter.getBytes(StandardCharsets.UTF_8);
6968
byteBuf.writeShort(binary.length);
7069
byteBuf.writeBytes(binary);
7170
final MqttTopicFilterImpl mqtt5TopicFilter = MqttTopicFilterImpl.decode(byteBuf);
@@ -120,7 +119,7 @@ void from_invalidSharedSubscriptionString_throws(
120119

121120
final IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class,
122121
() -> from(SharedTopicFilterSource.STRING, sharedTopicFilter));
123-
assertTrue("IllegalArgumentException must give hint that " + message, exception.getMessage().contains(message));
122+
assertTrue(exception.getMessage().contains(message), "IllegalArgumentException must give hint that " + message);
124123
}
125124

126125
private static @NotNull List<Arguments> invalidShareNameOrTopicFilter(
@@ -187,7 +186,7 @@ void from_invalidShareNameOrTopicFilterString_throws(
187186

188187
final IllegalArgumentException exception =
189188
Assertions.assertThrows(IllegalArgumentException.class, () -> from(source, shareName, topicFilter));
190-
assertTrue("IllegalArgumentException must give hint that " + message, exception.getMessage().contains(message));
189+
assertTrue(exception.getMessage().contains(message), "IllegalArgumentException must give hint that " + message);
191190
}
192191

193192
@Test
@@ -197,8 +196,8 @@ void from_shareNameWithTopicLevelSeparator_throws() {
197196
final String errorMsg = "Share name [gro/up] must not contain topic level separator";
198197
final IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class,
199198
() -> from(SharedTopicFilterSource.SHARE_NAME_AND_TOPIC_FILTER, shareName, topicFilter));
200-
assertTrue("IllegalArgumentException must give hint that " + errorMsg,
201-
exception.getMessage().contains(errorMsg));
199+
assertTrue(exception.getMessage().contains(errorMsg),
200+
"IllegalArgumentException must give hint that " + errorMsg);
202201
}
203202

204203
@Test
@@ -266,7 +265,7 @@ void getLevels_onlyTopicLevelSeparator(final @NotNull SharedTopicFilterSource so
266265
assertTrue(mqtt5TopicFilter.isShared());
267266
assertTrue(mqtt5TopicFilter instanceof MqttSharedTopicFilterImpl);
268267
final ImmutableList<String> levels = mqtt5TopicFilter.getLevels();
269-
assertThat(levels, CoreMatchers.is(Arrays.asList("", "")));
268+
assertEquals(levels, Arrays.asList("", ""));
270269

271270
final MqttSharedTopicFilterImpl mqtt5SharedTopicFilter = (MqttSharedTopicFilterImpl) mqtt5TopicFilter;
272271
assertEquals(shareName, mqtt5SharedTopicFilter.getShareName());
@@ -283,7 +282,7 @@ void getLevels_simple(final @NotNull SharedTopicFilterSource source) {
283282
assertTrue(mqtt5TopicFilter.isShared());
284283
assertTrue(mqtt5TopicFilter instanceof MqttSharedTopicFilterImpl);
285284
final ImmutableList<String> levels = mqtt5TopicFilter.getLevels();
286-
assertThat(levels, CoreMatchers.is(Arrays.asList("abc", "def", "ghi")));
285+
assertEquals(levels, Arrays.asList("abc", "def", "ghi"));
287286
}
288287

289288
@ParameterizedTest
@@ -296,6 +295,6 @@ void getLevels_multipleEmptyLevels(final @NotNull SharedTopicFilterSource source
296295
assertTrue(mqtt5TopicFilter.isShared());
297296
assertTrue(mqtt5TopicFilter instanceof MqttSharedTopicFilterImpl);
298297
final ImmutableList<String> levels = mqtt5TopicFilter.getLevels();
299-
assertThat(levels, CoreMatchers.is(Arrays.asList("", "abc", "", "def", "", "", "ghi", "")));
298+
assertEquals(levels, Arrays.asList("", "abc", "", "def", "", "", "ghi", ""));
300299
}
301300
}

0 commit comments

Comments
 (0)