Package randoop.output
Class JavaFileWriter
- java.lang.Object
-
- randoop.output.JavaFileWriter
-
- All Implemented Interfaces:
CodeWriter
public class JavaFileWriter extends Object implements CodeWriter
ACodeWriter
that writes JUnit4 test class source text to a.java
file with annotations so that tests are executed in ascending alphabetical order by test method name.
-
-
Constructor Summary
Constructors Constructor Description JavaFileWriter(String junitDirName)
JavaFileWriter creates an instance of class holding information needed to write a test suite.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Path
createOutputDir(String packageName)
Create the output directory for the package if it does not already exist.private Path
getDir(String packageName)
Returns the directory for the package name relative to the directory name of this writer.Path
writeClassCode(String packageName, String className, String classCode)
writeClassCode writes a code sequence as a JUnit4 test class to a .java file.Path
writeUnmodifiedClassCode(String packageName, String classname, String classCode)
Writes the given class.
-
-
-
Field Detail
-
dirName
private final String dirName
The directory to which JUnit files are written.
-
-
Constructor Detail
-
JavaFileWriter
public JavaFileWriter(String junitDirName)
JavaFileWriter creates an instance of class holding information needed to write a test suite.- Parameters:
junitDirName
- directory where files are to be written
-
-
Method Detail
-
writeClassCode
public Path writeClassCode(String packageName, String className, String classCode) throws RandoopOutputException
writeClassCode writes a code sequence as a JUnit4 test class to a .java file. Tests are executed in ascending alphabetical order by test method name.- Specified by:
writeClassCode
in interfaceCodeWriter
- Parameters:
packageName
- the package name for the classclassName
- the name of the classclassCode
- the source text of the test class- Returns:
- the Path object for generated java file
- Throws:
RandoopOutputException
- if there is an error while writing the code
-
writeUnmodifiedClassCode
public Path writeUnmodifiedClassCode(String packageName, String classname, String classCode) throws RandoopOutputException
Description copied from interface:CodeWriter
Writes the given class. Does not modify the class text.- Specified by:
writeUnmodifiedClassCode
in interfaceCodeWriter
- Parameters:
packageName
- the package name of the classclassname
- the simple name of the classclassCode
- the text of the class to be written, must be compilable- Returns:
- the
Path
object for the Java file written - Throws:
RandoopOutputException
- if there is an error while writing the code
-
createOutputDir
private Path createOutputDir(String packageName) throws RandoopOutputException
Create the output directory for the package if it does not already exist.- Parameters:
packageName
- the package name- Returns:
- the
Path
for the created directory - Throws:
RandoopOutputException
- if the directory for the package could not be created
-
-