-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerTest.java
More file actions
49 lines (40 loc) · 1.29 KB
/
PlayerTest.java
File metadata and controls
49 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.awt.Color;
import static org.junit.jupiter.api.Assertions.*;
class PlayerTest {
public static Player p;
@BeforeAll
public static void setUp() {
p = new Player("Timmy");
}
@Test
public void getName() {
assertEquals("Timmy", p.getName());
}
@Test
public void getScore() {
assertEquals(0, p.getScore());
}
@Test
public void increaseScore() {
Player p2 = new Player("Ashley");
assertEquals(0, p2.getScore());
assertEquals(7, p2.increaseScore(7));
assertEquals(7, p2.getScore());
}
@Test
public void test_equals() {
assertEquals(p, new Player("Timmy"));
assertNotEquals(p, null);
assertNotEquals(p, Color.BLUE);
assertNotEquals(p, new Player("Ashley"));
}
@Test
public void testPreconditions() {
assertThrows(IllegalArgumentException.class, () -> new Player(null));
assertThrows(IllegalArgumentException.class, () -> new Player(""));
assertThrows(IllegalArgumentException.class, () -> p.increaseScore(-1));
assertThrows(IllegalArgumentException.class, () -> p.increaseScore(0));
}
}