001package hw8.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 */
015@SuppressWarnings("nullness")
016public class HW8TestDriver {
017    
018    // Files for reading input and writing output in place of the console.
019    private File in, out;
020
021    /**
022     * @requires in != null && out != null
023     *
024     * @effects Creates a new HW8TestDriver and runs the Campus Paths main
025     * program with System.in and System.out redirected to the provided files.
026     **/
027    public HW8TestDriver(File in, File out) {
028        this.in = in;
029        this.out = out;
030    }
031    
032    public void runTests() throws FileNotFoundException {
033        // Store original values of I/O streams.
034        InputStream stdin = System.in;
035        PrintStream stdout = System.out;
036        PrintStream stderr = System.err;
037        
038        // Redirect I/O to files.
039        System.setIn(new FileInputStream(in));
040        System.setOut(new PrintStream(out));
041        
042        // TODO: add a line here to call your main method. For example, if your
043        // main class is called CampusPaths, write:
044        // CampusPaths.main(new String[0]);
045
046        // Restore standard I/O streams.
047        System.setIn(stdin);
048        System.setOut(stdout);
049        System.setErr(stderr);
050    }
051}