FileDocCategorySizeDatePackage
TestPerson.javaAPI DocExample1929Sun Sep 15 10:03:22 BST 2002com.oreilly.javaxp.junit

TestPerson.java

package com.oreilly.javaxp.junit;

import junit.extensions.TestSetup;
import junit.framework.*;

/**
 * Sample unit tests for the {@link Person} class.
 * @author Eric M. Burke
 * @version $Id: TestPerson.java,v 1.3 2002/09/12 02:23:39 jepc Exp $
 */
public class TestPerson extends TestCase {

    /**
     * This constructor is required by JUnit.
     * @param name the name of the test method to execute.
     */
    public TestPerson(String name) {
        super(name);
    }

    public void testPassNullsToConstructor() {
        try {
            Person p = new Person(null, null);
            fail("Expected IllegalArgumentException because both args are null");
        } catch (IllegalArgumentException expected) {
            // ignore this because it means the test passed!
        }
    }

    /**
     * TestAll the name concatenation feature of Person.
     */
    public void testGetFullName() {
        Person p = new Person("Aidan", "Burke");
        assertEquals("Aidan Burke", p.getFullName());
    }

    /**
     * Verify that nulls are handled properly.
     */
    public void testNullsInName() {
        Person p = new Person(null, "Burke");
        assertEquals("? Burke", p.getFullName());

        p = new Person("Tanner", null);
        assertEquals("Tanner ?", p.getFullName());
    }

    public static void oneTimeSetup() {
        System.out.println("oneTimeSetUp");
    }

    public static void oneTimeTearDown() {
        System.out.println("oneTimeTearDown");
    }

    public static Test suite() {
        TestSetup setup = new TestSetup(new TestSuite(TestPerson.class)) {
            protected void setUp() throws Exception {
                oneTimeSetup();
            }

            protected void tearDown() throws Exception {
                oneTimeTearDown();
            }
        };
        return setup;
    }
}