FileDocCategorySizeDatePackage
TestGame.javaAPI DocExample2655Tue Oct 22 21:03:22 BST 2002com.oreilly.javaxp.junit

TestGame

public class TestGame extends TestCase
Sample unit tests for the {@link Game} class.
author
Eric M. Burke
version
$Id: TestGame.java,v 1.1 2002/10/23 02:03:23 jepc Exp $

Fields Summary
private Game
game
private Ship
fighter
Constructors Summary
public TestGame(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        junit.textui.TestRunner.run(new TestSuite(TestGame.class));
    
public voidsetUp()

        this.game = new Game();
        this.fighter = this.game.createFighter("001");
    
public static junit.framework.Testsuite()


        // show how to run tests concurrently
        TestSuite suite = new ActiveTestSuite();
        suite.addTest(new TestGame("testCreateFighter"));
        suite.addTest(new RepeatedTest(new TestGame("testGameInitialState"), 20));
        suite.addTest(new RepeatedTest(new TestGame("testSameFighters"), 10));
        suite.addTest(TestPerson.suite());
        return suite;

        //return new RepeatedTest(new TestSuite(TestGame.class), 1);

//        TestSuite suite = new TestSuite();
//        suite.addTest(new RepeatedTest(new TestGame("testCreateFighter"), 100));
//        suite.addTest(new TestGame("testSameFighters"));
//        suite.addTest(new TestGame("testGameInitialState"));
//        return suite;

        /*
        TestSuite suite = new TestSuite(TestGame.class);
        suite.addTest(new TestSuite(TestPerson.class));
        return suite;
        */
    
public voidtearDown()

        this.game.shutdown();
    
public voidtestCreateFighter()

//        System.out.println("Begin testCreateFigher()");
        assertEquals("Fighter did not have the correct identifier",
                "001", this.fighter.getId());
//        System.out.println("End testCreateFighter()");
    
public voidtestGameInitialState()

//        System.out.println("Begin testGameInitialState()");
        assertTrue("A new game should not be started yet",
                !this.game.isPlaying());
//        System.out.println("End testGameInitialState()");
    
public voidtestSameFighters()

//        System.out.println("Begin testSameFighters()");
        Ship fighter2 = this.game.createFighter("001");
        assertSame("createFighter with same id should return same object",
                this.fighter, fighter2);
//        System.out.println("End testSameFighters()");