|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunitutils.Utils
This class contains miscellaneous (static) utility functions that are useful in writing JUnit functional tests.
Nested Class Summary | |
static class |
Utils.QuoteTokenizer
An enumerator that parses a string into tokens, according to the rules a command-line would use. |
Field Summary | |
static boolean |
disable
Setting this field to true disables the capturing of the output; one would do this only for debugging purposes. |
private static java.lang.String |
ORACLE_SUFFIX
The suffix to append to create the golden output filename |
private static java.io.PrintStream |
pse
A cached value of the usual System err stream. |
private static java.io.PrintStream |
pso
A cached value of the usual System out stream. |
private static java.lang.String |
SAVED_SUFFIX
The suffix to append to create the actual output filename |
Constructor Summary | |
Utils()
|
Method Summary | |
static Diff |
compareStringToFile(java.lang.String s,
java.lang.String rootname)
Compares the given string to the content of the given file using a comparator that ignores platform differences in line-endings. |
static java.lang.String |
executeCompile(java.lang.Class cls,
java.lang.String[] args)
Executes the static compile(String[]) method of the given class |
static java.lang.String |
executeMethod(java.lang.Class cls,
java.lang.String methodname,
java.lang.String[] args)
Finds and executes the method with the given name in the given class; the method must have a single argument of type String[]. |
static java.lang.String |
executeMethod(java.lang.reflect.Method method,
java.lang.String[] args)
Calls the given method on the given String[] argument. |
static java.lang.String[] |
parseLine(java.lang.String s)
Parses a string into arguments as if it were a command-line, using the QuoteTokenizer to parse the tokens. |
static java.lang.String |
readFile(java.lang.String filename)
Reads the contents of the file with the given name, returning a String. |
static java.lang.String |
readFile(java.lang.String filename,
byte[] cb)
Reads the contents of the file with the given name, returning a String. |
static java.lang.String |
readFileX(java.lang.String filename)
Reads a file, returning a String containing the contents |
static boolean |
recursivelyRemoveDirectory(java.io.File d,
boolean removeDirectoryItself)
Deletes the contents of a directory, including subdirectories. |
static void |
removeFiles(java.lang.String pattern)
This deletes all files (in the current directory) whose names match the given pattern in a regular-expression sense; however, it is only implemented for patterns consisting of characters and at most one '*', since I'm not going to rewrite an RE library. |
static void |
restoreStreams()
Restores System.out and System.err to the initial, system-defined values. |
static void |
restoreStreams(boolean close)
Restores System.out and System.err to the initial, system-defined values. |
static java.io.ByteArrayOutputStream |
setStreams()
Creates a new output stream (which is returned) and makes it the stream into which the standard and error outputs are captured. |
static void |
setStreams(java.io.PrintStream ps)
Redirects System.out and System.err to the given PrintStream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static boolean disable
private static final java.io.PrintStream pso
private static final java.io.PrintStream pse
private static final java.lang.String ORACLE_SUFFIX
private static final java.lang.String SAVED_SUFFIX
Constructor Detail |
public Utils()
Method Detail |
public static void setStreams(java.io.PrintStream ps)
ps
- The stream that is the new output and error streampublic static java.io.ByteArrayOutputStream setStreams()
public static void restoreStreams()
Note that setStreams/restoreStreams operate on the global values of System.out and System.err; these implementations are not synchronized - you will need to take care of any race conditions if you utilize these in more than one thread.
public static void restoreStreams(boolean close)
Note that setStreams/restoreStreams operate on the global values of System.out and System.err; these implementations are not synchronized - you will need to take care of any race conditions if you utilize these in more than one thread.
close
- if true, the current output and error streams
are closed before being reset (if they are not currently the
System output and error streams)public static java.lang.String[] parseLine(java.lang.String s)
s
- The String to parse
public static boolean recursivelyRemoveDirectory(java.io.File d, boolean removeDirectoryItself)
d
- The directory whose contents are deletedremoveDirectoryItself
- if true, the directory itself is deleted
public static java.lang.String readFile(java.lang.String filename, byte[] cb) throws java.io.IOException
filename
- The file to be readcb
- A temporary byte array to speed reading
java.io.IOException
public static java.lang.String readFileX(java.lang.String filename)
filename
- the file to be read
public static java.lang.String readFile(java.lang.String filename) throws java.io.IOException
filename
- The file to be read
java.io.IOException
public static java.lang.String executeCompile(java.lang.Class cls, java.lang.String[] args)
cls
- The class whose 'compile' method is be invokedargs
- The String[] argument of the method
public static java.lang.String executeMethod(java.lang.Class cls, java.lang.String methodname, java.lang.String[] args)
cls
- The class whose method is to be invokedmethodname
- The method to be invokedargs
- The argument of the method
public static java.lang.String executeMethod(java.lang.reflect.Method method, java.lang.String[] args)
method
- The static method to be invokedargs
- The argument of the method
public static Diff compareStringToFile(java.lang.String s, java.lang.String rootname) throws java.io.IOException
s
- the String to comparerootname
- the prefix of the file name
java.io.IOException
public static void removeFiles(java.lang.String pattern)
pattern
- the pattern to match against filenames
|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |