-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneralTest.java
101 lines (94 loc) · 3.77 KB
/
GeneralTest.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import org.junit.Test;
import static org.junit.Assert.*;
public class GeneralTest {
@Test
public void createGeneral(){
General sut = new General();
assertNotNull(sut);
}
@Test
public void removeSoldier(){
General sut = new General();
CorporalSoldier corporal = new CorporalSoldier(sut);
sut.removeSoldier(corporal);
assertEquals(0, sut.getSoldiers().size());
}
@Test
public void addArmyExperience(){
General sut = new General();
CorporalSoldier corporal = new CorporalSoldier(sut);
MajorSoldier major = new MajorSoldier(sut);
sut.addArmyExperience();
assertEquals(2, sut.getSoldiers().get(0).getExperience());
assertEquals(2, sut.getSoldiers().get(1).getExperience());
assertEquals(18, sut.getBalance());
}
@Test
public void addExperience(){
General sut = new General();
CorporalSoldier corporal = new CorporalSoldier(sut);
MajorSoldier major = new MajorSoldier(sut);
MajorSoldier major2 = new MajorSoldier(sut);
sut.addSoldiersExperience(major.getClass(), 1);
assertEquals(1, sut.getSoldiers().get(0).getExperience());
assertEquals(2, sut.getSoldiers().get(1).getExperience());
assertEquals(1, sut.getSoldiers().get(2).getExperience());
assertEquals(19, sut.getBalance());
}
@Test(expected = IllegalArgumentException.class)
public void tooMaySoldiersTest(){
General sut = new General();
CorporalSoldier corporal = new CorporalSoldier(sut);
MajorSoldier major = new MajorSoldier(sut);
MajorSoldier major2 = new MajorSoldier(sut);
sut.addSoldiersExperience(major.getClass(), 4);
assertEquals(1, sut.getSoldiers().get(0).getExperience());
assertEquals(2, sut.getSoldiers().get(1).getExperience());
assertEquals(1, sut.getSoldiers().get(2).getExperience());
assertEquals(19, sut.getBalance());
}
@Test
public void attackGeneralTest(){
General sut = new General();
CorporalSoldier corporal = new CorporalSoldier(sut);
MajorSoldier major = new MajorSoldier(sut);
MajorSoldier major2 = new MajorSoldier(sut);
General sut1 = new General();
PrivateSoldier ps1 = new PrivateSoldier(sut1);
PrivateSoldier ps2 = new PrivateSoldier(sut1);
PrivateSoldier ps3 = new PrivateSoldier(sut1);
sut.attackGeneral(sut1);
assertEquals(18, sut1.getBalance());
assertEquals(22, sut.getBalance());
}
@Test
public void drawTest(){
General sut = new General();
CorporalSoldier corporal = new CorporalSoldier(sut);
MajorSoldier major = new MajorSoldier(sut);
MajorSoldier major2 = new MajorSoldier(sut);
General sut1 = new General();
CorporalSoldier corporal3 = new CorporalSoldier(sut1);
MajorSoldier major4 = new MajorSoldier(sut1);
MajorSoldier major5 = new MajorSoldier(sut1);
sut.attackGeneral(sut1);
assertEquals(2, sut.getSoldiers().size());
assertEquals(2, sut1.getSoldiers().size());
}
@Test
public void calculateArmyStrengthTest(){
General sut = new General();
CorporalSoldier corporal = new CorporalSoldier(sut);
MajorSoldier major = new MajorSoldier(sut);
MajorSoldier major2 = new MajorSoldier(sut);
int strength = sut.calculateArmyStrength(sut);
assertEquals(10, strength);
}
@Test
public void buySoldiersTest(){
General sut = new General();
sut.buySoldier("private", 2);
assertEquals(2, sut.getSoldiers().size());
assertEquals(0, sut.getBalance());
}
}