This seems rather complex.  Can this test case be simplified?