|
7 | 7 | import com.dddheroes.heroesofddd.shared.domain.identifiers.ArmyId; |
8 | 8 | import com.dddheroes.heroesofddd.shared.domain.identifiers.CreatureId; |
9 | 9 | import com.dddheroes.heroesofddd.shared.domain.DomainRule; |
| 10 | +import com.dddheroes.heroesofddd.shared.domain.valueobjects.ResourceType; |
| 11 | +import com.dddheroes.heroesofddd.shared.domain.valueobjects.Resources; |
10 | 12 | import org.axonframework.modelling.command.AggregateNotFoundException; |
11 | 13 | import org.junit.jupiter.api.*; |
12 | 14 |
|
@@ -183,12 +185,34 @@ void givenDwellingWithRecruitedSomeAvailableCreaturesAnd1LeftWhenRecruit1Creatur |
183 | 185 | .expectEvents(thenEvent); |
184 | 186 | } |
185 | 187 |
|
| 188 | + @Test |
| 189 | + void givenDwellingWhenExpectedCostDoesNotMatchActualCostThenException() { |
| 190 | + // given |
| 191 | + var givenEvents = List.of( |
| 192 | + dwellingBuilt(), |
| 193 | + availableCreaturesChanged(1) |
| 194 | + ); |
| 195 | + |
| 196 | + // when |
| 197 | + var whenCommand = recruitCreature(angelId, 1, Resources.from(ResourceType.GOLD, Amount.of(999999))); |
| 198 | + |
| 199 | + // then |
| 200 | + fixture.given(givenEvents) |
| 201 | + .when(whenCommand) |
| 202 | + .expectException(DomainRule.ViolatedException.class) |
| 203 | + .expectExceptionMessage("Recruit cost cannot differ than expected cost"); |
| 204 | + } |
| 205 | + |
186 | 206 | private RecruitCreature recruitCreature(int recruit) { |
187 | 207 | return recruitCreature(angelId, recruit); |
188 | 208 | } |
189 | 209 |
|
190 | 210 | private RecruitCreature recruitCreature(CreatureId creatureId, int quantity) { |
191 | | - return RecruitCreature.command(dwellingId.raw(), creatureId.raw(), armyId.raw(), quantity, costPerTroop.multiply(Amount.of(quantity)).raw()); |
| 211 | + return recruitCreature(creatureId, quantity, costPerTroop.multiply(Amount.of(quantity))); |
| 212 | + } |
| 213 | + |
| 214 | + private RecruitCreature recruitCreature(CreatureId creatureId, int quantity, Resources expectedCost) { |
| 215 | + return RecruitCreature.command(dwellingId.raw(), creatureId.raw(), armyId.raw(), quantity, expectedCost.raw()); |
192 | 216 | } |
193 | 217 |
|
194 | 218 | private CreatureRecruited creatureRecruited(int quantity) { |
|
0 commit comments