Repository navigation
Expand file tree
/
Copy pathCommandTempTest.java
More file actions
64 lines (49 loc) · 2.46 KB
/
Copy pathCommandTempTest.java
File metadata and controls
64 lines (49 loc) · 2.46 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package bwapi;
import org.junit.Test;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
public class CommandTempTest {
@Test
public void upgradeShouldSubtractGasInsteadOfAdding() {
Game game = spy(new Game());
doReturn(10).when(game).getFrameCount();
ClientData.PlayerData playerData = mock(ClientData.PlayerData.class);
when(playerData.getName()).thenReturn("Self");
when(playerData.getMinerals()).thenReturn(500);
when(playerData.getGas()).thenReturn(500);
Player player = new Player(playerData, 0, game);
Unit unit = spy(new Unit(mock(ClientData.UnitData.class), 0, game));
doReturn(true).when(unit).exists();
doReturn(player).when(unit).getPlayer();
UpgradeType upgrade = UpgradeType.Terran_Infantry_Weapons;
CommandTemp cmd = new CommandTemp(UnitCommand.upgrade(unit, upgrade), game);
cmd.execute(false);
assertEquals(500 - upgrade.mineralPrice(1), player.minerals());
assertEquals(500 - upgrade.gasPrice(1), player.gas());
}
@Test
public void cancelTrainSlotShouldShiftQueueWithoutIndexOutOfBounds() {
Game game = spy(new Game());
doReturn(10).when(game).getFrameCount();
ClientData.PlayerData playerData = mock(ClientData.PlayerData.class);
when(playerData.getName()).thenReturn("Self");
Player player = new Player(playerData, 0, game);
ClientData.UnitData unitData = mock(ClientData.UnitData.class);
when(unitData.getExists()).thenReturn(true);
when(unitData.getTrainingQueueCount()).thenReturn(2);
when(unitData.getTrainingQueue(0)).thenReturn(UnitType.Terran_Marine.id);
when(unitData.getTrainingQueue(1)).thenReturn(UnitType.Terran_Medic.id);
when(unitData.getTrainingQueue(2)).thenReturn(UnitType.None.id);
when(unitData.getTrainingQueue(3)).thenReturn(UnitType.None.id);
when(unitData.getTrainingQueue(4)).thenReturn(UnitType.None.id);
Unit unit = spy(new Unit(unitData, 0, game));
doReturn(player).when(unit).getPlayer();
CommandTemp cmd = new CommandTemp(UnitCommand.cancelTrain(unit, 1), game);
cmd.execute(false);
assertEquals(Collections.singletonList(UnitType.Terran_Marine), unit.getTrainingQueue());
}
}