Package org.testng.internal
Class Utils
java.lang.Object
org.testng.internal.Utils
Helper methods to parse annotations.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
annotationFormFor
(ITestNGMethod method) Given a TestNG method, returns the corresponding annotation based on the method typestatic String
arrayToString
(String[] strings) private static String
buildStackTrace
(Throwable t, boolean toHtml, Utils.StackTraceType type) static void
checkInstanceOrStatic
(Object instance, Method method) static void
checkReturnType
(Method method, Class<?>... returnTypes) static String
defaultIfStringEmpty
(String s, String defaultValue) static String
detailedMethodName
(ITestNGMethod method, boolean fqn) static void
static String
escapeHtml
(String s) static String
static Class<?>[]
extractParameterTypes
(Object[] objects) (package private) static String
filterTrace
(String trace) static boolean
static boolean
static boolean
static boolean
private static boolean
static <T> String
static void
static void
Logs the the message to System.out if level is greater than or equal to TestRunner.getVerbose().static String
longStackTrace
(Throwable t, boolean toHtml) Helper that returns a short stack trace.private static BufferedWriter
openWriter
(File outputFile, String encoding) static BufferedWriter
openWriter
(String outputDir, String fileNameParameter) Open a BufferedWriter for the specified file.static String
replaceSpecialCharacters
(String fileNameParameter) If the file name contains special characters like *,/,\ and so on, exception will be thrown and report file will not be created.
Special characters are platform specific and they are not same for example on Windows and Macintosh.static String
shortStackTrace
(Throwable t, boolean toHtml) Helper that returns a long stack trace.static String[]
static String
stringifyTypes
(Class<?>[] parameterTypes) private static String
static String
Returns the string representation of the specified object, transparently handling null references and arrays.static String
static void
private static void
private static void
Writes the content of the sb string to the file named filename in outDir.static void
Writes the content of the sb string to the file named filename in outDir.static void
writeResourceToFile
(File file, String resourceName, Class<?> clasz) static void
writeUtf8File
(String outputDir, String fileName, String sb) Writes the content of the sb string to the file named filename in outDir encoding the output as UTF-8.static void
writeUtf8File
(String outputDir, String fileName, XMLStringBuffer xsb, String prefix)
-
Field Details
-
LINE_SEP
-
SPECIAL_CHARACTERS
private static final char[] SPECIAL_CHARACTERS -
CHAR_REPLACEMENT
public static final char CHAR_REPLACEMENT- See Also:
-
UNICODE_REPLACEMENT
public static final char UNICODE_REPLACEMENT- See Also:
-
FORMAT
-
LOG
-
ESCAPES
-
-
Constructor Details
-
Utils
private Utils()Hide constructor for utility class.
-
-
Method Details
-
writeUtf8File
public static void writeUtf8File(@Nullable String outputDir, String fileName, XMLStringBuffer xsb, String prefix) -
writeUtf8File
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). Ifnull
then current directory is used.fileName
- the filenamesb
- the file content
-
writeFile
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). Ifnull
then current directory is used.fileName
- the filenamesb
- the file content
-
writeFile
private static void writeFile(@Nullable File outputFolder, String fileNameParameter, String sb, @Nullable String encoding) Writes the content of the sb string to the file named filename in outDir. If outDir does not exist, it is created.- Parameters:
outputFolder
- the output directory (may not exist). If null then current directory is used.fileNameParameter
- the filenamesb
- the file content
-
writeFile
-
openWriter
public static BufferedWriter openWriter(@Nullable String outputDir, String fileNameParameter) throws IOException Open a BufferedWriter for the specified file. If output directory doesn't exist, it is created. If the output file exists, it is deleted. The output file is created in any case.- Parameters:
outputDir
- output directory. Ifnull
, then current directory is usedfileNameParameter
- file name- Throws:
IOException
- if anything goes wrong while creating files.
-
openWriter
private static BufferedWriter openWriter(File outputFile, @Nullable String encoding) throws IOException - Throws:
IOException
-
log
-
log
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
-
warn
-
split
-
writeResourceToFile
public static void writeResourceToFile(File file, String resourceName, Class<?> clasz) throws IOException - Throws:
IOException
-
defaultIfStringEmpty
-
isStringBlank
-
isStringEmpty
-
isStringNotBlank
-
isStringNotEmpty
-
longStackTrace
Helper that returns a short stack trace.- Parameters:
t
- - TheThrowable
exceptiontoHtml
- -true
if the stacktrace should be translated to html as well- Returns:
- - A string that represents the short stack trace.
-
shortStackTrace
Helper that returns a long stack trace.- Parameters:
t
- - TheThrowable
exceptiontoHtml
- -true
if the stacktrace should be translated to html as well- Returns:
- - A string that represents the full stack trace.
-
buildStackTrace
-
isTooVerbose
private static boolean isTooVerbose() -
escapeHtml
-
escapeUnicode
-
filterTrace
-
toString
-
detailedMethodName
-
annotationFormFor
Given a TestNG method, returns the corresponding annotation based on the method type- Parameters:
method
- - AnITestNGMethod
object.- Returns:
- - A String representation of the corresponding annotation.
-
arrayToString
-
replaceSpecialCharacters
If the file name contains special characters like *,/,\ and so on, exception will be thrown and report file will not be created.
Special characters are platform specific and they are not same for example on Windows and Macintosh. * is not allowed on Windows, but it is on Macintosh.
In order to have the same behavior of testng on the all platforms, characters like * will be replaced on all platforms whether they are causing the problem or not.- Parameters:
fileNameParameter
- file name that could contain special characters.- Returns:
- fileName with special characters replaced
-
join
-
checkInstanceOrStatic
-
checkReturnType
-
toString
-
toString
Returns the string representation of the specified object, transparently handling null references and arrays.- Parameters:
obj
- the object- Returns:
- the string representation
-
extractParameterTypes
-
stringifyTypes
-