1 | package jpacman; |
2 | |
3 | import static org.junit.Assert.assertEquals; |
4 | import static org.junit.Assert.assertTrue; |
5 | |
6 | import java.io.IOException; |
7 | |
8 | import jpacman.controller.AbstractMonsterController; |
9 | import jpacman.controller.IMonsterController; |
10 | import jpacman.controller.Pacman; |
11 | import jpacman.model.Engine; |
12 | import jpacman.model.GameTestCase; |
13 | import junit.framework.JUnit4TestAdapter; |
14 | import junit.framework.TestSuite; |
15 | |
16 | import org.junit.After; |
17 | import org.junit.Before; |
18 | import org.junit.Test; |
19 | |
20 | /** |
21 | * Systematic acceptance test for Pacman. |
22 | * It follows the test suite design document, |
23 | * which in turn follows the Pacman use cases. |
24 | * |
25 | * The test cases have been derived by translating the use |
26 | * cases into test-ready decision tables and state machines, |
27 | * both available in the JPacman documentation. |
28 | * |
29 | * @author Arie van Deursen; 5-sep-2004 |
30 | * @version $Id: PacmanTest.java,v 1.14 2008/02/10 19:28:20 arie Exp $ |
31 | */ |
32 | public class PacmanTest extends GameTestCase { |
33 | |
34 | /** |
35 | * The full game, including a gui. |
36 | */ |
37 | private Pacman myPacman; |
38 | |
39 | /** |
40 | * Set up the full game, making use of the |
41 | * game model created in the superclass. |
42 | * @throws IOException if images can't be loaded. |
43 | */ |
44 | @Before public void setup() throws IOException { |
45 | myPacman = new Pacman(new Engine(theGame), |
46 | new EmptyMonsterController()); |
47 | myPacman.start(); |
48 | assertTrue(myPacman.getEngine().inPlayingState()); |
49 | } |
50 | |
51 | /** |
52 | * And, at the end, nicely close the windows. |
53 | */ |
54 | @After public void tearDown() { |
55 | myPacman.exit(); |
56 | } |
57 | |
58 | /** |
59 | * Top level test running the default GUI, map, monstercontroller, |
60 | * observers, etc. |
61 | * Simple "smoke test" that just executes various methods to make sure that |
62 | * they don't crash immediately. |
63 | * More elaborate tests are conducted elsewhere. |
64 | * The name "alpha-omega" refers to the full cycle this test suite |
65 | * attempts to make (Binder's terminology). |
66 | * @throws InterruptedException if threads don't work well |
67 | * @throws IOException If the file systems is wrong |
68 | */ |
69 | @Test public void testTopLevelAlphaOmega() |
70 | throws InterruptedException, IOException { |
71 | Pacman p = new Pacman(); |
72 | p.start(); |
73 | p.left(); |
74 | p.right(); |
75 | final int nrOfMonsterMoves = 10; |
76 | Thread.sleep(AbstractMonsterController.DELAY * nrOfMonsterMoves); |
77 | p.up(); |
78 | p.down(); |
79 | p.quit(); |
80 | p.start(); |
81 | p.left(); |
82 | p.right(); |
83 | p.up(); |
84 | p.down(); |
85 | p.exit(); |
86 | } |
87 | |
88 | // The remaining acceptance test suite heavily depends on |
89 | // proper implementation of the functionality that has been |
90 | // left out as an exercise, and hence has been omitted from |
91 | // this version. |
92 | |
93 | |
94 | /** |
95 | * A monster controller that doesn't move any monsters, |
96 | * allowing us to do the moving ourselves in this test suite. |
97 | */ |
98 | private class EmptyMonsterController implements IMonsterController { |
99 | public void doTick() { } |
100 | public void start() { } |
101 | public void stop() { } |
102 | } |
103 | |
104 | /** |
105 | * @return The underlying engine. |
106 | */ |
107 | private Engine getEngine() { |
108 | return myPacman.getEngine(); |
109 | } |
110 | |
111 | /** |
112 | * Create a JUnit 3.8 Suite object that can be used to exercise |
113 | * the JUnit 4 test suite from the command line or from ant. |
114 | * @return A Junit 3.8 test suite containing all test cases. |
115 | */ |
116 | public static junit.framework.Test suite() { |
117 | TestSuite s = new TestSuite(); |
118 | s.addTest(new JUnit4TestAdapter(PacmanTest.class)); |
119 | return s; |
120 | } |
121 | |
122 | |
123 | /** |
124 | * Actually exercise the Pacman test suite. |
125 | * |
126 | * @param args All arguments are ignored. |
127 | */ |
128 | public static void main(String[] args) { |
129 | junit.textui.TestRunner.run(jpacman.PacmanTest.suite()); |
130 | } |
131 | } |