package junit.samples; import junit.framework.*; public class PersonTest extends TestCase { protected Car c1,c2; protected Person hans,peter,lars; protected void setUp() { hans = new Person("Hans"); peter = new Person("Peter"); lars = new Person("Lars"); c1 = new Car("Mustang", hans); c2 = new Car("Jeep", peter); } public static Test suite() { return new TestSuite(CarTest.class); } public void testNewPerson() { assertEquals("Lars", lars.getName()); assertNull(lars.getCar()); } public void testToString() { assertEquals("Person Hans", hans.toString()); } public void testSetCar(){ lars.setCar(c1); //Lars has no car proir to the call assertTrue(lars.getCar() == c1); peter.setCar(c1); // Peter already owns the car c2 assertTrue(peter.getCar() == c1); } public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } }