Unit Test for RefEntryValidator

package org.mcraig.cs445.refentry;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
import org.xml.sax.InputSource;
import junit.framework.TestCase;

/**
 * Test RefEntryValidator using the JUnit test framework.
 * @author <a href=mailto:mark@mcraig.org>Mark Craig</a>
 */
public class TestRefEntryValidator extends TestCase {
    protected InputSource validInput;
    protected InputSource invalidInput;
    protected File        testOut;
    protected void setUp() throws Exception {
        try {
            File validFile   = new File("src/test/test.xml");
            File invalidFile = new File("src/test/invalid.xml");

            validInput   = new InputSource(new FileReader(validFile));
            invalidInput = new InputSource(new FileReader(invalidFile));

            testOut = File.createTempFile("testout", "txt");
        } catch (Exception e) {
            throw e;
        }
    }
    public void tearDown() throws Exception {
        try {
            testOut.delete();
        } catch (Exception e) {
            throw e;
        }
    }
    public void testIsValid() {
        boolean isValid   = RefEntryValidator.isValid(validInput);
        assertTrue(isValid);
    }
    public void testIsInvalid() {
        // Set isValid to true. We expect the invalid input to change
        // it to false upon validation.
        boolean isValid = true;
        try {
            PrintStream out =
                new PrintStream(new FileOutputStream(testOut));
            System.setErr(out);
            System.setOut(out);
            isValid = RefEntryValidator.isValid(invalidInput);
        } catch (Exception se) {
            assertTrue(
                se.getClass().getName().equals("org.xml.sax.SAXException"));
            assertFalse(isValid);
        }
    }
    public void runTest() {
        testIsValid();
        testIsInvalid();
    }
}