001package hw7.test;
002
003import java.io.File;
004import java.io.FileInputStream;
005import java.io.FileNotFoundException;
006import java.io.InputStream;
007import java.io.PrintStream;
008
009/**
010 * This class can be used to test your Campus Paths main application. It
011 * redirects System.out and System.in to input and output files, then invokes
012 * the application's main method. This allows the output of a set of commands
013 * to be compared against the expected output without user intervention.  
014 */
015public class HW7TestDriver {
016    
017    // Files for reading input and writing output in place of the console.
018    private File in, out;
019
020    /**
021     * @requires in != null && out != null
022     *
023     * @effects Creates a new HW7TestDriver and runs the Campus Paths main
024     * program with System.in and System.out redirected to the provided files.
025     **/
026    public HW7TestDriver(File in, File out) {
027        this.in = in;
028        this.out = out;
029    }
030    
031    public void runTests() throws FileNotFoundException {
032        // Store original values of I/O streams.
033        InputStream stdin = System.in;
034        PrintStream stdout = System.out;
035        PrintStream stderr = System.err;
036        
037        // Redirect I/O to files.
038        System.setIn(new FileInputStream(in));
039        System.setOut(new PrintStream(out));
040        
041        // TODO: add a line here to call your main method. For example, if your
042        // main class is called CampusPaths, write:
043        // CampusPaths.main(new String[0]);
044
045        // Restore standard I/O streams.
046        System.setIn(stdin);
047        System.setOut(stdout);
048        System.setErr(stderr);
049    }
050}