Wednesday, July 21, 2010

Project 2 - JUnit

Well, it isn't very fancy, but it provided a decent intro to JUnit testing! :-)


/**
 *
 */
package crrasolrindexer;

import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author slittle2
 *
 */
public class CRRA_DatumTest {

    private CRRA_Datum testCD = null;
    CRRA_Datum crraCD = null;
   
    /**
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception {
        crraCD = new CRRA_Datum("id allfields institution collection building language format author author-letter authorStr auth_author auth_authorStr title title_sort title_sub title_short title_full title_fullStr title_auth physical publisher publisherStr publishDate edition description contents url thumbnail lccn ctrlnum isbn issn callnumber callnumber-a callnumber-first callnumber-first-code callnumber-subject callnumber-subject-code callnumber-label dewey-hundreds dewey-tens dewey-ones dewey-full dewey-sort author2 author2Str author2-role auth_author2 auth_author2Str author_additional author_additionalStr title_alt title_old title_new dateSpan series series2 topic genre geographic illustrated recordtype");
    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception {
        crraCD = null;
    }

    /**
     * Test method for {@link crrasolrindexer.CRRA_Datum#CRRA_Datum(java.lang.String)}.
     */
    @Test
    public final void testCRRA_DatumString() {
        testCD = new CRRA_Datum("foo bar");
        assertNotNull(testCD);
    }

    /**
     * Test method for {@link crrasolrindexer.CRRA_Datum#CRRA_Datum()}.
     */
    @Test
    public final void testCRRA_Datum() {
        testCD = new CRRA_Datum();
        assertNotNull(testCD);
        assertEquals(testCD.toString(), crraCD.toString());
        assert(testCD.equals(crraCD));
    }

    /**
     * Test method for {@link crrasolrindexer.CRRA_Datum#returnField(java.lang.String)}.
     * @throws IOException
     */
    @Test
    public final void testReturnField() throws IOException {
        testCD = new CRRA_Datum("foo bar");
        testCD.setField("foo", "boo!");
        assertEquals("boo!", testCD.returnField("foo"));
    }

    /**
     * Test method for {@link crrasolrindexer.CRRA_Datum#concatenateField(java.lang.String, java.lang.String)}.
     * @throws IOException
     */
    @Test
    public final void testConcatenateField() throws IOException {
        crraCD.setField("author", "Bob Shakespeare");
        crraCD.concatenateField("author", " & Joe Shakespeare");
        assertEquals("Bob Shakespeare & Joe Shakespeare", crraCD.returnField("author"));
    }

    /**
     * Test method for {@link crrasolrindexer.CRRA_Datum#toString()}.
     */
    @Test
    public final void testToString() {
        assertNotNull(crraCD.toString());
    }

}

No comments:

Post a Comment