Class Parameters


  • public class Parameters
    extends java.lang.Object
    Methods that bind parameters declared in testng.xml to actual values used to invoke methods.
    • Field Detail

      • annotationList

        private static java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationList
      • mapping

        private static java.util.Map<java.lang.String,​java.util.List<java.lang.Class<?>>> mapping
      • INJECTED_TYPES

        private static final java.util.List<java.lang.Class<?>> INJECTED_TYPES
    • Constructor Detail

      • Parameters

        public Parameters()
    • Method Detail

      • createInstantiationParameters

        public static java.lang.Object[] createInstantiationParameters​(java.lang.reflect.Constructor ctor,
                                                                       java.lang.String methodAnnotation,
                                                                       IAnnotationFinder finder,
                                                                       java.lang.String[] parameterNames,
                                                                       java.util.Map<java.lang.String,​java.lang.String> params,
                                                                       XmlSuite xmlSuite)
        Creates the parameters needed for constructing a test class instance.
      • createConfigurationParameters

        public static java.lang.Object[] createConfigurationParameters​(java.lang.reflect.Method m,
                                                                       java.util.Map<java.lang.String,​java.lang.String> params,
                                                                       java.lang.Object[] parameterValues,
                                                                       @Nullable
                                                                       ITestNGMethod currentTestMethod,
                                                                       IAnnotationFinder finder,
                                                                       XmlSuite xmlSuite,
                                                                       ITestContext ctx,
                                                                       ITestResult testResult)
        Creates the parameters needed for the specified @Configuration Method.
        Parameters:
        m - the configuraton method
        currentTestMethod - the current @Test method or null if no @Test is available (this is not only in case the configuration method is a @Before/@AfterMethod
        finder - the annotation finder
      • retrieveConfigAnnotation

        private static java.lang.Class<? extends java.lang.annotation.Annotation> retrieveConfigAnnotation​(java.lang.reflect.Method m)
      • createParametersForConstructor

        private static java.lang.Object[] createParametersForConstructor​(java.lang.reflect.Constructor constructor,
                                                                         java.lang.Class<?>[] parameterTypes,
                                                                         java.lang.String[] optionalValues,
                                                                         java.lang.String methodAnnotation,
                                                                         java.lang.String[] parameterNames,
                                                                         Parameters.MethodParameters params,
                                                                         XmlSuite xmlSuite)
      • createParams

        private static java.util.List<java.lang.Object> createParams​(java.lang.String name,
                                                                     java.lang.String prefix,
                                                                     java.lang.String methodAnnotation,
                                                                     java.lang.Class<?>[] parameterTypes,
                                                                     java.lang.String[] optionalValues,
                                                                     java.lang.String[] parameterNames,
                                                                     Parameters.MethodParameters params,
                                                                     XmlSuite xmlSuite)
      • filterOutInJectedTypesFromOptionalValues

        static Parameters.FilterOutInJectedTypesResult filterOutInJectedTypesFromOptionalValues​(java.lang.Class<?>[] parameterTypes,
                                                                                                java.lang.String[] optionalValues)
        Remove injected types from parameterTypes and optionalValues
        Parameters:
        parameterTypes - - The parameter types to be used
        optionalValues - - The optional values to be considered.
        Returns:
        FilterOutInJectedTypesResult
      • areAllOptionalValuesNull

        private static boolean areAllOptionalValuesNull​(java.lang.String[] optionalValues)
      • createParametersForMethod

        private static java.lang.Object[] createParametersForMethod​(ConstructorOrMethod method,
                                                                    java.lang.Class<?>[] parameterTypes,
                                                                    java.lang.String[] optionalValues,
                                                                    java.lang.String methodAnnotation,
                                                                    java.lang.String[] parameterNames,
                                                                    Parameters.MethodParameters params,
                                                                    XmlSuite xmlSuite)
        Returns:
        An array of parameters suitable to invoke this method, possibly picked from the property file
      • canInject

        private static boolean canInject​(java.lang.String annotation)
      • checkParameterTypes

        private static void checkParameterTypes​(java.lang.String methodName,
                                                java.lang.Class<?>[] parameterTypes,
                                                java.lang.String methodAnnotation,
                                                java.lang.String[] parameterNames)
      • validParameters

        private static boolean validParameters​(java.lang.String methodAnnotation,
                                               java.lang.Class[] parameterTypes)
      • prettyFormat

        private static java.lang.String prettyFormat​(java.util.List<java.lang.Class<?>> classes)
      • convertType

        public static <T> T convertType​(java.lang.Class<T> type,
                                        java.lang.String value,
                                        java.lang.String paramName)
      • findDataProviderInfo

        private static IDataProvidable findDataProviderInfo​(ITestClass clazz,
                                                            ConstructorOrMethod m,
                                                            IAnnotationFinder finder)
        Find the data provider info (data provider name and class) on either @Test(dataProvider), @Factory(dataProvider) on a method or @Factory(dataProvider) on a constructor.
      • isDataProviderClassEmpty

        private static boolean isDataProviderClassEmpty​(ITestAnnotation annotation)
      • isDataProviderNameEmpty

        private static boolean isDataProviderNameEmpty​(ITestAnnotation annotation)
      • getDataProviderName

        private static java.lang.String getDataProviderName​(IDataProviderAnnotation dp,
                                                            java.lang.reflect.Method m)
      • handleParameters

        public static ParameterHolder handleParameters​(ITestNGMethod testMethod,
                                                       java.util.Map<java.lang.String,​java.lang.String> allParameterNames,
                                                       java.lang.Object instance,
                                                       Parameters.MethodParameters methodParams,
                                                       XmlSuite xmlSuite,
                                                       IAnnotationFinder annotationFinder,
                                                       java.lang.Object fedInstance,
                                                       DataProviderHolder holder)
        If the method has parameters, fill them in. Either by using a @DataProvider if any was provided, or by looking up <parameters> in testng.xml
        Returns:
        An Iterator over the values for each parameter of this method.
      • handleParameters

        public static ParameterHolder handleParameters​(ITestNGMethod testMethod,
                                                       java.util.Map<java.lang.String,​java.lang.String> allParameterNames,
                                                       java.lang.Object instance,
                                                       Parameters.MethodParameters methodParams,
                                                       XmlSuite xmlSuite,
                                                       IAnnotationFinder annotationFinder,
                                                       java.lang.Object fedInstance,
                                                       DataProviderHolder holder,
                                                       java.lang.String annotationName)
        If the method has parameters, fill them in. Either by using a @DataProvider if any was provided, or by looking up <parameters> in testng.xml
        Returns:
        An Iterator over the values for each parameter of this method.
      • injectParameters

        public static java.lang.Object[] injectParameters​(java.lang.Object[] parameterValues,
                                                          java.lang.reflect.Method method,
                                                          ITestContext context)
                                                   throws TestNGException
        Gets an array of parameter values returned by data provider or the ones that are injected based on parameter type. The method also checks for NoInjection annotation
        Parameters:
        parameterValues - parameter values from a data provider
        method - method to be invoked
        context - test context
        Throws:
        TestNGException
      • getParametersFromIndex

        public static java.lang.Object[] getParametersFromIndex​(java.util.Iterator<java.lang.Object[]> parametersValues,
                                                                int index)