Package org.testng.internal
Class MethodInheritance
java.lang.Object
org.testng.internal.MethodInheritance
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Comparator<ITestNGMethod>
A Custom comparator that helps inITestNGMethod
ordering keeping in mind the class hierarchy. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
dependencyExists
(ITestNGMethod m1, ITestNGMethod m2, ITestNGMethod[] methods) private static boolean
private static List<ITestNGMethod>
findMethodListSuperClass
(Map<Class<?>, List<ITestNGMethod>> map, Class<? extends ITestNGMethod> methodClass) Look in map for a class that is a superclass of methodClassprivate static Class<?>
findSubClass
(Map<Class<?>, List<ITestNGMethod>> map, Class<? extends ITestNGMethod> methodClass) Look in map for a class that is a subclass of methodClassstatic void
fixMethodInheritance
(ITestNGMethod[] methods, boolean before) Fix the methodsDependedUpon to make sure that @Configuration methods respect inheritance (before methods are invoked in the order Base first and after methods are invoked in the order Child first)private static boolean
internalDependencyExists
(ITestNGMethod m1, ITestNGMethod m2, ITestNGMethod[] methods) private static void
sortMethodsByInheritance
(List<ITestNGMethod> methods, boolean baseClassToChild) Given a list of methods belonging to the same class hierarchy, orders them from the base class to the child (if true) or from child to base class (if false)
-
Field Details
-
COMPARATOR
A Custom comparator that helps inITestNGMethod
ordering keeping in mind the class hierarchy. Here's how the comparator works:
Lets say we have two method objects o1 and o2.
o1 is associated with MyClass and o2 is associated with AnotherClass.- -1 is returned if MyClass is the parent of AnotherClass
- 1 is returned if AnotherClass is the parent of MyClass
- 0 is returned otherwise if MyClass and AnotherClass are the same i.e., both methods belong to the same class.
Lets say we have :
- interface Oven
- Microwave implements Oven
- microwave instanceof Oven : returns true
- Oven.class.isAssignableFrom(microwave.getClass()) : returns true
-
-
Constructor Details
-
MethodInheritance
public MethodInheritance()
-
-
Method Details
-
findMethodListSuperClass
private static List<ITestNGMethod> findMethodListSuperClass(Map<Class<?>, List<ITestNGMethod>> map, Class<? extends ITestNGMethod> methodClass) Look in map for a class that is a superclass of methodClass -
findSubClass
private static Class<?> findSubClass(Map<Class<?>, List<ITestNGMethod>> map, Class<? extends ITestNGMethod> methodClass) Look in map for a class that is a subclass of methodClass -
fixMethodInheritance
Fix the methodsDependedUpon to make sure that @Configuration methods respect inheritance (before methods are invoked in the order Base first and after methods are invoked in the order Child first)- Parameters:
methods
- the list of methodsbefore
- true if we are handling a before method (meaning, the methods need to be sorted base class first and subclass last). false otherwise (subclass methods first, base classes last).
-
dependencyExists
private static boolean dependencyExists(ITestNGMethod m1, ITestNGMethod m2, ITestNGMethod[] methods) -
internalDependencyExists
private static boolean internalDependencyExists(ITestNGMethod m1, ITestNGMethod m2, ITestNGMethod[] methods) -
equalsEffectiveClass
-
sortMethodsByInheritance
Given a list of methods belonging to the same class hierarchy, orders them from the base class to the child (if true) or from child to base class (if false)
-