Class ClassHelper


  • public final class ClassHelper
    extends java.lang.Object
    Utility class for different class manipulations.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addClassLoader​(java.lang.ClassLoader loader)
      Add a class loader to the searchable loaders.
      static java.lang.Object createInstance​(java.lang.Class<?> declaringClass, java.util.Map<java.lang.Class<?>,​IClass> classes, XmlTest xmlTest, IAnnotationFinder finder, ITestObjectFactory objectFactory, boolean create)
      Deprecated.
      - This method is deprecated as of TestNG 7.0.0
      static java.lang.Object createInstance1​(java.lang.Class<?> declaringClass, java.util.Map<java.lang.Class<?>,​IClass> classes, XmlTest xmlTest, IAnnotationFinder finder, IObjectFactory factory, boolean create)
      Deprecated.
      - This method is deprecated as of TestNG 7.0.0
      static IMethodSelector createSelector​(XmlMethodSelector selector)
      Deprecated.
      - This method is deprecated as of TestNG 7.0.0
      static IJUnitTestRunner createTestRunner​(TestRunner runner)
      Deprecated.
      - This method is deprecated as of TestNG 7.0.0
      static java.lang.Class<?> fileToClass​(java.lang.String file)
      Returns the Class object corresponding to the given name.
      static XmlClass[] findClassesInSameTest​(java.lang.Class<?> cls, XmlSuite suite)  
      static java.util.List<ConstructorOrMethod> findDeclaredFactoryMethods​(java.lang.Class<?> cls, IAnnotationFinder finder)
      For the given class, returns the method annotated with @Factory or null if none is found.
      static java.lang.Class<?> forName​(java.lang.String className)
      Tries to load the specified class using the context ClassLoader or if none, than from the default ClassLoader.
      static java.util.Set<java.lang.reflect.Method> getAvailableMethods​(java.lang.Class<?> clazz)
      Extract all callable methods of a class and all its super (keeping in mind the Java access rules).
      static <T> T newInstance​(java.lang.Class<T> clazz)
      Deprecated.
      - This method is deprecated as of TestNG 7.0.0
      static <T> T newInstance​(java.lang.reflect.Constructor<T> constructor, java.lang.Object... parameters)
      Deprecated.
      - This method is deprecated as of TestNG 7.0.0
      static <T> T newInstanceOrNull​(java.lang.Class<T> clazz)
      Deprecated.
      - This method is deprecated as of TestNG 7.0.0
      static <T> T tryOtherConstructor​(java.lang.Class<T> declaringClass)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addClassLoader

        public static void addClassLoader​(java.lang.ClassLoader loader)
        Add a class loader to the searchable loaders.
      • newInstance

        @Deprecated
        public static <T> T newInstance​(java.lang.Class<T> clazz)
        Deprecated.
        - This method is deprecated as of TestNG 7.0.0
      • newInstanceOrNull

        @Deprecated
        public static <T> T newInstanceOrNull​(java.lang.Class<T> clazz)
        Deprecated.
        - This method is deprecated as of TestNG 7.0.0
      • newInstance

        @Deprecated
        public static <T> T newInstance​(java.lang.reflect.Constructor<T> constructor,
                                        java.lang.Object... parameters)
        Deprecated.
        - This method is deprecated as of TestNG 7.0.0
      • forName

        public static java.lang.Class<?> forName​(java.lang.String className)
        Tries to load the specified class using the context ClassLoader or if none, than from the default ClassLoader. This method differs from the standard class loading methods in that it does not throw an exception if the class is not found but returns null instead.
        Parameters:
        className - the class name to be loaded.
        Returns:
        the class or null if the class is not found.
      • findDeclaredFactoryMethods

        public static java.util.List<ConstructorOrMethod> findDeclaredFactoryMethods​(java.lang.Class<?> cls,
                                                                                     IAnnotationFinder finder)
        For the given class, returns the method annotated with @Factory or null if none is found. This method does not search up the superclass hierarchy. If more than one method is @Factory annotated, a TestNGException is thrown.
        Parameters:
        cls - The class to search for the @Factory annotation.
        finder - The finder (JDK 1.4 or JDK 5.0+) use to search for the annotation.
        Returns:
        the @Factory methods
      • getAvailableMethods

        public static java.util.Set<java.lang.reflect.Method> getAvailableMethods​(java.lang.Class<?> clazz)
        Extract all callable methods of a class and all its super (keeping in mind the Java access rules).
      • createTestRunner

        @Deprecated
        public static IJUnitTestRunner createTestRunner​(TestRunner runner)
        Deprecated.
        - This method is deprecated as of TestNG 7.0.0
      • createSelector

        @Deprecated
        public static IMethodSelector createSelector​(XmlMethodSelector selector)
        Deprecated.
        - This method is deprecated as of TestNG 7.0.0
      • createInstance

        @Deprecated
        public static java.lang.Object createInstance​(java.lang.Class<?> declaringClass,
                                                      java.util.Map<java.lang.Class<?>,​IClass> classes,
                                                      XmlTest xmlTest,
                                                      IAnnotationFinder finder,
                                                      ITestObjectFactory objectFactory,
                                                      boolean create)
        Deprecated.
        - This method is deprecated as of TestNG 7.0.0
        Create an instance for the given class.
      • createInstance1

        @Deprecated
        public static java.lang.Object createInstance1​(java.lang.Class<?> declaringClass,
                                                       java.util.Map<java.lang.Class<?>,​IClass> classes,
                                                       XmlTest xmlTest,
                                                       IAnnotationFinder finder,
                                                       IObjectFactory factory,
                                                       boolean create)
        Deprecated.
        - This method is deprecated as of TestNG 7.0.0
      • tryOtherConstructor

        public static <T> T tryOtherConstructor​(java.lang.Class<T> declaringClass)
      • fileToClass

        public static java.lang.Class<?> fileToClass​(java.lang.String file)
        Returns the Class object corresponding to the given name. The name may be of the following form:
        • A class name: "org.testng.TestNG"
        • A class file name: "/testng/src/org/testng/TestNG.class"
        • A class source name: "d:\testng\src\org\testng\TestNG.java"
        Parameters:
        file - the class name.
        Returns:
        the class corresponding to the name specified.
      • findClassesInSameTest

        public static XmlClass[] findClassesInSameTest​(java.lang.Class<?> cls,
                                                       XmlSuite suite)
        Parameters:
        cls - - The class to look for.
        suite - - The XmlSuite whose <test> tags needs to be searched in.
        Returns:
        - All the XmlClass objects that share the same <test> tag as the class.