SHOW:
|
|
- or go back to the newest paste.
1 | RunWith(JMock.class) | |
2 | public class WordGameTestMock { | |
3 | ||
4 | private WordGame wordGame ; | |
5 | char[] listTest= {'r','a','a','t','t','t','c'}; | |
6 | ||
7 | private Mockery context = new JUnit4Mockery(){{ | |
8 | setImposteriser(ClassImposteriser.INSTANCE); | |
9 | }}; | |
10 | ||
11 | ||
12 | @Before | |
13 | public void setup(){ | |
14 | ||
15 | ||
16 | ||
17 | } | |
18 | ||
19 | @Test | |
20 | public void testTryWordValidUpdateAddPoint() { | |
21 | final Hand mockHand = context.mock(Hand.class); | |
22 | final Player mockPlayer = context.mock(Player.class); | |
23 | final WordList stubWordList = context.mock(WordList.class); | |
24 | final LetterScoreList stubScore= context.mock(LetterScoreList.class); | |
25 | ||
26 | context.checking(new Expectations() {{ | |
27 | allowing(stubWordList).containsWordList("rat"); | |
28 | will(returnValue(true)); | |
29 | allowing(mockHand).containsLetters("rat"); | |
30 | will(returnValue(true)); | |
31 | allowing(stubScore).getWordScores("rat"); | |
32 | will(returnValue(5)); | |
33 | allowing(mockPlayer).getHand(); | |
34 | will(returnValue(mockHand)); | |
35 | ||
36 | oneOf(mockPlayer).addPoints(5); | |
37 | oneOf(mockHand).update("rat"); | |
38 | ||
39 | ||
40 | ||
41 | }}); | |
42 | ||
43 | ||
44 | wordGame = new WordGame(listTest.length, stubWordList, stubScore, mockPlayer); | |
45 | ||
46 | - | assertEquals(point,wordGame.tryWord("rat")); |
46 | + | assertEquals(5,wordGame.tryWord("rat")); |
47 | ||
48 | ||
49 | ||
50 | ||
51 | ||
52 | } | |
53 | ||
54 | @Test | |
55 | public void testTryWordValidFalseListNotFound() { | |
56 | final Hand mockHand = context.mock(Hand.class); | |
57 | final Player mockPlayer = context.mock(Player.class); | |
58 | final WordList stubWordList = context.mock(WordList.class); | |
59 | final LetterScoreList stubScore= context.mock(LetterScoreList.class); | |
60 | ||
61 | context.checking(new Expectations() {{ | |
62 | allowing(stubWordList).containsWordList("ABC"); | |
63 | will(returnValue(false)); | |
64 | ||
65 | ||
66 | }}); | |
67 | ||
68 | ||
69 | wordGame = new WordGame(listTest.length, stubWordList, stubScore, mockPlayer); | |
70 | ||
71 | ||
72 | assertEquals(0,wordGame.tryWord("ABC")); | |
73 | ||
74 | ||
75 | } | |
76 | ||
77 | @Test | |
78 | public void testTryWordSequence(){ | |
79 | final Hand mockHand = context.mock(Hand.class); | |
80 | final Player mockPlayer = context.mock(Player.class); | |
81 | final WordList stubWordList = context.mock(WordList.class); | |
82 | final LetterScoreList stubScore= context.mock(LetterScoreList.class); | |
83 | ||
84 | final Sequence trySeq = context.sequence("tryWord seq"); | |
85 | ||
86 | ||
87 | context.checking(new Expectations() {{ | |
88 | oneOf(stubWordList).containsWordList("rat"); | |
89 | will(returnValue(true)); | |
90 | inSequence(trySeq); | |
91 | ||
92 | oneOf(mockPlayer).getHand(); | |
93 | will(returnValue(mockHand)); | |
94 | inSequence(trySeq); | |
95 | ||
96 | oneOf(mockHand).containsLetters("rat"); | |
97 | will(returnValue(true)); | |
98 | inSequence(trySeq); | |
99 | ||
100 | ||
101 | oneOf(stubScore).getWordScores("rat"); | |
102 | - | will(returnValue(point)); |
102 | + | |
103 | ||
104 | oneOf(mockPlayer).getHand(); | |
105 | will(returnValue(mockHand)); | |
106 | inSequence(trySeq); | |
107 | ||
108 | oneOf(mockHand).update("rat"); | |
109 | inSequence(trySeq); | |
110 | ||
111 | oneOf(mockPlayer).addPoints(5); | |
112 | inSequence(trySeq); | |
113 | ||
114 | ||
115 | }}); | |
116 | ||
117 | wordGame = new WordGame(listTest.length, stubWordList, stubScore, mockPlayer); | |
118 | ||
119 | wordGame.tryWord("rat"); | |
120 | ||
121 | ||
122 | } | |
123 | ||
124 | ||
125 | ||
126 | ||
127 | } |