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

commit 042c9797bc94b6863c69e1779965fab6617cadf0
Author: Otavio Rodolfo Piske <angusyo...@gmail.com>
AuthorDate: Tue May 14 16:54:30 2024 +0200

    (chores) camel-test-junit5: decouple the hasAnnotationCheck
---
 .../apache/camel/test/junit5/CamelTestSupport.java | 19 ++++-------
 .../camel/test/junit5/util/ExtensionHelper.java    | 39 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 13 deletions(-)

diff --git 
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
index 4aae8bc3962..4f565b8c195 100644
--- 
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
+++ 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
@@ -61,6 +61,7 @@ import org.apache.camel.support.BreakpointSupport;
 import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.support.PluginHelper;
 import org.apache.camel.test.CamelRouteCoverageDumper;
+import org.apache.camel.test.junit5.util.ExtensionHelper;
 import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.TimeUtils;
@@ -406,7 +407,7 @@ public abstract class CamelTestSupport
      * Camel on Spring Boot.
      */
     protected void doSpringBootCheck() {
-        boolean springBoot = 
hasClassAnnotation("org.springframework.boot.test.context.SpringBootTest");
+        boolean springBoot = 
ExtensionHelper.hasClassAnnotation(getClass(),"org.springframework.boot.test.context.SpringBootTest");
         if (springBoot) {
             throw new RuntimeException(
                     "Spring Boot detected: The 
CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing 
with Spring Boot.");
@@ -418,8 +419,7 @@ public abstract class CamelTestSupport
      * Camel onQuarkus.
      */
     protected void doQuarkusCheck() {
-        boolean quarkus = 
hasClassAnnotation("io.quarkus.test.junit.QuarkusTest") ||
-                
hasClassAnnotation("org.apache.camel.quarkus.test.CamelQuarkusTest");
+        boolean quarkus = ExtensionHelper.hasClassAnnotation(getClass(), 
"io.quarkus.test.junit.QuarkusTest", 
"org.apache.camel.quarkus.test.CamelQuarkusTest");
         if (quarkus) {
             throw new RuntimeException(
                     "Quarkus detected: The 
CamelTestSupport/CamelSpringTestSupport class is not intended for Camel testing 
with Quarkus.");
@@ -727,7 +727,7 @@ public abstract class CamelTestSupport
     protected void applyCamelPostProcessor() throws Exception {
         // use the bean post processor if the test class is not dependency
         // injected already by Spring Framework
-        boolean spring = 
hasClassAnnotation("org.springframework.boot.test.context.SpringBootTest",
+        boolean spring = ExtensionHelper.hasClassAnnotation(getClass(), 
"org.springframework.boot.test.context.SpringBootTest",
                 "org.springframework.context.annotation.ComponentScan");
         if (!spring) {
             
PluginHelper.getBeanPostProcessor(context).postProcessBeforeInitialization(this,
@@ -740,16 +740,9 @@ public abstract class CamelTestSupport
     /**
      * Does this test class have any of the following annotations on the 
class-level.
      */
+    @Deprecated
     protected boolean hasClassAnnotation(String... names) {
-        for (String name : names) {
-            for (Annotation ann : getClass().getAnnotations()) {
-                String annName = ann.annotationType().getName();
-                if (annName.equals(name)) {
-                    return true;
-                }
-            }
-        }
-        return false;
+        return ExtensionHelper.hasClassAnnotation(getClass(), names);
     }
 
     protected void stopCamelContext() throws Exception {
diff --git 
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
new file mode 100644
index 00000000000..64f356b78ac
--- /dev/null
+++ 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/ExtensionHelper.java
@@ -0,0 +1,39 @@
+/*
+ * 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.camel.test.junit5.util;
+
+import java.lang.annotation.Annotation;
+
+public final class ExtensionHelper {
+
+    /**
+     * Does the test class have any of the following annotations on the 
class-level?
+     * @return true if has or false otherwise
+     */
+    public static boolean hasClassAnnotation(Class<?> clazz, String... names) {
+        for (String name : names) {
+            for (Annotation ann : clazz.getAnnotations()) {
+                String annName = ann.annotationType().getName();
+                if (annName.equals(name)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+}

Reply via email to