This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 72949bbd77 add junit6 support (#2289)
72949bbd77 is described below
commit 72949bbd77f26f6cc99485bcd259ec44b5902aee
Author: PJ Fanning <[email protected]>
AuthorDate: Tue Sep 30 20:29:37 2025 +0100
add junit6 support (#2289)
* add junit6 support
* call it JUnitJupiter
* Update LogCapturingExtensionExampleTest.java
---
.../typed/annotations/JUnitJupiterTestKit.java | 25 ++++++++++
.../typed/javadsl/JUnitJupiterTestKitBuilder.scala | 57 ++++++++++++++++++++++
.../typed/javadsl/TestKitJUnit5Extension.scala | 2 +-
...on.scala => TestKitJUnitJupiterExtension.scala} | 10 ++--
.../javadsl/JUnit5IntegrationExampleTest.java | 1 -
...ava => JUnitJupiterIntegrationExampleTest.java} | 17 +++----
.../javadsl/LogCapturingExtensionExampleTest.java | 12 ++---
.../typed/scaladsl/JUnit5TestKitBuilderSpec.scala | 4 +-
....scala => JUnitJupiterTestKitBuilderSpec.scala} | 32 ++++++------
9 files changed, 120 insertions(+), 40 deletions(-)
diff --git
a/actor-testkit-typed/src/main/java/org/apache/pekko/actor/testkit/typed/annotations/JUnitJupiterTestKit.java
b/actor-testkit-typed/src/main/java/org/apache/pekko/actor/testkit/typed/annotations/JUnitJupiterTestKit.java
new file mode 100644
index 0000000000..1e55dec81f
--- /dev/null
+++
b/actor-testkit-typed/src/main/java/org/apache/pekko/actor/testkit/typed/annotations/JUnitJupiterTestKit.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.actor.testkit.typed.annotations;
+
+import java.lang.annotation.*;
+
+@Documented
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface JUnitJupiterTestKit {}
diff --git
a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/JUnitJupiterTestKitBuilder.scala
b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/JUnitJupiterTestKitBuilder.scala
new file mode 100644
index 0000000000..256ecf8cb2
--- /dev/null
+++
b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/JUnitJupiterTestKitBuilder.scala
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.actor.testkit.typed.javadsl
+
+import org.apache.pekko
+import pekko.actor.testkit.typed.internal.TestKitUtils
+import pekko.actor.testkit.typed.scaladsl.ActorTestKit.ApplicationTestConfig
+import pekko.actor.typed.ActorSystem
+
+import com.typesafe.config.Config
+
+final class JUnitJupiterTestKitBuilder() {
+
+ var system: Option[ActorSystem[_]] = None
+
+ var customConfig: Config = ApplicationTestConfig
+
+ var name: String =
TestKitUtils.testNameFromCallStack(classOf[JUnitJupiterTestKitBuilder])
+
+ def withSystem(system: ActorSystem[_]): JUnitJupiterTestKitBuilder = {
+ this.system = Some(system)
+ this
+ }
+
+ def withCustomConfig(customConfig: Config): JUnitJupiterTestKitBuilder = {
+ this.customConfig = customConfig
+ this
+ }
+
+ def withName(name: String): JUnitJupiterTestKitBuilder = {
+ this.name = name
+ this
+ }
+
+ def build(): ActorTestKit = {
+ if (system.isDefined) {
+ return ActorTestKit.create(system.get)
+ }
+ ActorTestKit.create(name, customConfig)
+ }
+
+}
diff --git
a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnit5Extension.scala
b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnit5Extension.scala
index 9dc544b0b0..d957478228 100644
---
a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnit5Extension.scala
+++
b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnit5Extension.scala
@@ -27,7 +27,7 @@ final class TestKitJUnit5Extension() extends AfterAllCallback
with BeforeTestExe
var testKit: Option[ActorTestKit] = None
/**
- * Get a reference to the field annotated with @JUnit5Testkit
[[JUnit5TestKit]]
+ * Get a reference to the field annotated with `@JUnit5Testkit`
[[JUnit5TestKit]]
*/
override def beforeTestExecution(context: ExtensionContext): Unit = {
val testInstance: Option[AnyRef] =
diff --git
a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnit5Extension.scala
b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnitJupiterExtension.scala
similarity index 82%
copy from
actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnit5Extension.scala
copy to
actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnitJupiterExtension.scala
index 9dc544b0b0..6522897fd0 100644
---
a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnit5Extension.scala
+++
b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/javadsl/TestKitJUnitJupiterExtension.scala
@@ -20,22 +20,22 @@ package org.apache.pekko.actor.testkit.typed.javadsl
import org.junit.jupiter.api.extension.{ AfterAllCallback,
BeforeTestExecutionCallback, ExtensionContext }
import org.junit.platform.commons.support.AnnotationSupport
-import org.apache.pekko.actor.testkit.typed.annotations.JUnit5TestKit
+import org.apache.pekko.actor.testkit.typed.annotations.JUnitJupiterTestKit
-final class TestKitJUnit5Extension() extends AfterAllCallback with
BeforeTestExecutionCallback {
+final class TestKitJUnitJupiterExtension() extends AfterAllCallback with
BeforeTestExecutionCallback {
var testKit: Option[ActorTestKit] = None
/**
- * Get a reference to the field annotated with @JUnit5Testkit
[[JUnit5TestKit]]
+ * Get a reference to the field annotated with `@JUnitJupiterTestKit`
[[JUnitJupiterTestKit]]
*/
override def beforeTestExecution(context: ExtensionContext): Unit = {
val testInstance: Option[AnyRef] =
if (context.getTestInstance.isPresent)
Some(context.getTestInstance.get()) else None
testInstance.map(instance => {
- val annotations = AnnotationSupport.findAnnotatedFieldValues(instance,
classOf[JUnit5TestKit])
+ val annotations = AnnotationSupport.findAnnotatedFieldValues(instance,
classOf[JUnitJupiterTestKit])
val fieldValue = annotations.stream().findFirst().orElseThrow(() =>
- throw new IllegalArgumentException("Could not find field annotated
with @JUnit5TestKit"))
+ throw new IllegalArgumentException("Could not find field annotated
with @JUnitJupiterTestKit"))
testKit = Some(fieldValue.asInstanceOf[ActorTestKit])
})
}
diff --git
a/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnit5IntegrationExampleTest.java
b/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnit5IntegrationExampleTest.java
index afaea2825a..0e727d4c89 100644
---
a/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnit5IntegrationExampleTest.java
+++
b/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnit5IntegrationExampleTest.java
@@ -15,7 +15,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.pekko.actor.Address;
import org.apache.pekko.actor.testkit.typed.annotations.JUnit5TestKit;
import org.apache.pekko.actor.testkit.typed.javadsl.*;
-import org.apache.pekko.actor.testkit.typed.javadsl.JUnit5TestKitBuilder;
import org.apache.pekko.actor.typed.ActorRef;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
diff --git
a/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnit5IntegrationExampleTest.java
b/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnitJupiterIntegrationExampleTest.java
similarity index 82%
copy from
actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnit5IntegrationExampleTest.java
copy to
actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnitJupiterIntegrationExampleTest.java
index afaea2825a..b6efa97f92 100644
---
a/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnit5IntegrationExampleTest.java
+++
b/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/JUnitJupiterIntegrationExampleTest.java
@@ -13,23 +13,22 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.pekko.actor.Address;
-import org.apache.pekko.actor.testkit.typed.annotations.JUnit5TestKit;
+import org.apache.pekko.actor.testkit.typed.annotations.JUnitJupiterTestKit;
import org.apache.pekko.actor.testkit.typed.javadsl.*;
-import org.apache.pekko.actor.testkit.typed.javadsl.JUnit5TestKitBuilder;
import org.apache.pekko.actor.typed.ActorRef;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-// #junit5-integration
-@DisplayName("JUnit5")
-@ExtendWith(TestKitJUnit5Extension.class)
-class JUnit5IntegrationExampleTest {
+// #junit-jupiter-integration
+@DisplayName("JUnitJupiter")
+@ExtendWith(TestKitJUnitJupiterExtension.class)
+class JUnitJupiterIntegrationExampleTest {
- @JUnit5TestKit public ActorTestKit testKit = new
JUnit5TestKitBuilder().build();
+ @JUnitJupiterTestKit public ActorTestKit testKit = new
JUnitJupiterTestKitBuilder().build();
@Test
- void junit5Test() {
+ void junitJupiterTest() {
Address address = testKit.system().address();
assertNotNull(address);
}
@@ -57,4 +56,4 @@ class JUnit5IntegrationExampleTest {
assertEquals("hello", pong.message);
}
}
-// #junit5-integration
+// #junit-jupiter-integration
diff --git
a/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/LogCapturingExtensionExampleTest.java
b/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/LogCapturingExtensionExampleTest.java
index 8da89caad1..f64d69425c 100644
---
a/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/LogCapturingExtensionExampleTest.java
+++
b/actor-testkit-typed/src/test/java/jdocs/org/apache/pekko/actor/testkit/typed/javadsl/LogCapturingExtensionExampleTest.java
@@ -19,9 +19,9 @@ package jdocs.org.apache.pekko.actor.testkit.typed.javadsl;
import static
jdocs.org.apache.pekko.actor.testkit.typed.javadsl.AsyncTestingExampleTest.Echo;
-import org.apache.pekko.actor.testkit.typed.annotations.JUnit5TestKit;
+import
jdocs.org.apache.pekko.actor.testkit.typed.javadsl.AsyncTestingExampleTest.Echo;
+import org.apache.pekko.actor.testkit.typed.annotations.JUnitJupiterTestKit;
import org.apache.pekko.actor.testkit.typed.javadsl.*;
-import org.apache.pekko.actor.testkit.typed.javadsl.JUnit5TestKitBuilder;
import org.apache.pekko.actor.typed.ActorRef;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -29,12 +29,12 @@ import org.junit.jupiter.api.extension.ExtendWith;
// test code copied from LogCapturingExampleTest.java
-@DisplayName("JUnit5 log capturing")
-@ExtendWith(TestKitJUnit5Extension.class)
+@DisplayName("JUnitJupiter log capturing")
+@ExtendWith(TestKitJUnitJupiterExtension.class)
@ExtendWith(LogCapturingExtension.class)
class LogCapturingExtensionExampleTest {
- @JUnit5TestKit public ActorTestKit testKit = new
JUnit5TestKitBuilder().build();
+ @JUnitJupiterTestKit public ActorTestKit testKit = new
JUnitJupiterTestKitBuilder().build();
@Test
void testSomething() {
@@ -52,4 +52,4 @@ class LogCapturingExtensionExampleTest {
probe.expectMessage(new Echo.Pong("hello"));
}
}
-// #log-capturing-junit5
+// #log-capturing-junit-jupiter
diff --git
a/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnit5TestKitBuilderSpec.scala
b/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnit5TestKitBuilderSpec.scala
index 46b6e8ba69..efb14eca6e 100644
---
a/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnit5TestKitBuilderSpec.scala
+++
b/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnit5TestKitBuilderSpec.scala
@@ -74,12 +74,12 @@ class JUnit5TestKitBuilderSpec extends AnyWordSpec {
"the JUnit5TestKitBuilder" should {
"create a Testkit with a custom system" in {
- val system: ActorSystem[GreeterMain.SayHello] =
ActorSystem(GreeterMain(), "AkkaQuickStart")
+ val system: ActorSystem[GreeterMain.SayHello] =
ActorSystem(GreeterMain(), "PekkoQuickStart")
val actualTestKit = new JUnit5TestKitBuilder()
.withSystem(system)
.build()
- assertResult("AkkaQuickStart")(actualTestKit.system.name)
+ assertResult("PekkoQuickStart")(actualTestKit.system.name)
}
}
diff --git
a/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnit5TestKitBuilderSpec.scala
b/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnitJupiterTestKitBuilderSpec.scala
similarity index 67%
copy from
actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnit5TestKitBuilderSpec.scala
copy to
actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnitJupiterTestKitBuilderSpec.scala
index 46b6e8ba69..9b142c54d6 100644
---
a/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnit5TestKitBuilderSpec.scala
+++
b/actor-testkit-typed/src/test/scala/org/apache/pekko/actor/testkit/typed/scaladsl/JUnitJupiterTestKitBuilderSpec.scala
@@ -18,50 +18,50 @@
package org.apache.pekko.actor.testkit.typed.scaladsl
import org.apache.pekko
-import org.apache.pekko.actor.testkit.typed.javadsl.JUnit5TestKitBuilder
+import org.apache.pekko.actor.testkit.typed.javadsl.JUnitJupiterTestKitBuilder
import pekko.actor.typed.ActorSystem
import org.scalatest.wordspec.AnyWordSpec
import com.typesafe.config.ConfigFactory
-class JUnit5TestKitBuilderSpec extends AnyWordSpec {
+class JUnitJupiterTestKitBuilderSpec extends AnyWordSpec {
- "the JUnit5TestKitBuilder" should {
+ "the JUnitJupiterTestKitBuilder" should {
"create a Testkit with name hello" in {
- val actualTestKit = new JUnit5TestKitBuilder().withName("hello").build()
+ val actualTestKit = new
JUnitJupiterTestKitBuilder().withName("hello").build()
assertResult("hello")(actualTestKit.system.name)
}
}
- "the JUnit5TestKitBuilder" should {
+ "the JUnitJupiterTestKitBuilder" should {
"create a Testkit with the classname as name" in {
- val actualTestKit = new JUnit5TestKitBuilder()
+ val actualTestKit = new JUnitJupiterTestKitBuilder()
.build()
- assertResult("JUnit5TestKitBuilderSpec")(actualTestKit.system.name)
+ assertResult("JUnitJupiterTestKitBuilderSpec")(actualTestKit.system.name)
}
}
- "the JUnit5TestKitBuilder" should {
+ "the JUnitJupiterTestKitBuilder" should {
"create a Testkit with a custom config" in {
val conf = ConfigFactory.load("application.conf")
- val actualTestKit = new JUnit5TestKitBuilder()
+ val actualTestKit = new JUnitJupiterTestKitBuilder()
.withCustomConfig(conf)
.build()
assertResult("someValue")(actualTestKit.system.settings.config.getString("test.value"))
- assertResult("JUnit5TestKitBuilderSpec")(actualTestKit.system.name)
+ assertResult("JUnitJupiterTestKitBuilderSpec")(actualTestKit.system.name)
}
}
- "the JUnit5TestKitBuilder" should {
+ "the JUnitJupiterTestKitBuilder" should {
"create a Testkit with a custom config and name" in {
val conf = ConfigFactory.load("application.conf")
- val actualTestKit = new JUnit5TestKitBuilder()
+ val actualTestKit = new JUnitJupiterTestKitBuilder()
.withCustomConfig(conf)
.withName("hello")
.build()
@@ -71,15 +71,15 @@ class JUnit5TestKitBuilderSpec extends AnyWordSpec {
}
}
- "the JUnit5TestKitBuilder" should {
+ "the JUnitJupiterTestKitBuilder" should {
"create a Testkit with a custom system" in {
- val system: ActorSystem[GreeterMain.SayHello] =
ActorSystem(GreeterMain(), "AkkaQuickStart")
+ val system: ActorSystem[GreeterMain.SayHello] =
ActorSystem(GreeterMain(), "PekkoQuickStart")
- val actualTestKit = new JUnit5TestKitBuilder()
+ val actualTestKit = new JUnitJupiterTestKitBuilder()
.withSystem(system)
.build()
- assertResult("AkkaQuickStart")(actualTestKit.system.name)
+ assertResult("PekkoQuickStart")(actualTestKit.system.name)
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]