-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHeroTests.java
72 lines (59 loc) · 2.27 KB
/
HeroTests.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
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import rpgLab.Hero;
import rpgLab.interfaces.Target;
import rpgLab.interfaces.Weapon;
public class HeroTests {
private static final int DEFAULT_XP = 10;
private static final int DEFAULT_TARGET_HEALTH = 0;
private static final boolean DEFAULT_IS_TARGET_DEAD = Boolean.TRUE;
private static final int DEFAULT_WEAPON_ATTACK = 10;
private static final int DEFAULT_WEAPON_DURABILITY = 0;
public static final String HERO_NAME = "Pesho";
@Test
public void attackGainsExperienceIfTargetIsDead(){
Target mockTarget = Mockito.mock(Target.class);
Mockito.when(mockTarget.giveExperience()).thenReturn(DEFAULT_XP);
Mockito.when(mockTarget.isDead()).thenReturn(DEFAULT_IS_TARGET_DEAD);
/* Target fakeTarget = new Target() {
@Override
public int getHealth() {
return DEFAULT_TARGET_HEALTH;
}
@Override
public void takeAttack(int attackPoints) {}
@Override
public int giveExperience() {
return DEFAULT_XP;
}
@Override
public boolean isDead() {
return DEFAULT_IS_TARGET_DEAD;
}
};*/
Weapon mockWeapon = Mockito.mock(Weapon.class);
Mockito.when(mockWeapon.getAttackPoints()).thenReturn(DEFAULT_WEAPON_ATTACK);
Mockito.when(mockWeapon.getDurabilityPoints()).thenReturn(DEFAULT_WEAPON_DURABILITY);
/*
Weapon fakeWeapon = new Weapon() {
@Override
public int getAttackPoints() {
return DEFAULT_WEAPON_ATTACK;
}
@Override
public int getDurabilityPoints() {
return DEFAULT_WEAPON_DURABILITY;
}
@Override
public void attack(Target target) {
}
};*/
/*Hero hero = new Hero(HERO_NAME,fakeWeapon);
hero.attack(fakeTarget);
Assert.assertEquals(DEFAULT_XP,hero.getExperience());*/
Hero hero = new Hero(HERO_NAME,mockWeapon);
hero.attack(mockTarget);
Assert.assertEquals(DEFAULT_XP,hero.getExperience());
}
}