|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.io.IOUnitils
public class IOUnitils
Constructor Summary | |
---|---|
IOUnitils()
|
Method Summary | ||
---|---|---|
static File |
createTempDir(String dirName)
Creates a temporary directory with the given name. |
|
static File |
createTempFile(String fileName)
Creates a temporary file with the given name. |
|
static void |
deleteTempFileOrDir(File fileOrDir)
Deletes the given file or directory. |
|
static
|
readFileContent(Class<T> targetType,
Object testInstance)
Loads the content of 'test-class'.' |
|
static
|
readFileContent(Class<T> targetType,
String encoding,
Object testInstance)
Loads the content of 'test-class'.' |
|
static
|
readFileContent(String fileName,
Class<T> targetType,
Object testInstance)
Loads the content of the file with the given name and converts it to the given target type using the default encoding. |
|
static
|
readFileContent(String fileName,
Class<T> targetType,
String encoding,
Object testInstance)
Loads the content of the file with the given name and converts it to the given target type. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IOUnitils()
Method Detail |
---|
public static <T> T readFileContent(Class<T> targetType, Object testInstance)
String result1 = readFileContent(String.class, this);
Properties result2 = readFileContent(Properties.class, this);
If this is an instance of MyTest, this will read-in file name org/myPackage/MyTest.txt (txt is the default extension for the String converter) and return the result as a string.
The second line will read-in file name org/myPackage/MyTest.properties (properties is the default extension of the Properties converter) and return the result as a Properties instance.
See FileContent
for more information on how the file is resolved.
targetType
- The target type to convert the content to, not nulltestInstance
- The test instance that will be used to construct the file name and locate the file, not null
public static <T> T readFileContent(Class<T> targetType, String encoding, Object testInstance)
FileContent
for more information on how the file is resolved.
targetType
- The target type to convert the content to, not nullencoding
- The encoding to use when reading the file, null for the default encodingtestInstance
- The test instance that will be used to construct the file name and locate the file, not null
FileContent
public static <T> T readFileContent(String fileName, Class<T> targetType, Object testInstance)
String result1 = readFileContent("myFile.csv", String.class, this);
Properties result2 = readFileContent("/myFile.map", Properties.class, this);
If this is an instance of MyTest, this will read-in file name org/myPackage/myFile.csv and return the result as a string.
The second line will read-in file name myFile.properties and return the result as a Properties instance.
See FileContent
for more information on how the file is resolved.
fileName
- The name of the file, not nulltargetType
- The target type to convert the content to, not nulltestInstance
- The test instance that will be used to locate the file, not null
public static <T> T readFileContent(String fileName, Class<T> targetType, String encoding, Object testInstance)
FileContent
for more information on how the file is resolved.
fileName
- The name of the file, not nulltargetType
- The target type to convert the content to, not nullencoding
- The encoding to use when reading the file, null for the default encodingtestInstance
- The test instance that will be used to locate the file, not null
public static File createTempFile(String fileName)
DefaultTempServiceFactory.ROOT_TEMP_DIR
property.
If no root temp dir is specified the default user temp dir will be used.
Watch out: if the file already exists, it will first be deleted.
The file will not be removed after the test. You can use deleteTempFileOrDir(java.io.File)
, if you want
to perform cleanup after the test.
fileName
- The name of the temp file, not null
public static File createTempDir(String dirName)
DefaultTempServiceFactory.ROOT_TEMP_DIR
property.
If no root temp dir is specified the default user temp dir will be used.
Watch out: if the directory already exists, it will first be deleted. If the directory was not empty,
all files in the directory will be deleted.
The directory will not be removed after the test. You can use deleteTempFileOrDir(java.io.File)
, if
you want to perform cleanup after the test.
dirName
- The name of the temp dir, not null
public static void deleteTempFileOrDir(File fileOrDir)
fileOrDir
- The file or directory to delete, can be null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |