public final class Utils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
CHAR_REPLACEMENT |
private static java.util.Map<java.lang.Character,java.lang.String> |
ESCAPES |
private static java.lang.String |
LINE_SEP |
static char[] |
SPECIAL_CHARACTERS |
static char |
UNICODE_REPLACEMENT |
Modifier | Constructor and Description |
---|---|
private |
Utils()
Hide constructor for utility class.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
arrayToString(java.lang.String[] strings) |
static int |
calculateInvokedMethodCount(ITestNGMethod[] methods) |
static void |
checkInstanceOrStatic(java.lang.Object instance,
java.lang.reflect.Method method)
Make sure that either we have an instance or if not, that the method is static
|
static void |
checkReturnType(java.lang.reflect.Method method,
java.lang.Class<?>... returnTypes) |
static XmlClass[] |
classesToXmlClasses(java.lang.Class<?>[] classes) |
static void |
copyFile(java.io.File from,
java.io.File to) |
static java.io.File |
createTempFile(java.lang.String content) |
static java.lang.String |
defaultIfStringEmpty(java.lang.String s,
java.lang.String defaultValue) |
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 |
escapeHtml(java.lang.String s) |
static java.lang.String |
escapeUnicode(java.lang.String s) |
private static java.lang.String |
filterTrace(java.lang.String trace) |
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 boolean |
isStringBlank(java.lang.String s) |
static boolean |
isStringEmpty(java.lang.String s) |
static boolean |
isStringNotBlank(java.lang.String s) |
static boolean |
isStringNotEmpty(java.lang.String s) |
static <T> java.lang.String |
join(java.util.List<T> objects,
java.lang.String separator) |
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) |
private static java.io.BufferedWriter |
openWriter(java.io.File outputFile,
java.lang.String encoding,
boolean append) |
static java.io.BufferedWriter |
openWriter(java.lang.String outputDir,
java.lang.String fileName)
Open a BufferedWriter for the specified file.
|
static java.lang.String[] |
parseMultiLine(java.lang.String line) |
private static void |
ppp(java.lang.String s) |
static java.lang.String |
replaceSpecialCharacters(java.lang.String fileName)
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 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.
|
private static java.lang.String |
toString(java.lang.Class<?>[] classes) |
static java.lang.String |
toString(java.lang.Object obj)
Returns the string representation of the specified object, transparently
handling null references and arrays.
|
static java.lang.String |
toString(java.lang.Object object,
java.lang.Class<?> objectClass) |
private static void |
writeFile(java.io.File outputFile,
java.lang.String sb,
java.lang.String encoding,
boolean append) |
private static void |
writeFile(java.io.File outDir,
java.lang.String fileName,
java.lang.String sb,
java.lang.String encoding,
boolean append)
Writes the content of the sb string to the file named filename in outDir.
|
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 void |
writeUtf8File(java.lang.String outputDir,
java.lang.String fileName,
XMLStringBuffer xsb,
java.lang.String prefix) |
private static final java.lang.String LINE_SEP
public static final char[] SPECIAL_CHARACTERS
public static final char CHAR_REPLACEMENT
public static final char UNICODE_REPLACEMENT
private static final java.util.Map<java.lang.Character,java.lang.String> ESCAPES
public static java.lang.String[] stringToArray(java.lang.String s)
s
- the string to splitpublic static XmlClass[] classesToXmlClasses(java.lang.Class<?>[] classes)
public static java.lang.String[] parseMultiLine(java.lang.String line)
public static void writeUtf8File(java.lang.String outputDir, java.lang.String fileName, XMLStringBuffer xsb, java.lang.String prefix)
public static void writeUtf8File(java.lang.String outputDir, java.lang.String fileName, java.lang.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(java.lang.String outputDir, java.lang.String fileName, java.lang.String sb)
outputDir
- the output directory (may not exist). If null then current directory is used.fileName
- the filenamesb
- the file contentprivate static void writeFile(java.io.File outDir, java.lang.String fileName, java.lang.String sb, java.lang.String encoding, boolean append)
outDir
- the output directory (may not exist). If null then current directory is used.fileName
- the filenamesb
- the file contentprivate static void writeFile(java.io.File outputFile, java.lang.String sb, java.lang.String encoding, boolean append)
public static java.io.BufferedWriter openWriter(java.lang.String outputDir, java.lang.String fileName) throws java.io.IOException
outputDir
- output directory. If null, then current directory is usedfileName
- file namejava.io.IOException
- if anything goes wrong while creating files.private static java.io.BufferedWriter openWriter(java.io.File outputFile, java.lang.String encoding, boolean append) throws java.io.IOException
java.io.IOException
private static void ppp(java.lang.String s)
public static void dumpMap(java.util.Map<?,?> result)
result
- public static void dumpMethods(java.util.List<ITestNGMethod> allMethods)
allMethods
- public static java.lang.String[] dependentGroupsForThisMethodForTest(java.lang.reflect.Method m, IAnnotationFinder finder)
public static java.lang.String[] groupsForThisMethodForTest(java.lang.reflect.Method m, IAnnotationFinder finder)
public static java.lang.String[] groupsForThisMethodForConfiguration(java.lang.reflect.Method m, IAnnotationFinder finder)
public static java.lang.String[] dependentGroupsForThisMethodForConfiguration(java.lang.reflect.Method m, IAnnotationFinder finder)
public static void log(java.lang.String msg)
public static void log(java.lang.String cls, int level, java.lang.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(java.lang.String errorMessage)
public static int calculateInvokedMethodCount(ITestNGMethod[] methods)
public static java.lang.String[] split(java.lang.String string, java.lang.String sep)
public static void logInvocation(java.lang.String reason, java.lang.reflect.Method thisMethod, java.lang.Object[] parameters)
public static void writeResourceToFile(java.io.File file, java.lang.String resourceName, java.lang.Class<?> clasz) throws java.io.IOException
java.io.IOException
public static java.lang.String defaultIfStringEmpty(java.lang.String s, java.lang.String defaultValue)
public static boolean isStringBlank(java.lang.String s)
public static boolean isStringEmpty(java.lang.String s)
public static boolean isStringNotBlank(java.lang.String s)
public static boolean isStringNotEmpty(java.lang.String s)
public static java.lang.String[] stackTrace(java.lang.Throwable t, boolean toHtml)
public static java.lang.String escapeHtml(java.lang.String s)
public static java.lang.String escapeUnicode(java.lang.String s)
private static java.lang.String filterTrace(java.lang.String trace)
public static java.lang.String toString(java.lang.Object object, java.lang.Class<?> objectClass)
public static java.lang.String detailedMethodName(ITestNGMethod method, boolean fqn)
public static java.lang.String arrayToString(java.lang.String[] strings)
public static java.lang.String replaceSpecialCharacters(java.lang.String fileName)
fileName
- file name that could contain special characters.public static <T> java.lang.String join(java.util.List<T> objects, java.lang.String separator)
public static void copyFile(java.io.File from, java.io.File to)
public static java.io.File createTempFile(java.lang.String content)
public static void checkInstanceOrStatic(java.lang.Object instance, java.lang.reflect.Method method)
public static void checkReturnType(java.lang.reflect.Method method, java.lang.Class<?>... returnTypes)
private static java.lang.String toString(java.lang.Class<?>[] classes)
public static java.lang.String toString(java.lang.Object obj)
obj
- the object