import junit.framework.TestCase; import listFW.*; import listFW.visitor.*; import listFW.factory.*; public class Test_HW07 extends TestCase { /** * * Tests the CopyFac visitor using all combinations of CompositeListFactory * and InnerCompListFact to make the original and generated lists. */ public void test_CopyFac() { test_CopyFac_help(CompositeListFactory.Singleton, CompositeListFactory.Singleton); test_CopyFac_help(InnerCompListFact.Singleton, InnerCompListFact.Singleton); test_CopyFac_help(CompositeListFactory.Singleton, InnerCompListFact.Singleton); test_CopyFac_help(InnerCompListFact.Singleton, CompositeListFactory.Singleton); } /** * * Test code used in conjunction with test_CopyFac() that is independent of which * factory is being used. * Notes: The name of this method begins with "test" because this way JUnit will identifiy * any error as occurring in a specific line of this method, rather than in the calling * line in test_CopyFac. Also, the error strings below explicitly include the toString() of the * factories being used so that the parameters under which this test code was called can be * readily identified. This way one can tell when one factory works but another does not. * @param fac1 the factory used to make the original list. * @param fac2 the factory used to make the copy */ private void test_CopyFac_help(IListFactory fac1, IListFactory fac2) { IList l = fac1.makeEmptyList(); IListAlgo cf = new CopyFac(fac2); assertEquals("Empty "+fac1+" list: CopyFac using "+fac2, "()", l.execute(cf).toString()); l = fac1.makeNEList("a", l); assertEquals("(a) from "+fac1+": CopyFac using "+fac2, "(a)", l.execute(cf).toString()); l = fac1.makeNEList("b", l); assertEquals("(b, a) from "+fac1+": CopyFac using "+fac2, "(b, a)", l.execute(cf).toString()); } }