Class JavaFileWriter

  • All Implemented Interfaces:
    CodeWriter

    public class JavaFileWriter
    extends Object
    implements CodeWriter
    A CodeWriter 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.
    • 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 interface CodeWriter
        Parameters:
        packageName - the package name for the class
        className - the name of the class
        classCode - 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 interface CodeWriter
        Parameters:
        packageName - the package name of the class
        classname - the simple name of the class
        classCode - 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
      • getDir

        private Path getDir​(String packageName)
        Returns the directory for the package name relative to the directory name of this writer.
        Parameters:
        packageName - the package name
        Returns:
        the Path for the directory corresponding to the package name