Class MethodHelper


  • public class MethodHelper
    extends java.lang.Object
    Collection of helper methods to help sort and arrange methods.
    • Field Detail

      • CANONICAL_NAME_CACHE

        private static final java.util.Map<java.lang.reflect.Method,​java.lang.String> CANONICAL_NAME_CACHE
      • MATCH_CACHE

        private static final java.util.Map<Pair<java.lang.String,​java.lang.String>,​java.lang.Boolean> MATCH_CACHE
    • Constructor Detail

      • MethodHelper

        public MethodHelper()
    • Method Detail

      • collectAndOrderMethods

        public static ITestNGMethod[] collectAndOrderMethods​(java.util.List<ITestNGMethod> methods,
                                                             boolean forTests,
                                                             RunInfo runInfo,
                                                             IAnnotationFinder finder,
                                                             boolean unique,
                                                             java.util.List<ITestNGMethod> outExcludedMethods,
                                                             java.util.Comparator<ITestNGMethod> comparator)
        Collects and orders test or configuration methods
        Parameters:
        methods - methods to be worked on
        forTests - true for test methods, false for configuration methods
        runInfo - - RunInfo object.
        finder - annotation finder
        unique - true for unique methods, false otherwise
        outExcludedMethods - - A List of excluded ITestNGMethod methods.
        Returns:
        list of ordered methods
      • findDependedUponMethods

        protected static ITestNGMethod[] findDependedUponMethods​(ITestNGMethod m,
                                                                 java.util.List<ITestNGMethod> methods)
        Finds TestNG methods that the specified TestNG method depends upon
        Parameters:
        m - TestNG method
        methods - list of methods to search for depended upon methods
        Returns:
        list of methods that match the criteria
      • findDependedUponMethods

        public static ITestNGMethod[] findDependedUponMethods​(ITestNGMethod m,
                                                              ITestNGMethod[] methods)
        Finds TestNG methods that the specified TestNG method depends upon
        Parameters:
        m - TestNG method
        methods - list of methods to search for depended upon methods
        Returns:
        list of methods that match the criteria
      • findMethodByName

        private static java.lang.reflect.Method findMethodByName​(ITestNGMethod testngMethod,
                                                                 java.lang.String regExp)
        Finds method based on regex and TestNGMethod. If regex doesn't represent the class name, uses the TestNG method's class name.
        Parameters:
        testngMethod - TestNG method
        regExp - regex representing a method and/or related class name
      • isEnabled

        public static boolean isEnabled​(java.lang.Class<?> objectClass,
                                        IAnnotationFinder finder)
      • isEnabled

        public static boolean isEnabled​(java.lang.reflect.Method m,
                                        IAnnotationFinder finder)
      • uniqueMethodList

        public static java.util.List<ITestNGMethod> uniqueMethodList​(java.util.Collection<java.util.List<ITestNGMethod>> methods)
        Extracts the unique list of ITestNGMethods.
      • sortMethodsByInstance

        private static java.util.Map<java.lang.Object,​java.util.List<ITestNGMethod>> sortMethodsByInstance​(ITestNGMethod[] methods)
        This method is used to create a map of test instances and their associated method(s) . Used to decrease the scope to only a methods instance when trying to find method dependencies.
        Parameters:
        methods - Methods to be sorted
        Returns:
        Map of Instances as the keys and the methods associated with the instance as the values
      • calculateMethodCanonicalName

        protected static java.lang.String calculateMethodCanonicalName​(ITestNGMethod m)
      • calculateMethodCanonicalName

        private static java.lang.String calculateMethodCanonicalName​(java.lang.reflect.Method m)
      • getMethodsDependedUpon

        public static java.util.List<ITestNGMethod> getMethodsDependedUpon​(ITestNGMethod method,
                                                                           ITestNGMethod[] methods,
                                                                           java.util.Comparator<ITestNGMethod> comparator)
        Returns:
        A sorted array containing all the methods 'method' depends on
      • methodInstancesToMethods

        public static java.util.List<ITestNGMethod> methodInstancesToMethods​(java.util.List<IMethodInstance> methodInstances)
      • dumpInvokedMethodInfoToConsole

        public static void dumpInvokedMethodInfoToConsole​(ITestNGMethod[] methods,
                                                          int currentVerbosity)
      • isConfigurationMethod

        private static boolean isConfigurationMethod​(ITestNGMethod tm)
      • calculateMethodCanonicalName

        protected static java.lang.String calculateMethodCanonicalName​(java.lang.Class<?> methodClass,
                                                                       java.lang.String methodName)
      • clear

        public static void clear​(java.util.stream.Stream<java.lang.reflect.Method> methods)
      • calculateTimeOut

        public static long calculateTimeOut​(ITestNGMethod tm)