A simple class that demos how to begin to write code to test a class.

Just for fun -- think of ways to make the testing code more elaborate (e.g., track and output the % of tests that pass)


public class FooTests {

	private void test1() {
		println("\ntest1");
		Foo
			foo1 = Foo.fromNameId("Kofi", 101),
			foo2 = Foo.fromNameId("Asha", 102);
		println("foo1: " + foo1);
		println("foo2: " + foo2);
		println("equals: " + foo1.equals(foo2));
	}

	private void test2() {
		println("\ntest2");
		Foo
			foo1 = Foo.fromNameId("Kofi", 101),
			foo2 = Foo.fromNameId("Kofi", 101);
		println("foo1: " + foo1);
		println("foo2: " + foo2);
		println("equals: " + foo1.equals(foo2));
	}

	private void test3() {
		println("\ntest3");
		Foo
			foo1 = Foo.fromNameId("Kofi", 101),
			foo2;
		//use copy constructor
		foo2 = new Foo(foo1);
		println("foo1: " + foo1);
		println("foo2 (copy of foo1): " + foo2);
		println("equals: " + foo1.equals(foo2));
	}


	public static void main(String[] args) {
		FooTests tests = new FooTests();
		tests.test1();
		tests.test2();
		tests.test3();
	}

	public static void println(Object o) {
		System.out.println(o != null ? o.toString() : "null");
	}
}