File tree 4 files changed +106
-0
lines changed
main/java/com/testing/javatest/player
test/java/com/testing/javatest/player
4 files changed +106
-0
lines changed Original file line number Diff line number Diff line change 19
19
<version >4.12</version >
20
20
<scope >test</scope >
21
21
</dependency >
22
+ <dependency >
23
+ <groupId >org.mockito</groupId >
24
+ <artifactId >mockito-core</artifactId >
25
+ <version >2.23.4</version >
26
+ <scope >test</scope >
27
+ </dependency >
28
+
22
29
</dependencies >
23
30
</project >
Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ */
4
+ package com .testing .javatest .player ;
5
+
6
+ import java .util .Random ;
7
+
8
+ /**
9
+ * Clase que representa un dado que usa la clase {@link Player}
10
+ *
11
+ *
12
+ * @author sumel
13
+ *
14
+ */
15
+ public class Dice {
16
+
17
+ private int sides ;
18
+
19
+ public Dice (int sides ) {
20
+
21
+ this .sides = sides ;
22
+ }
23
+
24
+ public int roll () {
25
+ return new Random ().nextInt (sides ) + 1 ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ */
4
+ package com .testing .javatest .player ;
5
+
6
+ /**
7
+ * Clase que representa un jugador
8
+ *
9
+ * @author sumel
10
+ *
11
+ */
12
+ public class Player {
13
+ private Dice dice ;
14
+ private int mimNumberToWin ;
15
+
16
+ public Player (Dice dice , int mimNumberToWin ) {
17
+ this .dice = dice ;
18
+ this .mimNumberToWin = mimNumberToWin ;
19
+ }
20
+
21
+ public boolean play () {
22
+ int diceNumber = dice .roll ();
23
+ return diceNumber > mimNumberToWin ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ */
4
+ package com .testing .javatest .player ;
5
+
6
+ import org .junit .Test ;
7
+
8
+ import static org .junit .Assert .assertEquals ;
9
+ import static org .junit .Assert .assertFalse ;
10
+ import static org .junit .Assert .assertTrue ;
11
+
12
+ import org .junit .Assert .*;
13
+ import org .mockito .Mockito ;
14
+
15
+ /**
16
+ * Clase de test para la clase {@link Player}
17
+ *
18
+ * @author sumel
19
+ *
20
+ */
21
+ public class PlayerTest {
22
+
23
+ @ Test
24
+ public void lossesPlayerWhenIsTooLow () {
25
+ //Dice dice = new Dice(6);
26
+ Dice dice = Mockito .mock (Dice .class );
27
+ Mockito .when (dice .roll ()).thenReturn (2 );
28
+
29
+ Player player = new Player (dice , 3 );
30
+
31
+ //assertEquals(false, player.play());
32
+ assertFalse (player .play ());
33
+ }
34
+
35
+ @ Test
36
+ public void WinPlayerWhenIsBig () {
37
+
38
+ Dice dice = Mockito .mock (Dice .class );
39
+ Mockito .when (dice .roll ()).thenReturn (4 );
40
+
41
+ Player player = new Player (dice , 3 );
42
+
43
+ //assertEquals(true, player.play());
44
+ assertTrue (player .play ());
45
+ }
46
+ }
47
+
You can’t perform that action at this time.
0 commit comments