-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIncreaseAvailableCreaturesTest.java
More file actions
70 lines (56 loc) · 2.23 KB
/
IncreaseAvailableCreaturesTest.java
File metadata and controls
70 lines (56 loc) · 2.23 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
package com.dddheroes.heroesofddd.creaturerecruitment.write.changeavailablecreatures;
import com.dddheroes.heroesofddd.creaturerecruitment.events.AvailableCreaturesChanged;
import com.dddheroes.heroesofddd.creaturerecruitment.write.DwellingTest;
import com.dddheroes.heroesofddd.shared.domain.valueobjects.Amount;
import org.axonframework.modelling.command.AggregateNotFoundException;
import org.junit.jupiter.api.*;
import java.util.List;
class IncreaseAvailableCreaturesTest extends DwellingTest {
@Test
void givenNotBuildDwellingWhenIncreaseAvailableCreaturesThenException() {
// given
var givenEvents = List.of();
// when
var whenCommand = increaseAvailableCreatures(3);
// then
var thenEvent = availableCreaturesChanged(3);
fixture.given(givenEvents)
.when(whenCommand)
.expectException(AggregateNotFoundException.class);
}
@Test
void givenBuiltDwellingWhenIncreaseAvailableCreaturesThenAvailableCreaturesChanged() {
// given
var givenEvents = List.of(
dwellingBuilt()
);
// when
var whenCommand = increaseAvailableCreatures(3);
// then
var thenEvent = availableCreaturesChanged(3);
fixture.given(givenEvents)
.when(whenCommand)
.expectEvents(thenEvent);
}
@Test
void givenBuiltDwellingWithAvailableCreaturesWhenIncreaseAvailableCreaturesThenAvailableCreaturesChanged() {
// given
var givenEvents = List.of(
dwellingBuilt(),
availableCreaturesChanged(1)
);
// when
var whenCommand = increaseAvailableCreatures(3);
// then
var thenEvent = availableCreaturesChanged(4);
fixture.given(givenEvents)
.when(whenCommand)
.expectEvents(thenEvent);
}
protected IncreaseAvailableCreatures increaseAvailableCreatures(int increaseBy) {
return IncreaseAvailableCreatures.command(dwellingId.raw(), angelId.raw(), increaseBy);
}
private AvailableCreaturesChanged availableCreaturesChanged(int changedTo) {
return AvailableCreaturesChanged.event(dwellingId, angelId, Amount.of(changedTo));
}
}