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 StringannotationFormFor(ITestNGMethod method) Given a TestNG method, returns the corresponding annotation based on the method typestatic StringarrayToString(String[] strings) private static StringbuildStackTrace(Throwable t, boolean toHtml, Utils.StackTraceType type) static voidcheckInstanceOrStatic(Object instance, Method method) static voidcheckReturnType(Method method, Class<?>... returnTypes) static StringdefaultIfStringEmpty(String s, String defaultValue) static StringdetailedMethodName(ITestNGMethod method) static StringdetailedMethodName(ITestNGMethod method, boolean fqn) static voidstatic StringescapeHtml(String s) static String(package private) static StringfilterTrace(String trace) static intstatic booleanstatic booleanstatic booleanstatic booleanprivate static booleanstatic <T> Stringstatic voidstatic voidLogs the the message to System.out if level is greater than or equal to getVerbose().static StringlongStackTrace(Throwable t, boolean toHtml) Helper that returns a short stack trace.private static BufferedWriteropenWriter(File outputFile, String encoding) static BufferedWriteropenWriter(String outputDir, String fileNameParameter) Open a BufferedWriter for the specified file.static StringreplaceSpecialCharacters(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 voidsetVerbose(int n) static StringshortStackTrace(Throwable t, boolean toHtml) Helper that returns a long stack trace.static String[]static StringstringifyTypes(Class<?>[] parameterTypes) private static Stringstatic StringReturns the string representation of the specified object, transparently handling null references and arrays.static Stringstatic voidprivate static voidprivate static voidWrites the content of the sb string to the file named filename in outDir.static voidWrites the content of the sb string to the file named filename in outDir.static voidwriteResourceToFile(File file, String resourceName, Class<?> clasz) static voidwriteUtf8File(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 voidwriteUtf8File(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
-
m_verbose
private static int m_verbose
-
-
Constructor Details
-
Utils
private Utils()Hide constructor for utility class.
-
-
Method Details
-
getVerbose
public static int getVerbose() -
setVerbose
public static void setVerbose(int n) -
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). Ifnullthen 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). Ifnullthen 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 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- - TheThrowableexceptiontoHtml- -trueif 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- - TheThrowableexceptiontoHtml- -trueif 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
-
detailedMethodName
-
annotationFormFor
Given a TestNG method, returns the corresponding annotation based on the method type- Parameters:
method- - AnITestNGMethodobject.- 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
-
stringifyTypes
-