-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScenarioTest.java
112 lines (97 loc) · 2.61 KB
/
ScenarioTest.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
102
103
104
105
106
107
108
109
110
111
112
package com.example.demo;
import com.example.demo.application.controller.ProductionController.SkipProductionRequest;
import com.example.demo.domain.Building;
import com.example.demo.domain.BuildingState;
import com.example.demo.domain.BuildingType;
import com.example.demo.domain.CityType;
import com.example.demo.domain.Player;
import com.example.demo.domain.ProductionType;
import com.example.demo.domain.Resource;
import com.innogames.scenariobuilder.Ref;
import org.junit.jupiter.api.Test;
/**
* Example tests that use the Scenario Builder
*/
public class ScenarioTest extends BaseIntegrationTest {
@Test
public void scenarioTest() {
var playerRef = new Ref<Player>();
var farmRef = new Ref<Building>();
scenarioBuilder.build(scenario -> scenario
.withPlayer(player -> player
.ref(playerRef)
.withCity(CityType.CAPITAL, city -> city
.withBuilding(BuildingType.FARM, farm -> farm
.ref(farmRef)
.withLevel(1)
.withPosition(11, 12)
.withProduction(ProductionType.FOOD, production -> production
.withAmount(20)
)
)
)
.withResource(Resource.FOOD, 0)
.withResource(Resource.GEMS, ProductionType.FOOD.getSkipCost())
)
);
var response = gameClientOf(playerRef).sendRequest("/production/skip", SkipProductionRequest.builder()
.buildingId(farmRef.get().getId())
.build());
assertThatResponse(response, res ->
res.isOk()
);
assertThatDatabaseOf(playerRef, db -> db
.resources(resources -> resources
.hasAmount(Resource.FOOD, 20)
.hasAmount(Resource.GEMS, 0)
)
.buildings(buildings -> buildings
.building(farmRef, farm -> farm
.hasState(BuildingState.IDLE)
)
)
);
}
@Test
public void allianceTest() {
var aliceRef = new Ref<Player>();
var bobRef = new Ref<Player>();
scenarioBuilder.build(scenario -> scenario
.withPlayer(player -> player
.ref(aliceRef)
.withName("alice")
)
.withPlayer(player -> player
.ref(bobRef)
.withName("bob")
)
.withAlliance(alliance -> alliance
.withName("Fireflies")
.withMember(aliceRef)
.withMember(bobRef)
)
);
// action and assertion here ...
}
@Test
public void tradeOfferTest() {
var aliceRef = new Ref<Player>();
var bobRef = new Ref<Player>();
scenarioBuilder.build(scenario -> scenario
.withPlayer(player -> player
.ref(aliceRef)
.withName("alice")
.withTradeOffer(tradeOffer -> tradeOffer
.withResource(Resource.WOOD)
.withAmount(100)
.withAcceptedBy(bobRef)
)
)
.withPlayer(player -> player
.ref(bobRef)
.withName("bob")
)
);
// action and assertion here ...
}
}