Class ClassHelper

java.lang.Object
org.testng.internal.ClassHelper

public final class ClassHelper extends Object
Utility class for different class manipulations.
  • Field Details

    • classLoaders

      private static final List<ClassLoader> classLoaders
      The additional class loaders to find classes in.
    • CLASS_HELPER

      private static final String CLASS_HELPER
    • lastGoodRootIndex

      private static int lastGoodRootIndex
      When given a file name to form a class name, the file name is parsed and divided into segments. For example, "c:/java/classes/com/foo/A.class" would be divided into 6 segments {"C:" "java", "classes", "com", "foo", "A"}. The first segment actually making up the class name is [3]. This value is saved in lastGoodRootIndex so that when we parse the next file name, we will try 3 right away. If 3 fails we will take the long approach. This is just a optimization cache value.
  • Constructor Details

    • ClassHelper

      private ClassHelper()
      Hide constructor.
  • Method Details

    • addClassLoader

      public static void addClassLoader(ClassLoader loader)
    • appendContextualClassLoaders

      static List<ClassLoader> appendContextualClassLoaders(List<ClassLoader> currentLoaders)
    • forName

      public static Class<?> forName(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.
    • logClassNotFoundError

      private static void logClassNotFoundError(String className, Throwable ex)
    • findDeclaredFactoryMethods

      public static List<ConstructorOrMethod> findDeclaredFactoryMethods(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
    • getAvailableMethodsExcludingDefaults

      public static Set<Method> getAvailableMethodsExcludingDefaults(Class<?> clazz)
      Parameters:
      clazz - - The Class in which the search is to be done.
      Returns:
      - A Set of Method excluding default methods from base class interfaces.
    • getAvailableMethods

      public static Set<Method> getAvailableMethods(Class<?> clazz)
    • appendMethod

      private static void appendMethod(Map<String,Set<Method>> methods, Method declaredMethod)
    • extractMethods

      private static Map<String,Set<Method>> extractMethods(Class<?> childClass, Class<?> clazz, Map<String,Set<Method>> collected)
    • canInclude

      private static boolean canInclude(boolean isSamePackage, Method method, Map<String,Set<Method>> collected)
    • isSamePackage

      private static boolean isSamePackage(Package childPackage, Package classPackage)
    • isOverridden

      private static boolean isOverridden(Method method, Map<String,Set<Method>> methodsByName)
    • findAnnotatedConstructor

      static Constructor<?> findAnnotatedConstructor(IAnnotationFinder finder, Class<?> declaringClass)
      Find the best constructor given the parameters found on the annotation
    • tryOtherConstructor

      public static <T> T tryOtherConstructor(Class<T> declaringClass)
    • fileToClass

      public static Class<?> fileToClass(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(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.
    • findClassesInSameTest

      private static Collection<XmlClass> findClassesInSameTest(Class<?> cls, XmlTest xmlTest)