Skip to content

Commit 7367653

Browse files
xerialclaude
andauthored
Migrate from JUnit 4 to JUnit 5 to resolve deprecation warnings (#897)
- Update build.sbt to use JUnit 5 dependencies (jupiter + vintage) - Replace JUnit 4 imports with JUnit 5 equivalents - Convert @test(expected=Exception.class) to assertThrows() - Update @before to @beforeeach annotation - Replace deprecated org.junit.Assert.assertThat with Hamcrest assertThat - Maintain backward compatibility with JUnit Vintage engine Fixes all JUnit deprecation warnings in msgpack-jackson tests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 8f1dddd commit 7367653

10 files changed

+47
-38
lines changed

build.sbt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ val buildSettings = Seq[Setting[_]](
4646
Test / compile := ((Test / compile) dependsOn (Test / jcheckStyle)).value
4747
)
4848

49-
val junitInterface = "com.github.sbt" % "junit-interface" % "0.13.3" % "test"
49+
val junitJupiter = "org.junit.jupiter" % "junit-jupiter" % "5.11.4" % "test"
50+
val junitVintage = "org.junit.vintage" % "junit-vintage-engine" % "5.11.4" % "test"
5051

5152
// Project settings
5253
lazy val root = Project(id = "msgpack-java", base = file("."))
@@ -83,7 +84,8 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
8384
Test / fork := true,
8485
libraryDependencies ++= Seq(
8586
// msgpack-core should have no external dependencies
86-
junitInterface,
87+
junitJupiter,
88+
junitVintage,
8789
"org.wvlet.airframe" %% "airframe-json" % AIRFRAME_VERSION % "test",
8890
"org.wvlet.airframe" %% "airspec" % AIRFRAME_VERSION % "test",
8991
// Add property testing support with forAll methods
@@ -110,7 +112,8 @@ lazy val msgpackJackson =
110112
),
111113
libraryDependencies ++= Seq(
112114
"com.fasterxml.jackson.core" % "jackson-databind" % "2.18.2",
113-
junitInterface,
115+
junitJupiter,
116+
junitVintage,
114117
"org.apache.commons" % "commons-math3" % "3.6.1" % "test"
115118
),
116119
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v")

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackDataformatForFieldIdTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import java.util.Map;
3434
import java.util.Set;
3535
import java.util.LinkedHashMap;
36-
import org.junit.Test;
36+
import org.junit.jupiter.api.Test;
3737

38-
import static org.junit.Assert.assertEquals;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
3939

4040
public class MessagePackDataformatForFieldIdTest
4141
{

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackDataformatForPojoTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
package org.msgpack.jackson.dataformat;
1717

1818
import com.fasterxml.jackson.databind.ObjectMapper;
19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import java.io.IOException;
2222
import java.nio.charset.Charset;
2323

2424
import static org.hamcrest.CoreMatchers.not;
2525
import static org.hamcrest.CoreMatchers.containsString;
2626

27-
import static org.junit.Assert.assertEquals;
28-
import static org.junit.Assert.assertThat;
29-
import static org.junit.Assert.assertArrayEquals;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
29+
import static org.hamcrest.MatcherAssert.assertThat;
3030

3131
public class MessagePackDataformatForPojoTest
3232
extends MessagePackDataformatTestBase

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackFactoryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.fasterxml.jackson.databind.AnnotationIntrospector;
2424
import com.fasterxml.jackson.databind.ObjectMapper;
2525
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727
import org.msgpack.core.MessagePack;
2828

2929
import java.io.IOException;
@@ -35,8 +35,8 @@
3535
import static org.hamcrest.CoreMatchers.is;
3636
import static org.hamcrest.CoreMatchers.notNullValue;
3737
import static org.hamcrest.CoreMatchers.nullValue;
38-
import static org.junit.Assert.assertEquals;
39-
import static org.junit.Assert.assertThat;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
import static org.hamcrest.MatcherAssert.assertThat;
4040

4141
public class MessagePackFactoryTest
4242
extends MessagePackDataformatTestBase

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackGeneratorTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.fasterxml.jackson.databind.SerializerProvider;
2525
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2626
import com.fasterxml.jackson.databind.module.SimpleModule;
27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828
import org.msgpack.core.ExtensionTypeHeader;
2929
import org.msgpack.core.MessagePack;
3030
import org.msgpack.core.MessageUnpacker;
@@ -53,13 +53,14 @@
5353
import java.util.concurrent.TimeUnit;
5454

5555
import static org.hamcrest.CoreMatchers.is;
56-
import static org.junit.Assert.assertArrayEquals;
57-
import static org.junit.Assert.assertEquals;
58-
import static org.junit.Assert.assertFalse;
59-
import static org.junit.Assert.assertNotEquals;
60-
import static org.junit.Assert.assertThat;
61-
import static org.junit.Assert.assertTrue;
62-
import static org.junit.Assert.fail;
56+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
57+
import static org.junit.jupiter.api.Assertions.assertEquals;
58+
import static org.junit.jupiter.api.Assertions.assertFalse;
59+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
60+
import static org.junit.jupiter.api.Assertions.assertTrue;
61+
import static org.junit.jupiter.api.Assertions.fail;
62+
import static org.junit.jupiter.api.Assertions.assertThrows;
63+
import static org.hamcrest.MatcherAssert.assertThat;
6364

6465
public class MessagePackGeneratorTest
6566
extends MessagePackDataformatTestBase
@@ -349,7 +350,7 @@ public void testBigDecimal()
349350
}
350351
}
351352

352-
@Test(expected = IOException.class)
353+
@Test
353354
public void testEnableFeatureAutoCloseTarget()
354355
throws IOException
355356
{
@@ -358,7 +359,9 @@ public void testEnableFeatureAutoCloseTarget()
358359
ObjectMapper objectMapper = new ObjectMapper(messagePackFactory);
359360
List<Integer> integers = Arrays.asList(1);
360361
objectMapper.writeValue(out, integers);
361-
objectMapper.writeValue(out, integers);
362+
assertThrows(IOException.class, () -> {
363+
objectMapper.writeValue(out, integers);
364+
});
362365
}
363366

364367
@Test

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackMapperTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
package org.msgpack.jackson.dataformat;
1717

1818
import com.fasterxml.jackson.core.JsonProcessingException;
19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import java.io.IOException;
2222
import java.math.BigDecimal;
2323
import java.math.BigInteger;
2424

25-
import static org.junit.Assert.assertEquals;
26-
import static org.junit.Assert.fail;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.fail;
2727

2828
public class MessagePackMapperTest
2929
{

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackParserTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.fasterxml.jackson.databind.ObjectMapper;
2828
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
2929
import com.fasterxml.jackson.databind.module.SimpleModule;
30-
import org.junit.Test;
30+
import org.junit.jupiter.api.Test;
3131
import org.msgpack.core.MessagePack;
3232
import org.msgpack.core.MessagePacker;
3333
import org.msgpack.value.ExtensionValue;
@@ -52,10 +52,11 @@
5252

5353
import static org.hamcrest.MatcherAssert.assertThat;
5454
import static org.hamcrest.core.Is.is;
55-
import static org.junit.Assert.assertArrayEquals;
56-
import static org.junit.Assert.assertEquals;
57-
import static org.junit.Assert.assertTrue;
58-
import static org.junit.Assert.fail;
55+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
56+
import static org.junit.jupiter.api.Assertions.assertEquals;
57+
import static org.junit.jupiter.api.Assertions.assertTrue;
58+
import static org.junit.jupiter.api.Assertions.fail;
59+
import static org.junit.jupiter.api.Assertions.assertThrows;
5960

6061
public class MessagePackParserTest
6162
extends MessagePackDataformatTestBase
@@ -450,7 +451,7 @@ public void setup(File f)
450451
return tempFile;
451452
}
452453

453-
@Test(expected = IOException.class)
454+
@Test
454455
public void testEnableFeatureAutoCloseSource()
455456
throws Exception
456457
{
@@ -459,7 +460,9 @@ public void testEnableFeatureAutoCloseSource()
459460
FileInputStream in = new FileInputStream(tempFile);
460461
ObjectMapper objectMapper = new ObjectMapper(factory);
461462
objectMapper.readValue(in, new TypeReference<List<Integer>>() {});
462-
objectMapper.readValue(in, new TypeReference<List<Integer>>() {});
463+
assertThrows(IOException.class, () -> {
464+
objectMapper.readValue(in, new TypeReference<List<Integer>>() {});
465+
});
463466
}
464467

465468
@Test

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/TimestampExtensionModuleTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package org.msgpack.jackson.dataformat;
1717

1818
import com.fasterxml.jackson.databind.ObjectMapper;
19-
import org.junit.Before;
20-
import org.junit.Test;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2121
import org.msgpack.core.MessagePack;
2222
import org.msgpack.core.MessagePacker;
2323
import org.msgpack.core.MessageUnpacker;
@@ -26,7 +26,7 @@
2626
import java.io.IOException;
2727
import java.time.Instant;
2828

29-
import static org.junit.Assert.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
3030

3131
public class TimestampExtensionModuleTest
3232
{
@@ -46,7 +46,7 @@ private static class TripleInstants
4646
public Instant c;
4747
}
4848

49-
@Before
49+
@BeforeEach
5050
public void setUp()
5151
throws Exception
5252
{

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/benchmark/MessagePackDataformatHugeDataBenchmarkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.fasterxml.jackson.core.JsonProcessingException;
2020
import com.fasterxml.jackson.core.type.TypeReference;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323
import org.msgpack.jackson.dataformat.MessagePackFactory;
2424

2525
import java.io.File;

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/benchmark/MessagePackDataformatPojoBenchmarkTest.java

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

1818
import com.fasterxml.jackson.core.JsonProcessingException;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2121
import org.msgpack.jackson.dataformat.MessagePackFactory;
2222
import static org.msgpack.jackson.dataformat.MessagePackDataformatTestBase.NormalPojo;
2323
import static org.msgpack.jackson.dataformat.MessagePackDataformatTestBase.Suit;

0 commit comments

Comments
 (0)