org.testng.internal
Class MethodHelper

java.lang.Object
  extended by org.testng.internal.MethodHelper

public class MethodHelper
extends java.lang.Object

Collection of helper methods to help sort and arrange methods.

Author:
Cedric Beust, Alexandru Popescu

Constructor Summary
MethodHelper()
           
 
Method Summary
static java.lang.String calculateMethodCanonicalName(java.lang.Class<?> methodClass, java.lang.String methodName)
           
static java.lang.String calculateMethodCanonicalName(ITestNGMethod m)
           
static ITestNGMethod[] collectAndOrderConfigurationMethods(java.util.List<ITestNGMethod> methods, RunInfo runInfo, IAnnotationFinder finder, boolean unique, java.util.List<ITestNGMethod> outExcludedMethods)
           
static ITestNGMethod[] collectAndOrderMethods(java.util.List<ITestNGMethod> methods, RunInfo runInfo, IAnnotationFinder finder, java.util.List<ITestNGMethod> outExcludedMethods)
           
static java.util.Iterator<java.lang.Object[]> createArrayIterator(java.lang.Object[][] objects)
           
static java.lang.Class<?>[] findExpectedExceptions(IAnnotationFinder finder, java.lang.reflect.Method method)
          Read the expected exceptions, if any (need to handle both the old and new syntax
static java.util.Map<java.lang.String,java.util.List<ITestNGMethod>> findGroupsMethods(java.util.Collection<ITestClass> classes, boolean before)
          Extracts the map of groups and their corresponding methods from the classes.
static void findGroupTransitiveClosure(XmlMethodSelector xms, java.util.List<ITestNGMethod> includedMethods, java.util.List<ITestNGMethod> allMethods, java.lang.String[] includedGroups, java.util.Set<java.lang.String> outGroups, java.util.Set<ITestNGMethod> outMethods)
           
static ITestNGMethod[] findMethodsNamed(java.lang.String mainMethod, ITestNGMethod[] methods, java.lang.String[] regexps)
           
static ITestNGMethod[] findMethodsThatBelongToGroup(ITestNGMethod method, ITestNGMethod[] methods, java.lang.String groupRegexp)
           
static ITestNGMethod[] findMethodsThatBelongToGroup(ITestNGMethod method, java.util.List<ITestNGMethod> methods, java.lang.String groupRegexp)
           
static java.util.List<ITestNGMethod> getMethodsDependedUpon(ITestNGMethod method, ITestNGMethod[] methods)
           
static java.util.Iterator<java.lang.Object[]> invokeDataProvider(java.lang.Object instance, java.lang.reflect.Method dataProvider, ITestNGMethod method, ITestContext testContext, java.lang.Object fedInstance, IAnnotationFinder annotationFinder)
           
static void invokeHookable(java.lang.Object instance, java.lang.Object[] parameters, ITestClass testClass, java.lang.reflect.Method thisMethod, TestResult testResult)
          Invokes the run method of the IHookable.
static java.lang.Object invokeMethod(java.lang.reflect.Method thisMethod, java.lang.Object instance, java.lang.Object[] parameters)
           
static void invokeWithTimeout(ITestNGMethod tm, java.lang.Object instance, java.lang.Object[] parameterValues, ITestResult testResult)
          Invokes a method on a separate thread in order to allow us to timeout the invocation.
static boolean isEnabled(java.lang.Class<?> objectClass, IAnnotationFinder finder)
           
static boolean isEnabled(ITestOrConfiguration test)
           
static boolean isEnabled(java.lang.reflect.Method m, IAnnotationFinder finder)
           
static void ppp(java.lang.String s)
           
static Graph<ITestNGMethod> topologicalSort(ITestNGMethod[] methods, java.util.List<ITestNGMethod> sequentialList, java.util.List<ITestNGMethod> parallelList)
           
static java.util.List<ITestNGMethod> uniqueMethodList(java.util.Collection<java.util.List<ITestNGMethod>> methods)
          Extracts the unique list of ITestNGMethods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodHelper

public MethodHelper()
Method Detail

collectAndOrderMethods

public static ITestNGMethod[] collectAndOrderMethods(java.util.List<ITestNGMethod> methods,
                                                     RunInfo runInfo,
                                                     IAnnotationFinder finder,
                                                     java.util.List<ITestNGMethod> outExcludedMethods)

collectAndOrderConfigurationMethods

public static ITestNGMethod[] collectAndOrderConfigurationMethods(java.util.List<ITestNGMethod> methods,
                                                                  RunInfo runInfo,
                                                                  IAnnotationFinder finder,
                                                                  boolean unique,
                                                                  java.util.List<ITestNGMethod> outExcludedMethods)
Parameters:
methods -
Returns:
All the methods that match the filtered groups. If a method belongs to an excluded group, it is automatically excluded.

findMethodsThatBelongToGroup

public static ITestNGMethod[] findMethodsThatBelongToGroup(ITestNGMethod method,
                                                           ITestNGMethod[] methods,
                                                           java.lang.String groupRegexp)
Returns:
all the methods that belong to the group specified by the regular expression groupRegExp. methods[] is the list of all the methods we are choosing from and method is the method that owns the dependsOnGroups statement (only used if a group is missing to flag an error on that method).

findMethodsNamed

public static ITestNGMethod[] findMethodsNamed(java.lang.String mainMethod,
                                               ITestNGMethod[] methods,
                                               java.lang.String[] regexps)

findExpectedExceptions

public static java.lang.Class<?>[] findExpectedExceptions(IAnnotationFinder finder,
                                                          java.lang.reflect.Method method)
Read the expected exceptions, if any (need to handle both the old and new syntax


isEnabled

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

isEnabled

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

isEnabled

public static boolean isEnabled(ITestOrConfiguration test)

findMethodsThatBelongToGroup

public static ITestNGMethod[] findMethodsThatBelongToGroup(ITestNGMethod method,
                                                           java.util.List<ITestNGMethod> methods,
                                                           java.lang.String groupRegexp)

findGroupTransitiveClosure

public static void findGroupTransitiveClosure(XmlMethodSelector xms,
                                              java.util.List<ITestNGMethod> includedMethods,
                                              java.util.List<ITestNGMethod> allMethods,
                                              java.lang.String[] includedGroups,
                                              java.util.Set<java.lang.String> outGroups,
                                              java.util.Set<ITestNGMethod> outMethods)

findGroupsMethods

public static java.util.Map<java.lang.String,java.util.List<ITestNGMethod>> findGroupsMethods(java.util.Collection<ITestClass> classes,
                                                                                              boolean before)
Extracts the map of groups and their corresponding methods from the classes.


uniqueMethodList

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


topologicalSort

public static Graph<ITestNGMethod> topologicalSort(ITestNGMethod[] methods,
                                                   java.util.List<ITestNGMethod> sequentialList,
                                                   java.util.List<ITestNGMethod> parallelList)

calculateMethodCanonicalName

public static java.lang.String calculateMethodCanonicalName(ITestNGMethod m)

ppp

public static void ppp(java.lang.String s)

getMethodsDependedUpon

public static java.util.List<ITestNGMethod> getMethodsDependedUpon(ITestNGMethod method,
                                                                   ITestNGMethod[] methods)
Parameters:
method -
allTestMethods -
Returns:
A sorted array containing all the methods 'method' depends on

invokeMethod

public static java.lang.Object invokeMethod(java.lang.reflect.Method thisMethod,
                                            java.lang.Object instance,
                                            java.lang.Object[] parameters)
                                     throws java.lang.reflect.InvocationTargetException,
                                            java.lang.IllegalAccessException
Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

createArrayIterator

public static java.util.Iterator<java.lang.Object[]> createArrayIterator(java.lang.Object[][] objects)

invokeDataProvider

public static java.util.Iterator<java.lang.Object[]> invokeDataProvider(java.lang.Object instance,
                                                                        java.lang.reflect.Method dataProvider,
                                                                        ITestNGMethod method,
                                                                        ITestContext testContext,
                                                                        java.lang.Object fedInstance,
                                                                        IAnnotationFinder annotationFinder)

calculateMethodCanonicalName

public static java.lang.String calculateMethodCanonicalName(java.lang.Class<?> methodClass,
                                                            java.lang.String methodName)

invokeHookable

public static void invokeHookable(java.lang.Object instance,
                                  java.lang.Object[] parameters,
                                  ITestClass testClass,
                                  java.lang.reflect.Method thisMethod,
                                  TestResult testResult)
                           throws java.lang.NoSuchMethodException,
                                  java.lang.IllegalAccessException,
                                  java.lang.reflect.InvocationTargetException,
                                  java.lang.Throwable
Invokes the run method of the IHookable.

Parameters:
instance - the instance to invoke the method in
parameters - the parameters to be passed to IHookCallBack
testClass - the test class
thisMethod - the method to be invoked through the IHookCallBack
testResult - the current ITestResult passed to IHookable.run
Throws:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.Throwable - thrown if the reflective call to thisMethod results in an exception

invokeWithTimeout

public static void invokeWithTimeout(ITestNGMethod tm,
                                     java.lang.Object instance,
                                     java.lang.Object[] parameterValues,
                                     ITestResult testResult)
                              throws java.lang.InterruptedException,
                                     ThreadExecutionException
Invokes a method on a separate thread in order to allow us to timeout the invocation. It uses as implementation an Executor and a CountDownLatch.

Parameters:
tm - the
instance -
parameterValues -
testResult -
Throws:
java.lang.InterruptedException
ThreadExecutionException


Copyright © 2010. All Rights Reserved.