Skip to content

Commit c8f84db

Browse files
committed
Migrate tests to JUnit 5
1 parent ae3f9a8 commit c8f84db

15 files changed

+465
-557
lines changed

build.gradle

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,36 @@ ext.isReleaseVersion = provider {
2525
!version.endsWith("SNAPSHOT")
2626
}
2727

28-
sourceCompatibility = JavaVersion.VERSION_17
29-
targetCompatibility = JavaVersion.VERSION_17
28+
dependencies {
29+
testImplementation platform(testLibs.junit.bom)
30+
}
3031

3132
java {
3233
withJavadocJar()
3334
withSourcesJar()
35+
sourceCompatibility = JavaVersion.VERSION_17
36+
targetCompatibility = JavaVersion.VERSION_17
3437
}
3538

36-
dependencies {
37-
testImplementation project.testLibs.junit
39+
testing {
40+
suites {
41+
configureEach {
42+
useJUnitJupiter()
43+
dependencies {
44+
implementation.bundle(testLibs.bundles.junit)
45+
}
46+
targets {
47+
configureEach {
48+
testTask.configure {
49+
testLogging {
50+
events "passed", "skipped", "failed"
51+
}
52+
systemProperty 'file.encoding', 'UTF-8'
53+
}
54+
}
55+
}
56+
}
57+
}
3858
}
3959

4060
sourceSets {
@@ -55,10 +75,6 @@ tasks.withType(JavaCompile).configureEach {
5575
options.encoding = 'UTF-8'
5676
}
5777

58-
tasks.withType(Test).configureEach {
59-
systemProperty 'file.encoding', 'UTF-8'
60-
}
61-
6278
tasks.withType(Jar).configureEach {
6379
// General manifest info
6480
manifest {

settings.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ dependencyResolutionManagement {
77

88
versionCatalogs {
99
testLibs {
10-
version('junit', '4.13.1')
10+
version('junit', '5.9.3')
1111

12-
library('junit', 'junit', 'junit').versionRef('junit')
12+
library('junit-bom', 'org.junit', 'junit-bom').versionRef('junit')
13+
library('junit-jupiter', 'org.junit.jupiter', 'junit-jupiter').withoutVersion()
14+
15+
bundle('junit', ['junit-jupiter'])
1316
}
1417
}
1518
}

src/test/java/org/firebirdsql/decimal/Decimal128ByteConversionTest.java

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,44 @@
2121
*/
2222
package org.firebirdsql.decimal;
2323

24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
26-
import org.junit.runners.Parameterized;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.Arguments;
26+
import org.junit.jupiter.params.provider.MethodSource;
2727

2828
import java.math.BigDecimal;
29-
import java.util.Arrays;
30-
import java.util.Collection;
29+
import java.util.stream.Stream;
3130

3231
import static org.firebirdsql.decimal.util.ByteArrayHelper.hexToBytes;
33-
import static org.junit.Assert.assertArrayEquals;
34-
import static org.junit.Assert.assertEquals;
35-
import static org.junit.Assume.assumeTrue;
32+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
3635

37-
/**
38-
* @author <a href="mailto:mark@lawinegevaar.nl">Mark Rotteveel</a>
39-
*/
40-
@RunWith(Parameterized.class)
41-
public class Decimal128ByteConversionTest {
42-
43-
@Parameterized.Parameter
44-
public String description;
45-
@Parameterized.Parameter(1)
46-
public byte[] sourceBytes;
47-
@Parameterized.Parameter(2)
48-
public Decimal128 decimalValue;
49-
@Parameterized.Parameter(3)
50-
public byte[] targetBytes;
36+
class Decimal128ByteConversionTest {
5137

52-
@Test
53-
public void testConversionFromBytesToDecimal128() {
54-
assumeTrue("No source bytes for " + description, sourceBytes != null);
38+
@SuppressWarnings("unused")
39+
@ParameterizedTest(name = "{index}: value {0} ({2})")
40+
@MethodSource("data")
41+
void testConversionFromBytesToDecimal128(String description, byte[] sourceBytes, Decimal128 decimalValue,
42+
byte[] targetBytes) {
43+
assumeTrue(sourceBytes != null, "No source bytes for " + description);
5544
Decimal128 result = Decimal128.parseBytes(sourceBytes);
5645

57-
assertEquals("Expected " + description, decimalValue, result);
46+
assertEquals(decimalValue, result, "Expected " + description);
5847
}
5948

60-
@Test
61-
public void testConversionFromDecimal128ToBytes() {
62-
assumeTrue("No target bytes for " + description, targetBytes != null);
49+
@SuppressWarnings("unused")
50+
@ParameterizedTest(name = "{index}: value {0} ({2})")
51+
@MethodSource("data")
52+
void testConversionFromDecimal128ToBytes(String description, byte[] sourceBytes, Decimal128 decimalValue,
53+
byte[] targetBytes) {
54+
assumeTrue(targetBytes != null, "No target bytes for " + description);
6355
byte[] result = decimalValue.toBytes();
6456

6557
assertArrayEquals(targetBytes, result);
6658
}
6759

68-
@Parameterized.Parameters(name = "{index}: value {0} ({2})")
69-
public static Collection<Object[]> data() {
70-
return Arrays.asList(
60+
static Stream<Arguments> data() {
61+
return Stream.of(
7162
testCase("POSITIVE_INFINITY",
7263
new byte[] { 0b0_11110_00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
7364
Decimal128.POSITIVE_INFINITY),
@@ -446,7 +437,7 @@ public static Collection<Object[]> data() {
446437
* String encoding of the decimal value (compatible with parsing by {@link BigDecimal}
447438
* @return Test case data
448439
*/
449-
private static Object[] testCase(String sourceEncodedString, String decimalString) {
440+
private static Arguments testCase(String sourceEncodedString, String decimalString) {
450441
return testCase(decimalString, hexToBytes(sourceEncodedString), dec(decimalString));
451442
}
452443

@@ -464,7 +455,7 @@ private static Object[] testCase(String sourceEncodedString, String decimalStrin
464455
* Hex string of binary encoding of decimal (target)
465456
* @return Test case data
466457
*/
467-
private static Object[] testCase(String sourceEncodedString, String decimalString, String targetEncodedString) {
458+
private static Arguments testCase(String sourceEncodedString, String decimalString, String targetEncodedString) {
468459
return testCase(decimalString, hexToBytes(sourceEncodedString), dec(decimalString),
469460
hexToBytes(targetEncodedString));
470461
}
@@ -481,7 +472,7 @@ private static Object[] testCase(String sourceEncodedString, String decimalStrin
481472
* Decimal128 value
482473
* @return Test case data
483474
*/
484-
private static Object[] testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value) {
475+
private static Arguments testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value) {
485476
return testCase(description, sourceBytes, decimal128Value, sourceBytes);
486477
}
487478

@@ -499,9 +490,9 @@ private static Object[] testCase(String description, byte[] sourceBytes, Decimal
499490
* Binary encoding of decimal (target)
500491
* @return Test case data
501492
*/
502-
private static Object[] testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value,
493+
private static Arguments testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value,
503494
byte[] targetBytes) {
504-
return new Object[] { description, sourceBytes, decimal128Value, targetBytes };
495+
return Arguments.of(description, sourceBytes, decimal128Value, targetBytes);
505496
}
506497

507498
private static Decimal128 dec(String decimalString) {

0 commit comments

Comments
 (0)