Unit Test for RefEntry

package org.mcraig.cs445.refentry;
import java.io.*;
import java.util.HashSet;
import java.util.Properties;
import junit.framework.TestCase;

/** 
 * Test friendly and public methods of the RefEntry class using the
 * JUnit test framework.
 * @author <a href="mailto:mark@mcraig.org">Mark Craig</a>
 */
public class TestRefEntry extends TestCase {
    protected File       infile;
    protected File       outfile;
    protected Properties xslt;
    protected RefEntry   refentry;
    protected void setUp() throws Exception {
        try {
            infile   = new File("src/test/test.xml");
            outfile  = File.createTempFile("test", ".html");
            xslt     = new Properties();
            xslt.load(
                new BufferedInputStream(
                    new FileInputStream("src/conf/xslt.props")));
            refentry = new RefEntry(infile, outfile, xslt);
        } catch (Exception e) {
            throw e;
        }
    }
    protected void tearDown() throws Exception {
        try {
            outfile.delete();
        } catch (Exception e) {
            throw e;
        }
    }
    public void testCompareTo() {
        assertTrue(refentry.compareTo(refentry) == 0);
    }
    public void testGetID() {
        String id = new String(refentry.getID());
        assertEquals("test-test", id); 
    }
    public void testGetKeys() {
        HashSet keys = new HashSet();
        keys.add(new String("test"));
        keys.add(new String("refentry"));
        keys.add(new String("servlet"));
        keys.add(new String("code"));
        keys.add(new String("synopsis"));
        keys.add(new String("refsect1"));
        keys.add(new String("reference"));
        keys.add(new String("section"));

        HashSet gotkeys = refentry.getKeys(new HashSet());
        assertTrue(gotkeys.size() == keys.size());
    }
    public void testGetManVolNum() {
        String mvn = new String(refentry.getManVolNum());
        assertEquals("test", mvn);
    }
    public void testGetRefName() {
        String rn = new String(refentry.getRefName());
        assertEquals("test", rn);
    }
    public void testGetRefPurpose() {
        String rp = new String(refentry.getRefPurpose());
        assertEquals("test RefEntry servlet code", rp);
    }
    public void testGetXHTML() {
        String test;
        try {
            BufferedReader br   =
                new BufferedReader(
                    new FileReader(
                        new File("src/test/test.div")));
            StringWriter   sr   = new StringWriter();
            BufferedWriter bw   = new BufferedWriter(sr);
            String         line = new String("");
            while ((line = br.readLine()) != null) {
                bw.write(line);
                bw.newLine();
            }
            br.close();
            bw.close();
            sr.close();
            test = sr.toString();
            assertEquals(test, refentry.getXHTML());
        } catch (Exception e) {
            fail(e.toString());
        }
    }
    public void runTest() {
        testCompareTo();
        testGetID();
        testGetKeys();
        testGetManVolNum();
        testGetRefName();
        testGetRefPurpose();
        testGetXHTML();
    }
}