Skip to content

Commit 5d40148

Browse files
committed
Switch to jUnit 5 ("jupiter")
1 parent e2f38cb commit 5d40148

19 files changed

+632
-596
lines changed

modules/core/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ SPDX-License-Identifier: CC0-1.0
114114

115115
<dependencies>
116116
<dependency>
117-
<groupId>junit</groupId>
118-
<artifactId>junit</artifactId>
117+
<groupId>org.junit.jupiter</groupId>
118+
<artifactId>junit-jupiter</artifactId>
119119
<scope>test</scope>
120120
</dependency>
121121

@@ -135,4 +135,3 @@ SPDX-License-Identifier: CC0-1.0
135135
</dependencies>
136136

137137
</project>
138-

modules/core/src/test/java/com/illposed/osc/OSCBundleTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import java.util.Date;
1111
import java.util.GregorianCalendar;
1212
import java.util.List;
13-
import org.junit.Assert;
14-
import org.junit.Test;
13+
import org.junit.jupiter.api.Assertions;
14+
import org.junit.jupiter.api.Test;
1515

1616
/**
1717
* @see OSCBundle
@@ -25,14 +25,14 @@ private void sendBundleTimestampTestHelper(
2525
{
2626
final OSCBundle reparsedBundle = OSCReparserTest.reparse(bundle);
2727
if (!reparsedBundle.getTimestamp().equals(expectedTimestamp)) {
28-
Assert.fail("Send Bundle did not receive the correct timestamp "
28+
Assertions.fail("Send Bundle did not receive the correct timestamp "
2929
+ reparsedBundle.getTimestamp().getNtpTime()
3030
+ " (should be " + expectedTimestamp.getNtpTime() + ')');
3131
}
3232
List<OSCPacket> packets = reparsedBundle.getPackets();
3333
OSCMessage msg = (OSCMessage) packets.get(0);
3434
if (!msg.getAddress().equals("/dummy")) {
35-
Assert.fail("Send Bundle's message did not receive the correct address");
35+
Assertions.fail("Send Bundle's message did not receive the correct address");
3636
}
3737
}
3838

@@ -65,15 +65,18 @@ public void testSendBundleImmediateExplicit() throws Exception {
6565
sendBundleTimestampTestHelper(bundle, OSCTimeTag64.IMMEDIATE);
6666
}
6767

68-
@Test(expected=IllegalArgumentException.class)
68+
@Test
6969
public void testSendBundleImmediateExplicitNull() throws Exception {
7070
final Date timeNow = GregorianCalendar.getInstance().getTime();
7171
final OSCTimeTag64 timestampNow = OSCTimeTag64.valueOf(timeNow);
7272
List<OSCPacket> packetsSent = new ArrayList<>(1);
7373
packetsSent.add(new OSCMessage("/dummy"));
7474
OSCBundle bundle = new OSCBundle(packetsSent, timestampNow);
75-
bundle.setTimestamp(null); // should throw IllegalArgumentException
76-
sendBundleTimestampTestHelper(bundle, OSCTimeTag64.IMMEDIATE);
75+
Assertions.assertThrows(
76+
IllegalArgumentException.class,
77+
() -> bundle.setTimestamp(null)
78+
);
79+
// sendBundleTimestampTestHelper(bundle, OSCTimeTag64.IMMEDIATE);
7780
}
7881

7982
@Test

modules/core/src/test/java/com/illposed/osc/OSCMessageTest.java

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-FileCopyrightText: 2003-2017 C. Ramakrishnan / Illposed Software
2-
// SPDX-FileCopyrightText: 2021 Robin Vobruba <[email protected]>
2+
// SPDX-FileCopyrightText: 2021 - 2024 Robin Vobruba <[email protected]>
33
//
44
// SPDX-License-Identifier: BSD-3-Clause
55

@@ -17,19 +17,14 @@
1717
import java.util.LinkedList;
1818
import java.util.List;
1919
import java.util.TimeZone;
20-
import org.junit.Assert;
21-
import org.junit.Rule;
22-
import org.junit.Test;
23-
import org.junit.rules.ExpectedException;
20+
import org.junit.jupiter.api.Assertions;
21+
import org.junit.jupiter.api.Test;
2422

2523
/**
2624
* @see OSCMessage
2725
*/
2826
public class OSCMessageTest {
2927

30-
@Rule
31-
public ExpectedException expectedException = ExpectedException.none();
32-
3328
public static OSCMessage createUncheckedAddressMessage(final String address, final List<?> arguments, final OSCMessageInfo info) {
3429
return new OSCMessage(address, arguments, info, false);
3530
}
@@ -45,12 +40,12 @@ public static OSCMessage createUncheckedAddressMessage(final String address, fin
4540
private static void checkResultEqualsAnswer(byte[] result, byte[] expected, final int optBytes)
4641
{
4742
if ((result.length != expected.length) && (result.length != (expected.length - optBytes))) {
48-
Assert.fail(createErrorString("Result and expected answer aren't the same length, "
43+
Assertions.fail(createErrorString("Result and expected answer aren't the same length, "
4944
+ result.length + " vs " + expected.length + '.', result, expected));
5045
}
5146
for (int i = 0; i < result.length; i++) {
5247
if (result[i] != expected[i]) {
53-
Assert.fail(createErrorString("Failed to convert correctly at position: " + i,
48+
Assertions.fail(createErrorString("Failed to convert correctly at position: " + i,
5449
result, expected));
5550
}
5651
}
@@ -516,17 +511,17 @@ public void testEncodeLong() throws OSCParseException {
516511
final ByteBuffer bytes = ByteBuffer.wrap(byteArray).asReadOnlyBuffer();
517512
final OSCMessage packet = (OSCMessage) converter.convert(bytes);
518513
if (!packet.getAddress().equals("/dummy")) {
519-
Assert.fail("Send Big Integer did not receive the correct address");
514+
Assertions.fail("Send Big Integer did not receive the correct address");
520515
}
521516
List<?> arguments = packet.getArguments();
522517
if (arguments.size() != 1) {
523-
Assert.fail("Send Big Integer should have 1 argument, not " + arguments.size());
518+
Assertions.fail("Send Big Integer should have 1 argument, not " + arguments.size());
524519
}
525520
if (!(arguments.get(0) instanceof Long)) {
526-
Assert.fail("arguments.get(0) should be a Long, not " + arguments.get(0).getClass());
521+
Assertions.fail("arguments.get(0) should be a Long, not " + arguments.get(0).getClass());
527522
}
528-
if (!(new Long(1001L).equals(arguments.get(0)))) {
529-
Assert.fail("Instead of Long(1001), received " + arguments.get(0));
523+
if (!(Long.valueOf(1001L).equals(arguments.get(0)))) {
524+
Assertions.fail("Instead of Long(1001), received " + arguments.get(0));
530525
}
531526
}
532527

@@ -542,29 +537,29 @@ public void testEncodeArray() throws OSCParseException {
542537
final ByteBuffer bytes = ByteBuffer.wrap(byteArray).asReadOnlyBuffer();
543538
final OSCMessage packet = (OSCMessage) converter.convert(bytes);
544539
if (!packet.getAddress().equals("/dummy")) {
545-
Assert.fail("We did not receive the correct address");
540+
Assertions.fail("We did not receive the correct address");
546541
}
547542
final List<?> arguments = packet.getArguments();
548543
if (arguments.size() != origArguments.size()) {
549-
Assert.fail("We should have received " + origArguments + " arguments, not "
544+
Assertions.fail("We should have received " + origArguments + " arguments, not "
550545
+ arguments.size());
551546
}
552547
final Object firstArgument = arguments.get(0);
553548
if (!(firstArgument instanceof List)) {
554-
Assert.fail("arguments.get(0) should be a List, not "
549+
Assertions.fail("arguments.get(0) should be a List, not "
555550
+ ((firstArgument == null)
556551
? String.valueOf((Object) null)
557552
: firstArgument.getClass().toString()));
558553
}
559554
// We can safely suppress the warning, as we already made sure the cast will not fail.
560555
@SuppressWarnings("unchecked") final List<Object> theArray = (List<Object>) firstArgument;
561556
if (theArray.size() != floats.size()) {
562-
Assert.fail("arguments.get(0) should be a List of size " + floats.size() + " not "
557+
Assertions.fail("arguments.get(0) should be a List of size " + floats.size() + " not "
563558
+ theArray.size());
564559
}
565560
for (int i = 0; i < floats.size(); ++i) {
566561
if (!floats.get(i).equals(theArray.get(i))) {
567-
Assert.fail("List element " + i + " should be " + floats.get(i) + " not "
562+
Assertions.fail("List element " + i + " should be " + floats.get(i) + " not "
568563
+ theArray.get(i));
569564
}
570565
}
@@ -573,9 +568,10 @@ public void testEncodeArray() throws OSCParseException {
573568
@Test
574569
public void testAddressValidationFrontendConstructorNull() {
575570

576-
// expect no exception, as we could still set a valid address later on
577-
expectedException.expect(IllegalArgumentException.class);
578-
OSCMessage oscMessage = new OSCMessage(null);
571+
Assertions.assertThrows(
572+
IllegalArgumentException.class,
573+
() -> new OSCMessage(null)
574+
);
579575
}
580576

581577
@Test
@@ -588,54 +584,56 @@ public void testAddressValidationFrontendConstructorValid() {
588584
@Test
589585
public void testAddressValidationFrontendConstructorInvalid() {
590586

591-
expectedException.expect(IllegalArgumentException.class);
592-
OSCMessage oscMessage = new OSCMessage("/ hello/world");
587+
Assertions.assertThrows(
588+
IllegalArgumentException.class,
589+
() -> new OSCMessage("/ hello/world")
590+
);
593591
}
594592

595593
@Test
596594
public void testAddressValidation() {
597-
Assert.assertFalse(OSCMessage.isValidAddress(null));
598-
Assert.assertFalse(OSCMessage.isValidAddress(""));
599-
Assert.assertFalse(OSCMessage.isValidAddress("hello/world"));
600-
Assert.assertFalse(OSCMessage.isValidAddress("/ hello/world"));
601-
Assert.assertFalse(OSCMessage.isValidAddress("/#hello/world"));
602-
Assert.assertFalse(OSCMessage.isValidAddress("/*hello/world"));
603-
Assert.assertFalse(OSCMessage.isValidAddress("/,hello/world"));
604-
Assert.assertFalse(OSCMessage.isValidAddress("/?hello/world"));
605-
Assert.assertFalse(OSCMessage.isValidAddress("/[hello/world"));
606-
Assert.assertFalse(OSCMessage.isValidAddress("/]hello/world"));
607-
Assert.assertFalse(OSCMessage.isValidAddress("/{hello/world"));
608-
Assert.assertFalse(OSCMessage.isValidAddress("/}hello/world"));
609-
Assert.assertFalse(OSCMessage.isValidAddress("//hello/world"));
610-
Assert.assertFalse(OSCMessage.isValidAddress("#abc"));
611-
Assert.assertFalse(OSCMessage.isValidAddress("#replyx"));
612-
Assert.assertFalse(OSCMessage.isValidAddress("#replx"));
613-
Assert.assertTrue( OSCMessage.isValidAddress("/hello"));
614-
Assert.assertTrue( OSCMessage.isValidAddress("/hello/world"));
615-
Assert.assertTrue( OSCMessage.isValidAddress("/hello/world/two"));
616-
Assert.assertTrue( OSCMessage.isValidAddress("/123/world/two"));
617-
Assert.assertTrue( OSCMessage.isValidAddress("/!hello/world"));
618-
Assert.assertTrue( OSCMessage.isValidAddress("/~hello/world"));
619-
Assert.assertTrue( OSCMessage.isValidAddress("/`hello/world"));
620-
Assert.assertTrue( OSCMessage.isValidAddress("/@hello/world"));
621-
Assert.assertTrue( OSCMessage.isValidAddress("/$hello/world"));
622-
Assert.assertTrue( OSCMessage.isValidAddress("/%hello/world"));
623-
Assert.assertTrue( OSCMessage.isValidAddress("/€hello/world"));
624-
Assert.assertTrue( OSCMessage.isValidAddress("/^hello/world"));
625-
Assert.assertTrue( OSCMessage.isValidAddress("/&hello/world"));
626-
Assert.assertTrue( OSCMessage.isValidAddress("/(hello/world"));
627-
Assert.assertTrue( OSCMessage.isValidAddress("/)hello/world"));
628-
Assert.assertTrue( OSCMessage.isValidAddress("/-hello/world"));
629-
Assert.assertTrue( OSCMessage.isValidAddress("/_hello/world"));
630-
Assert.assertTrue( OSCMessage.isValidAddress("/+hello/world"));
631-
Assert.assertTrue( OSCMessage.isValidAddress("/=hello/world"));
632-
Assert.assertTrue( OSCMessage.isValidAddress("/.hello/world"));
633-
Assert.assertTrue( OSCMessage.isValidAddress("/<hello/world"));
634-
Assert.assertTrue( OSCMessage.isValidAddress("/>hello/world"));
635-
Assert.assertTrue( OSCMessage.isValidAddress("/;hello/world"));
636-
Assert.assertTrue( OSCMessage.isValidAddress("/:hello/world"));
637-
Assert.assertTrue( OSCMessage.isValidAddress("/'hello/world"));
638-
Assert.assertTrue( OSCMessage.isValidAddress("/\"hello/world"));
639-
Assert.assertTrue( OSCMessage.isValidAddress("#reply"));
595+
Assertions.assertFalse(OSCMessage.isValidAddress(null));
596+
Assertions.assertFalse(OSCMessage.isValidAddress(""));
597+
Assertions.assertFalse(OSCMessage.isValidAddress("hello/world"));
598+
Assertions.assertFalse(OSCMessage.isValidAddress("/ hello/world"));
599+
Assertions.assertFalse(OSCMessage.isValidAddress("/#hello/world"));
600+
Assertions.assertFalse(OSCMessage.isValidAddress("/*hello/world"));
601+
Assertions.assertFalse(OSCMessage.isValidAddress("/,hello/world"));
602+
Assertions.assertFalse(OSCMessage.isValidAddress("/?hello/world"));
603+
Assertions.assertFalse(OSCMessage.isValidAddress("/[hello/world"));
604+
Assertions.assertFalse(OSCMessage.isValidAddress("/]hello/world"));
605+
Assertions.assertFalse(OSCMessage.isValidAddress("/{hello/world"));
606+
Assertions.assertFalse(OSCMessage.isValidAddress("/}hello/world"));
607+
Assertions.assertFalse(OSCMessage.isValidAddress("//hello/world"));
608+
Assertions.assertFalse(OSCMessage.isValidAddress("#abc"));
609+
Assertions.assertFalse(OSCMessage.isValidAddress("#replyx"));
610+
Assertions.assertFalse(OSCMessage.isValidAddress("#replx"));
611+
Assertions.assertTrue( OSCMessage.isValidAddress("/hello"));
612+
Assertions.assertTrue( OSCMessage.isValidAddress("/hello/world"));
613+
Assertions.assertTrue( OSCMessage.isValidAddress("/hello/world/two"));
614+
Assertions.assertTrue( OSCMessage.isValidAddress("/123/world/two"));
615+
Assertions.assertTrue( OSCMessage.isValidAddress("/!hello/world"));
616+
Assertions.assertTrue( OSCMessage.isValidAddress("/~hello/world"));
617+
Assertions.assertTrue( OSCMessage.isValidAddress("/`hello/world"));
618+
Assertions.assertTrue( OSCMessage.isValidAddress("/@hello/world"));
619+
Assertions.assertTrue( OSCMessage.isValidAddress("/$hello/world"));
620+
Assertions.assertTrue( OSCMessage.isValidAddress("/%hello/world"));
621+
Assertions.assertTrue( OSCMessage.isValidAddress("/€hello/world"));
622+
Assertions.assertTrue( OSCMessage.isValidAddress("/^hello/world"));
623+
Assertions.assertTrue( OSCMessage.isValidAddress("/&hello/world"));
624+
Assertions.assertTrue( OSCMessage.isValidAddress("/(hello/world"));
625+
Assertions.assertTrue( OSCMessage.isValidAddress("/)hello/world"));
626+
Assertions.assertTrue( OSCMessage.isValidAddress("/-hello/world"));
627+
Assertions.assertTrue( OSCMessage.isValidAddress("/_hello/world"));
628+
Assertions.assertTrue( OSCMessage.isValidAddress("/+hello/world"));
629+
Assertions.assertTrue( OSCMessage.isValidAddress("/=hello/world"));
630+
Assertions.assertTrue( OSCMessage.isValidAddress("/.hello/world"));
631+
Assertions.assertTrue( OSCMessage.isValidAddress("/<hello/world"));
632+
Assertions.assertTrue( OSCMessage.isValidAddress("/>hello/world"));
633+
Assertions.assertTrue( OSCMessage.isValidAddress("/;hello/world"));
634+
Assertions.assertTrue( OSCMessage.isValidAddress("/:hello/world"));
635+
Assertions.assertTrue( OSCMessage.isValidAddress("/'hello/world"));
636+
Assertions.assertTrue( OSCMessage.isValidAddress("/\"hello/world"));
637+
Assertions.assertTrue( OSCMessage.isValidAddress("#reply"));
640638
}
641639
}

0 commit comments

Comments
 (0)