class TresAmigosTester { public static void main(String[] args) { TresAmigos f1 = new TresAmigos( "Arturo", "Margarita", "Zorro" ); TresAmigos f2 = new TresAmigos( "Arturo", "Zorro", "Margarita" ); TresAmigos f3 = new TresAmigos( "Margarita", "Arturo", "Zorro" ); TresAmigos f4 = new TresAmigos( "Margarita", "Zorro", "Arturo" ); TresAmigos f5 = new TresAmigos( "Zorro", "Arturo", "Margarita" ); TresAmigos f6 = new TresAmigos( "Zorro", "Margarita", "Arturo" ); TresAmigos g1 = new TresAmigos( "Arturo", "Arturo", "Margarita" ); TresAmigos g2 = new TresAmigos( "Arturo", "Margarita", "Arturo" ); TresAmigos g3 = new TresAmigos( "Margarita", "Arturo", "Arturo" ); TresAmigos h1 = new TresAmigos( "Zorro", "Zorro", "Zorro" ); System.err.println("\nStarting tests:" ); // Call three of our own (static) methods: TresAmigosTester.testGetters(f1, "Arturo", "Margarita", "Zorro", "f1"); TresAmigosTester.testGetters(f2, "Arturo", "Margarita", "Zorro", "f2"); TresAmigosTester.testGetters(f3, "Arturo", "Margarita", "Zorro", "f3"); TresAmigosTester.testGetters(f4, "Arturo", "Margarita", "Zorro", "f4"); TresAmigosTester.testGetters(f5, "Arturo", "Margarita", "Zorro", "f5"); TresAmigosTester.testGetters(f6, "Arturo", "Margarita", "Zorro", "f6"); TresAmigosTester.testGetters(g1, "Arturo", "Arturo", "Margarita", "g1"); TresAmigosTester.testGetters(g2, "Arturo", "Arturo", "Margarita", "g2"); TresAmigosTester.testGetters(g3, "Arturo", "Arturo", "Margarita", "g3"); TresAmigosTester.testGetters(h1, "Zorro", "Zorro", "Zorro", "h1"); System.err.println("Finished tests." ); } /** Do a comprehensive check on calling getFirst,getSecond,getThird for * a TresAmigos object. * @param f The TresAmigos object to test. * @param exp1 The expected alphabetically-first name. * @param exp2 The expected alphabetically-second name. * @param exp3 The expected alphabetically-third name. * @param posseName A name for this test case, for error-reporting purposes. */ public static void testGetters( TresAmigos f, String exp1, String exp2, String exp3, String posseName ) { TresAmigosTester.reportIfError( exp2, f.getSecond(), posseName, "Second" ); TresAmigosTester.reportIfError( exp1, f.getFirst(), posseName, "First" ); TresAmigosTester.reportIfError( exp3, f.getThird(), posseName, "Third" ); } /** Look at the results of one particular test, and print an error * if the results weren't expected. * @param expectedResult What the test case *should* have given. * @param actualResult What the test case *actually* gave. * @param The name (for testing) of the object being tested, e.g. "f3". * @param The name (for testing) of the method being tested, e.g. "getThird". */ public static void reportIfError( String expectedResult, String actualResult, String posseName, String methodName ) { if (! expectedResult.equals(actualResult)) { System.err.println( posseName + "." + "get" + methodName + " expected \"" + expectedResult + "\"" + " but got \"" + actualResult + "\"." ); } } }