This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new ed5b774f06e CAMEL-20785: fixes JUnit 5 API abuses
ed5b774f06e is described below

commit ed5b774f06e88fa3b5c6d0074757af604be94208
Author: Otavio Rodolfo Piske <angusyo...@gmail.com>
AuthorDate: Fri May 31 16:57:13 2024 +0200

    CAMEL-20785: fixes JUnit 5 API abuses
---
 .../SqsProducerAutoCreateQueueLocalstackIT.java           |  8 +++-----
 .../component/file/watch/FileWatchComponentTestBase.java  | 13 ++-----------
 .../camel/component/jpa/JpaWithOptionsTestSupport.java    |  5 ++---
 .../camel/component/nitrite/AbstractNitriteTest.java      | 15 ++-------------
 4 files changed, 9 insertions(+), 32 deletions(-)

diff --git 
a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerAutoCreateQueueLocalstackIT.java
 
b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerAutoCreateQueueLocalstackIT.java
index cd319632a67..bfca795e976 100644
--- 
a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerAutoCreateQueueLocalstackIT.java
+++ 
b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/integration/SqsProducerAutoCreateQueueLocalstackIT.java
@@ -28,8 +28,8 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.aws2.sqs.Sqs2Constants;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtensionContext;
 import software.amazon.awssdk.services.sqs.SqsClient;
 import software.amazon.awssdk.services.sqs.model.CreateQueueRequest;
 
@@ -41,10 +41,8 @@ public class SqsProducerAutoCreateQueueLocalstackIT extends 
Aws2SQSBaseTest {
     @EndpointInject("mock:result")
     private MockEndpoint result;
 
-    @Override
-    public void beforeEach(ExtensionContext context) throws Exception {
-        super.beforeEach(context);
-
+    @BeforeEach
+    void setup() {
         SqsClient client = AWSSDKClientUtils.newSQSClient();
         for (int i = 0; i < 2000; i++) {
             client.createQueue(CreateQueueRequest.builder().queueName("queue-" 
+ String.valueOf(i)).build());
diff --git 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
index 1a9d9f25b00..4c40891548b 100644
--- 
a/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
+++ 
b/components/camel-file-watch/src/test/java/org/apache/camel/component/file/watch/FileWatchComponentTestBase.java
@@ -20,7 +20,6 @@ import java.io.File;
 import java.io.IOError;
 import java.io.IOException;
 import java.io.UncheckedIOException;
-import java.lang.reflect.Method;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
@@ -29,7 +28,6 @@ import java.util.List;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.file.watch.constants.FileEventEnum;
 import org.apache.camel.test.junit5.CamelTestSupport;
-import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.io.TempDir;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -43,24 +41,17 @@ public class FileWatchComponentTestBase extends 
CamelTestSupport {
 
     protected List<Path> testFiles = new ArrayList<>();
 
-    protected String testMethod;
-
     static void assertFileEvent(String expectedFileName, FileEventEnum 
expectedEventType, Exchange exchange) {
         assertEquals(expectedFileName, 
exchange.getIn().getBody(File.class).getName());
         assertEquals(expectedEventType, 
exchange.getIn().getHeader(FileWatchConstants.EVENT_TYPE_HEADER, 
FileEventEnum.class));
     }
 
-    public void beforeEach(ExtensionContext context) throws Exception {
-        super.beforeEach(context);
-        this.testMethod = 
context.getTestMethod().map(Method::getName).orElse("");
-    }
-
     @Override
     protected void doPreSetup() throws Exception {
         cleanTestDir(new File(testPath()));
         new File(testPath()).mkdirs();
         for (int i = 0; i < 10; i++) {
-            File newFile = new File(testPath(), testMethod + "-" + i);
+            File newFile = new File(testPath(), getCurrentTestName() + "-" + 
i);
             assumeTrue(newFile.createNewFile());
             testFiles.add(newFile.toPath());
         }
@@ -95,7 +86,7 @@ public class FileWatchComponentTestBase extends 
CamelTestSupport {
         try {
             return folder.toRealPath()
                    + folder.getFileSystem().getSeparator()
-                   + getClass().getSimpleName() + "_" + testMethod
+                   + getClass().getSimpleName() + "_" + getCurrentTestName()
                    + folder.getFileSystem().getSeparator();
         } catch (IOException e) {
             throw new IOError(e);
diff --git 
a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithOptionsTestSupport.java
 
b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithOptionsTestSupport.java
index f37620ce59b..09796e18109 100644
--- 
a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithOptionsTestSupport.java
+++ 
b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithOptionsTestSupport.java
@@ -38,9 +38,10 @@ import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.examples.Customer;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
-public abstract class JpaWithOptionsTestSupport extends 
AbstractJpaMethodSupport {
+public abstract class JpaWithOptionsTestSupport extends 
AbstractJpaMethodSupport implements BeforeEachCallback {
 
     // should be less than 1000 as numbers in entries' names are formatted for 
sorting with %03d (or change format)
     static final int ENTRIES_COUNT = 30;
@@ -100,8 +101,6 @@ public abstract class JpaWithOptionsTestSupport extends 
AbstractJpaMethodSupport
 
     @Override
     public void beforeEach(ExtensionContext context) throws Exception {
-        super.beforeEach(context);
-
         final Optional<AnnotatedElement> element = context.getElement();
         if (element.isPresent()) {
             final AnnotatedElement annotatedElement = element.get();
diff --git 
a/components/camel-nitrite/src/test/java/org/apache/camel/component/nitrite/AbstractNitriteTest.java
 
b/components/camel-nitrite/src/test/java/org/apache/camel/component/nitrite/AbstractNitriteTest.java
index 9a39a574e14..a7530a467c1 100644
--- 
a/components/camel-nitrite/src/test/java/org/apache/camel/component/nitrite/AbstractNitriteTest.java
+++ 
b/components/camel-nitrite/src/test/java/org/apache/camel/component/nitrite/AbstractNitriteTest.java
@@ -17,18 +17,13 @@
 package org.apache.camel.component.nitrite;
 
 import java.io.File;
-import java.lang.reflect.Method;
 import java.util.List;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.apache.camel.util.FileUtil;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
 
-public abstract class AbstractNitriteTest extends CamelTestSupport implements 
BeforeEachCallback {
-
-    protected String testMethodName;
+public abstract class AbstractNitriteTest extends CamelTestSupport {
 
     @Override
     protected void doPreSetup() throws Exception {
@@ -36,14 +31,8 @@ public abstract class AbstractNitriteTest extends 
CamelTestSupport implements Be
         FileUtil.deleteFile(new File(tempDb()));
     }
 
-    @Override
-    public void beforeEach(ExtensionContext context) throws Exception {
-        testMethodName = 
context.getTestMethod().map(Method::getName).orElse("unknown");
-        super.beforeEach(context);
-    }
-
     protected String tempDb() {
-        return "target/" + getClass().getSimpleName() + "_" + testMethodName + 
".db";
+        return "target/" + getClass().getSimpleName() + "_" + 
getCurrentTestName() + ".db";
     }
 
     protected List<Exchange> sortByChangeTimestamp(List<Exchange> input) {

Reply via email to