public final class Utils extends Object
| Modifier and Type | Field and Description |
|---|---|
static char |
CHAR_REPLACEMENT |
static char |
UNICODE_REPLACEMENT |
| Modifier and Type | Method and Description |
|---|---|
static String |
annotationFormFor(ITestNGMethod method)
Given a TestNG method, returns the corresponding annotation based on the method type
|
static String |
arrayToString(String[] strings) |
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 |
error(String errorMessage) |
static String |
escapeHtml(String s) |
static String |
escapeUnicode(String s) |
static int |
getVerbose() |
static boolean |
isStringBlank(String s) |
static boolean |
isStringEmpty(String s) |
static boolean |
isStringNotBlank(String s) |
static boolean |
isStringNotEmpty(String s) |
static <T> String |
join(List<T> objects,
String separator) |
static void |
log(String msg) |
static void |
log(String cls,
int level,
String msg)
Logs the the message to System.out if level is greater than or equal to getVerbose().
|
static String |
longStackTrace(Throwable t,
boolean toHtml)
Helper that returns a short stack trace.
|
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 void |
setVerbose(int n) |
static String |
shortStackTrace(Throwable t,
boolean toHtml)
Helper that returns a long stack trace.
|
static String[] |
split(String string,
String sep) |
static String |
stringifyTypes(Class<?>[] parameterTypes) |
static String |
toString(Object obj)
Returns the string representation of the specified object, transparently handling null
references and arrays.
|
static String |
toString(Object object,
Class<?> objectClass) |
static void |
warn(String warnMsg) |
static void |
writeFile(String outputDir,
String fileName,
String sb)
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) |
public static final char CHAR_REPLACEMENT
public static final char UNICODE_REPLACEMENT
public static int getVerbose()
public static void setVerbose(int n)
public static void writeUtf8File(@Nullable String outputDir, String fileName, XMLStringBuffer xsb, String prefix)
public static void writeUtf8File(@Nullable String outputDir, String fileName, String sb)
outputDir - the output directory (may not exist). If null then current
directory is used.fileName - the filenamesb - the file contentpublic static void writeFile(@Nullable String outputDir, String fileName, String sb)
outputDir - the output directory (may not exist). If null then current
directory is used.fileName - the filenamesb - the file contentpublic static BufferedWriter openWriter(@Nullable String outputDir, String fileNameParameter) throws IOException
outputDir - output directory. If null, then current directory is usedfileNameParameter - file nameIOException - if anything goes wrong while creating files.public static void log(String msg)
public static void log(String cls, int level, String msg)
"[cls] msg"
cls - the class name to prefix the log message.level - the logging level of the message.msg - the message to log to System.out.public static void error(String errorMessage)
public static void warn(String warnMsg)
public static void writeResourceToFile(File file, String resourceName, Class<?> clasz) throws IOException
IOExceptionpublic static boolean isStringBlank(String s)
public static boolean isStringEmpty(String s)
public static boolean isStringNotBlank(String s)
public static boolean isStringNotEmpty(String s)
public static String longStackTrace(Throwable t, boolean toHtml)
t - - The Throwable exceptiontoHtml - - true if the stacktrace should be translated to html as wellpublic static String shortStackTrace(Throwable t, boolean toHtml)
t - - The Throwable exceptiontoHtml - - true if the stacktrace should be translated to html as wellpublic static String detailedMethodName(ITestNGMethod method, boolean fqn)
public static String annotationFormFor(ITestNGMethod method)
method - - An ITestNGMethod object.public static String replaceSpecialCharacters(String fileNameParameter)
fileNameParameter - file name that could contain special characters.public static String toString(Object obj)
obj - the objectCopyright © 2025. All rights reserved.