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.1 2002/10/23 02:03:23 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() {
fail("sample failure");
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;
}
}
|