-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoldierTest.java
50 lines (48 loc) · 1.65 KB
/
SoldierTest.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
import org.junit.Test;
import static org.junit.Assert.*;
public class SoldierTest {
@Test
public void createSoldierTest(){
General general = new General();
CorporalSoldier sut = new CorporalSoldier(general);
assertNotNull(sut);
}
@Test(expected = IllegalArgumentException.class)
public void setExperienceFail(){
General general = new General();
CorporalSoldier sut = new CorporalSoldier(general);
sut.setExperience(-2);
}
@Test
public void addExperienceTest(){
General general = new General();
CorporalSoldier sut = new CorporalSoldier(general);
sut.addExperience();
assertEquals(2, sut.getExperience());
}
@Test
public void canAdvanceTest(){
General general = new General();
CorporalSoldier sut = new CorporalSoldier(general);
sut.setExperience(11);
assertTrue(sut.canAdvance());
}
@Test
public void deathTest(){
General general = new General();
CorporalSoldier sut = new CorporalSoldier(general);
sut.setExperience(0);
sut.executeDeath(sut.isDead());
Soldier[] empty = {};
assertArrayEquals(empty, general.getSoldiers().toArray());
}
@Test
public void advanceTest(){
General general = new General();
CorporalSoldier sut = new CorporalSoldier(general);
sut.setExperience(11);
sut.executeAdvance(sut.canAdvance());
Soldier[] arrayTest = {new CapitanSoldier(general)};
assertEquals(arrayTest[0].getClass(), general.getSoldiers().toArray()[0].getClass());
}
}