-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemoveCreatureFromArmyTest.java
More file actions
86 lines (70 loc) · 2.87 KB
/
RemoveCreatureFromArmyTest.java
File metadata and controls
86 lines (70 loc) · 2.87 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.dddheroes.heroesofddd.armies.write.removecreature;
import com.dddheroes.heroesofddd.armies.write.ArmyTest;
import com.dddheroes.heroesofddd.shared.domain.valueobjects.Amount;
import com.dddheroes.heroesofddd.shared.domain.identifiers.CreatureId;
import com.dddheroes.heroesofddd.shared.CreatureIds;
import com.dddheroes.heroesofddd.shared.domain.DomainRule;
import org.axonframework.modelling.command.AggregateNotFoundException;
import org.junit.jupiter.api.*;
import java.util.List;
class RemoveCreatureFromArmyTest extends ArmyTest {
@Test
void givenEmptyArmy_WhenRemoveCreatureFromArmy_ThenException() {
// given
var givenEvents = List.of();
// when
var whenCommand = removeCreatureFromArmy(CreatureIds.angel(), 1);
// then
fixture.given(givenEvents)
.when(whenCommand)
.expectException(AggregateNotFoundException.class);
}
@Test
void givenSomeStacksInArmy_WhenRemovePresentCreatureFromArmy_ThenSuccess() {
// given
var givenEvents = List.of(
creatureAddedToArmy(CreatureIds.centaur(), 5),
creatureAddedToArmy(CreatureIds.bowman(), 99)
);
// when
var whenCommand = removeCreatureFromArmy(CreatureIds.centaur(), 5);
// then
var thenEvent = creatureRemovedFromArmy(CreatureIds.centaur(), 5);
fixture.given(givenEvents)
.when(whenCommand)
.expectEvents(thenEvent);
}
@Test
void givenSomeStacksInArmy_WhenRemoveNotPresentCreatureFromArmy_ThenException() {
// given
var givenEvents = List.of(
creatureAddedToArmy(CreatureIds.centaur(), 5),
creatureAddedToArmy(CreatureIds.bowman(), 99)
);
// when
var whenCommand = removeCreatureFromArmy(CreatureIds.angel(), 5);
// then
fixture.given(givenEvents)
.when(whenCommand)
.expectException(DomainRule.ViolatedException.class)
.expectExceptionMessage("Can remove only present creatures");
}
@Test
void givenSomeStacksInArmy_WhenRemoveMoreCreatureThanPresentFromArmy_ThenException() {
// given
var givenEvents = List.of(
creatureAddedToArmy(CreatureIds.centaur(), 5),
creatureAddedToArmy(CreatureIds.bowman(), 99)
);
// when
var whenCommand = removeCreatureFromArmy(CreatureIds.centaur(), 6);
// then
fixture.given(givenEvents)
.when(whenCommand)
.expectException(DomainRule.ViolatedException.class)
.expectExceptionMessage("Can remove only present creatures");
}
protected RemoveCreatureFromArmy removeCreatureFromArmy(CreatureId creatureId, int quantity) {
return new RemoveCreatureFromArmy(armyId, creatureId, Amount.of(quantity));
}
}