org.testng.internal
Class Utils

java.lang.Object
  extended by org.testng.internal.Utils

public final class Utils
extends java.lang.Object

Helper methods to parse annotations.

Author:
Cedric Beust, Apr 26, 2004, Alexandru Popescu

Method Summary
static java.lang.String arrayToString(java.lang.String[] strings)
           
static int calculateInvokedMethodCount(ITestNGMethod[] methods)
           
static XmlClass[] classesToXmlClasses(java.lang.Class<?>[] classes)
           
static java.lang.String[] dependentGroupsForThisMethodForConfiguration(java.lang.reflect.Method m, IAnnotationFinder finder)
           
static java.lang.String[] dependentGroupsForThisMethodForTest(java.lang.reflect.Method m, IAnnotationFinder finder)
           
static java.lang.String detailedMethodName(ITestNGMethod method, boolean fqn)
           
static void dumpMap(java.util.Map<?,?> result)
           
static void dumpMethods(java.util.List<ITestNGMethod> allMethods)
           
static void error(java.lang.String errorMessage)
           
static java.lang.String[] groupsForThisMethodForConfiguration(java.lang.reflect.Method m, IAnnotationFinder finder)
           
static java.lang.String[] groupsForThisMethodForTest(java.lang.reflect.Method m, IAnnotationFinder finder)
           
static void initLogger(java.util.logging.Logger logger, java.lang.String outputLogPath)
           
static boolean isStringEmpty(java.lang.String s)
           
static void log(java.lang.String msg)
           
static void log(java.lang.String cls, int level, java.lang.String msg)
          Logs the the message to System.out if level is greater than or equal to TestRunner.getVerbose().
static void logInvocation(java.lang.String reason, java.lang.reflect.Method thisMethod, java.lang.Object[] parameters)
           
static java.lang.String[] parseMultiLine(java.lang.String line)
           
static java.lang.String[] split(java.lang.String string, java.lang.String sep)
          Tokenize the string using the separator.
static java.lang.String[] stackTrace(java.lang.Throwable t, boolean tohtml)
           
static java.lang.String[] stringToArray(java.lang.String s)
          Splits the given String s into tokens where the separator is either the space character or the comma character.
static java.lang.String toString(java.lang.Object object, java.lang.Class<?> objectClass)
           
static void writeFile(java.lang.String outputDir, java.lang.String fileName, java.lang.String sb)
          Writes the content of the sb string to the file named filename in outDir.
static void writeResourceToFile(java.io.File file, java.lang.String resourceName, java.lang.Class<?> clasz)
           
static void writeUtf8File(java.lang.String outputDir, java.lang.String fileName, java.lang.String sb)
          Writes the content of the sb string to the file named filename in outDir encoding the output as UTF-8.
static java.lang.Class<?>[] xmlClassesToClasses(java.util.List<XmlClass> classes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

stringToArray

public static java.lang.String[] stringToArray(java.lang.String s)
Splits the given String s into tokens where the separator is either the space character or the comma character. For example, if s is "a,b, c" this method returns {"a", "b", "c"}

Parameters:
s - the string to split
Returns:
the split token

xmlClassesToClasses

public static java.lang.Class<?>[] xmlClassesToClasses(java.util.List<XmlClass> classes)

classesToXmlClasses

public static XmlClass[] classesToXmlClasses(java.lang.Class<?>[] classes)

parseMultiLine

public static java.lang.String[] parseMultiLine(java.lang.String line)

writeUtf8File

public static void writeUtf8File(java.lang.String outputDir,
                                 java.lang.String fileName,
                                 java.lang.String sb)
Writes the content of the sb string to the file named filename in outDir encoding the output as UTF-8. If outDir does not exist, it is created.

Parameters:
outputDir - the output directory (may not exist). If null then current directory is used.
fileName - the filename
sb - the file content

writeFile

public static void writeFile(java.lang.String outputDir,
                             java.lang.String fileName,
                             java.lang.String sb)
Writes the content of the sb string to the file named filename in outDir. If outDir does not exist, it is created.

Parameters:
outputDir - the output directory (may not exist). If null then current directory is used.
fileName - the filename
sb - the file content

dumpMap

public static void dumpMap(java.util.Map<?,?> result)
Parameters:
result -

dumpMethods

public static void dumpMethods(java.util.List<ITestNGMethod> allMethods)
Parameters:
allMethods -

dependentGroupsForThisMethodForTest

public static java.lang.String[] dependentGroupsForThisMethodForTest(java.lang.reflect.Method m,
                                                                     IAnnotationFinder finder)
Returns:
The list of dependent groups for this method, including the class groups

groupsForThisMethodForTest

public static java.lang.String[] groupsForThisMethodForTest(java.lang.reflect.Method m,
                                                            IAnnotationFinder finder)
Returns:
The list of groups this method belongs to, including the class groups

groupsForThisMethodForConfiguration

public static java.lang.String[] groupsForThisMethodForConfiguration(java.lang.reflect.Method m,
                                                                     IAnnotationFinder finder)
Returns:
The list of groups this method belongs to, including the class groups

dependentGroupsForThisMethodForConfiguration

public static java.lang.String[] dependentGroupsForThisMethodForConfiguration(java.lang.reflect.Method m,
                                                                              IAnnotationFinder finder)
Returns:
The list of groups this method depends on, including the class groups

log

public static void log(java.lang.String msg)

log

public static void log(java.lang.String cls,
                       int level,
                       java.lang.String msg)
Logs the the message to System.out if level is greater than or equal to TestRunner.getVerbose(). The message is logged as:
     "[cls] msg"
 

Parameters:
cls - the class name to prefix the log message.
level - the logging level of the message.
msg - the message to log to System.out.

error

public static void error(java.lang.String errorMessage)

calculateInvokedMethodCount

public static int calculateInvokedMethodCount(ITestNGMethod[] methods)
Returns:
The number of methods invoked, taking into account the number of instances.

split

public static java.lang.String[] split(java.lang.String string,
                                       java.lang.String sep)
Tokenize the string using the separator.


initLogger

public static void initLogger(java.util.logging.Logger logger,
                              java.lang.String outputLogPath)

logInvocation

public static void logInvocation(java.lang.String reason,
                                 java.lang.reflect.Method thisMethod,
                                 java.lang.Object[] parameters)

writeResourceToFile

public static void writeResourceToFile(java.io.File file,
                                       java.lang.String resourceName,
                                       java.lang.Class<?> clasz)
                                throws java.io.IOException
Throws:
java.io.IOException

isStringEmpty

public static boolean isStringEmpty(java.lang.String s)

stackTrace

public static java.lang.String[] stackTrace(java.lang.Throwable t,
                                            boolean tohtml)

toString

public static java.lang.String toString(java.lang.Object object,
                                        java.lang.Class<?> objectClass)
Parameters:
object -
Returns:

detailedMethodName

public static java.lang.String detailedMethodName(ITestNGMethod method,
                                                  boolean fqn)
Parameters:
method -
Returns:

arrayToString

public static java.lang.String arrayToString(java.lang.String[] strings)


Copyright © 2010. All Rights Reserved.