FileDocCategorySizeDatePackage
TestPerson.javaAPI DocExample1954Tue Oct 22 21:03:22 BST 2002com.oreilly.javaxp.junit

TestPerson

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

Fields Summary
Constructors Summary
public TestPerson(String name)
This constructor is required by JUnit.

param
name the name of the test method to execute.

        super(name);
    
Methods Summary
public static voidoneTimeSetup()

        System.out.println("oneTimeSetUp");
    
public static voidoneTimeTearDown()

        System.out.println("oneTimeTearDown");
    
public static junit.framework.Testsuite()

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

            protected void tearDown() throws Exception {
                oneTimeTearDown();
            }
        };
        return setup;
    
public voidtestGetFullName()
TestAll the name concatenation feature of Person.

        Person p = new Person("Aidan", "Burke");
        assertEquals("Aidan Burke", p.getFullName());
    
public voidtestNullsInName()
Verify that nulls are handled properly.

fail("sample failure");
        Person p = new Person(null, "Burke");
        assertEquals("? Burke", p.getFullName());

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

        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!
        }