Skip to content

Commit b3e52ce

Browse files
✅ chore(test): Creature Recruitment | add test givenDwellingWhenExpectedCostDoesNotMatchActualCostThenException
1 parent 3a21bc8 commit b3e52ce

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/test/java/com/dddheroes/heroesofddd/creaturerecruitment/write/recruitcreature/RecruitCreatureTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.dddheroes.heroesofddd.shared.domain.identifiers.ArmyId;
88
import com.dddheroes.heroesofddd.shared.domain.identifiers.CreatureId;
99
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;
1012
import org.axonframework.modelling.command.AggregateNotFoundException;
1113
import org.junit.jupiter.api.*;
1214

@@ -183,12 +185,34 @@ void givenDwellingWithRecruitedSomeAvailableCreaturesAnd1LeftWhenRecruit1Creatur
183185
.expectEvents(thenEvent);
184186
}
185187

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+
186206
private RecruitCreature recruitCreature(int recruit) {
187207
return recruitCreature(angelId, recruit);
188208
}
189209

190210
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());
192216
}
193217

194218
private CreatureRecruited creatureRecruited(int quantity) {

0 commit comments

Comments
 (0)