Class MethodInheritance


  • public class MethodInheritance
    extends java.lang.Object
    • Field Detail

      • COMPARATOR

        private static final java.util.Comparator<ITestNGMethod> COMPARATOR
        A Custom comparator that helps in ITestNGMethod 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.
        Working of isAssignableFrom
        Lets say we have :
        1. interface Oven
        2. Microwave implements Oven
        1. microwave instanceof Oven : returns true
        2. Oven.class.isAssignableFrom(microwave.getClass()) : returns true
    • Constructor Detail

      • MethodInheritance

        public MethodInheritance()
    • Method Detail

      • findMethodListSuperClass

        private static java.util.List<ITestNGMethod> findMethodListSuperClass​(java.util.Map<java.lang.Class,​java.util.List<ITestNGMethod>> map,
                                                                              java.lang.Class<? extends ITestNGMethod> methodClass)
        Look in map for a class that is a superclass of methodClass
      • findSubClass

        private static java.lang.Class findSubClass​(java.util.Map<java.lang.Class,​java.util.List<ITestNGMethod>> map,
                                                    java.lang.Class<? extends ITestNGMethod> methodClass)
        Look in map for a class that is a subclass of methodClass
      • fixMethodInheritance

        public static 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)
        Parameters:
        methods - the list of methods
        before - 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).
      • sortMethodsByInheritance

        private static void sortMethodsByInheritance​(java.util.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)