You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/08/10 11:15:33 UTC

[camel] branch main updated: CAMEL-19712: adapt to support Junit 5.10 (#11027)

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 261e676ef12 CAMEL-19712: adapt to support Junit 5.10 (#11027)
261e676ef12 is described below

commit 261e676ef12c995f87f6c672b9214b2400861f8a
Author: Jono Morris <jo...@xtra.co.nz>
AuthorDate: Thu Aug 10 23:15:25 2023 +1200

    CAMEL-19712: adapt to support Junit 5.10 (#11027)
    
    * CAMEL-19712 provide context to argument converter
    
    * CAMEL-19712 remove extra blank lines
---
 components/camel-test/camel-test-junit5/pom.xml            |  5 +++++
 .../camel/test/junit5/params/ParameterizedExtension.java   | 14 +++++++++++++-
 parent/pom.xml                                             |  2 +-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/components/camel-test/camel-test-junit5/pom.xml b/components/camel-test/camel-test-junit5/pom.xml
index cae643c767b..04bf761e4a1 100644
--- a/components/camel-test/camel-test-junit5/pom.xml
+++ b/components/camel-test/camel-test-junit5/pom.xml
@@ -147,6 +147,11 @@
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-params</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>${mockito-version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-xml-jaxb</artifactId>
diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/params/ParameterizedExtension.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/params/ParameterizedExtension.java
index cda04cfc491..4751276be23 100644
--- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/params/ParameterizedExtension.java
+++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/params/ParameterizedExtension.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.test.junit5.params;
 
+import java.lang.reflect.Executable;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -26,6 +27,7 @@ import java.util.stream.Stream;
 
 import org.junit.jupiter.api.extension.Extension;
 import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
 import org.junit.jupiter.api.extension.TestInstancePostProcessor;
 import org.junit.jupiter.api.extension.TestInstantiationException;
 import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
@@ -37,6 +39,8 @@ import org.junit.platform.commons.util.ReflectionUtils;
 
 import static org.junit.jupiter.params.provider.Arguments.arguments;
 import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class ParameterizedExtension implements TestTemplateInvocationContextProvider {
 
@@ -135,10 +139,18 @@ public class ParameterizedExtension implements TestTemplateInvocationContextProv
             for (int i = 0; i < fields.size(); i++) {
                 Field f = fields.get(i);
                 f.setAccessible(true);
-                f.set(testInstance, DefaultArgumentConverter.INSTANCE.convert(params[i], f.getType()));
+                f.set(testInstance, DefaultArgumentConverter.INSTANCE.convert(params[i], f.getType(), getContext()));
             }
         }
 
+        private ParameterContext getContext() throws NoSuchMethodException {
+            Executable executable =
+                    this.getClass().getConstructor(Object[].class).getParameters()[0].getDeclaringExecutable();
+            ParameterContext parameterContext = mock(ParameterContext.class);
+            when(parameterContext.getDeclaringExecutable()).thenReturn(executable);
+            return parameterContext;
+        }
+
         protected Stream<Class<?>> hierarchy(Class<?> clazz) {
             Class<?> superclass = clazz.getSuperclass();
             return Stream.concat(Stream.of(clazz), superclass != null ? hierarchy(superclass) : Stream.empty());
diff --git a/parent/pom.xml b/parent/pom.xml
index 123ab1ec21d..b820e366a51 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -290,7 +290,7 @@
         <jsoup-version>1.16.1</jsoup-version>
         <jt400-version>20.0.0</jt400-version>
         <junit-toolbox-version>2.4</junit-toolbox-version>
-        <junit-jupiter-version>5.9.3</junit-jupiter-version>
+        <junit-jupiter-version>5.10.0</junit-jupiter-version>
         <junit-pioneer-version>2.0.1</junit-pioneer-version>
         <jxmpp-version>1.0.3</jxmpp-version>
         <jython-version>2.7.3</jython-version>