Package org.testng.internal
Class ClassHelper
java.lang.Object
org.testng.internal.ClassHelper
Utility class for different class manipulations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addClassLoader
(ClassLoader loader) static Class<?>
fileToClass
(String file) Returns the Class object corresponding to the given name.static XmlClass[]
findClassesInSameTest
(Class<?> cls, XmlSuite suite) static List<ConstructorOrMethod>
findDeclaredFactoryMethods
(Class<?> cls, IAnnotationFinder finder) For the given class, returns the method annotated with @Factory or null if none is found.static Class<?>
Tries to load the specified class using the context ClassLoader or if none, than from the default ClassLoader.getAvailableMethods
(Class<?> clazz) getAvailableMethodsExcludingDefaults
(Class<?> clazz) static <T> T
tryOtherConstructor
(Class<T> declaringClass)
-
Method Details
-
addClassLoader
-
forName
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 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
-
getAvailableMethods
-
tryOtherConstructor
-
fileToClass
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
-