-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStartDayTest.java
More file actions
125 lines (107 loc) · 5.22 KB
/
StartDayTest.java
File metadata and controls
125 lines (107 loc) · 5.22 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.dddheroes.heroesofddd.calendar.write.startday;
import com.dddheroes.heroesofddd.calendar.events.DayStarted;
import com.dddheroes.heroesofddd.calendar.write.CalendarId;
import com.dddheroes.heroesofddd.calendar.write.CalendarTest;
import com.dddheroes.heroesofddd.calendar.write.Day;
import com.dddheroes.heroesofddd.calendar.write.Month;
import com.dddheroes.heroesofddd.calendar.write.Week;
import com.dddheroes.heroesofddd.calendar.events.DayFinished;
import com.dddheroes.heroesofddd.shared.domain.DomainRule;
import org.junit.jupiter.api.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class StartDayTest extends CalendarTest {
@Test
void givenNoPreviousDay_WhenStartDay_ThenSuccess() {
// given
var calendarId = CalendarId.random();
// when
var whenCommand = StartDay.command(calendarId.raw(), 1, 1, 1);
// then
var thenEvent = DayStarted.event(calendarId, Month.of(1), Week.of(1), Day.of(1));
fixture.givenNoPriorActivity()
.when(whenCommand)
.expectEvents(thenEvent);
}
@Test
void givenPreviousDayFinished_WhenStartNextDay_ThenSuccess() {
// given
var calendarId = CalendarId.random();
var givenEvents = List.of(
DayStarted.event(calendarId, Month.of(1), Week.of(1), Day.of(1)),
DayFinished.event(calendarId, Month.of(1), Week.of(1), Day.of(1))
);
// when
var whenCommand = StartDay.command(calendarId.raw(), 1, 1, 2);
// then
var thenEvent = DayStarted.event(calendarId, Month.of(1), Week.of(1), Day.of(2));
fixture.given(givenEvents)
.when(whenCommand)
.expectEvents(thenEvent);
}
@Test
void givenPreviousDayFinished_WhenStartDaySkipping_ThenException() {
// given
var calendarId = CalendarId.random();
var givenEvents = List.of(
DayStarted.event(calendarId, Month.of(1), Week.of(1), Day.of(1)),
DayFinished.event(calendarId, Month.of(1), Week.of(1), Day.of(1))
);
// when
var whenCommand = StartDay.command(calendarId.raw(), 1, 1, 3);
// then
fixture.given(givenEvents)
.when(whenCommand)
.expectException(DomainRule.ViolatedException.class)
.expectExceptionMessage("Cannot skip days");
}
@Test
void givenLastDayOfFinished_WhenStartDayOfNextWeek_ThenNewWeekStarted() {
// given
var calendarId = CalendarId.random();
var givenEvents = IntStream.rangeClosed(1, 7)
.mapToObj(day -> List.of(
DayStarted.event(calendarId, Month.of(1), Week.of(1), Day.of(day)),
DayFinished.event(calendarId, Month.of(1), Week.of(1), Day.of(day))
))
.flatMap(List::stream)
.collect(Collectors.toList());
// when
var whenCommand = StartDay.command(calendarId.raw(), 1, 2, 1);
// then
var thenEvent = DayStarted.event(calendarId, Month.of(1), Week.of(2), Day.of(1));
fixture.given(givenEvents)
.when(whenCommand)
.expectEvents(thenEvent);
}
@Test
void givenLastDayOfMonthFinished_WhenStartDayOfNextMonth_ThenNewMonthStarted() {
// given
var calendarId = CalendarId.random();
var givenEvents = IntStream.rangeClosed(1, 4)
.mapToObj(week -> IntStream.rangeClosed(1, 7)
.mapToObj(day -> List.of(
DayStarted.event(calendarId,
Month.of(1),
Week.of(week),
Day.of(day)),
DayFinished.event(calendarId,
Month.of(1),
Week.of(week),
Day.of(day))
))
.flatMap(List::stream)
.collect(Collectors.toList())
)
.flatMap(List::stream)
.collect(Collectors.toList());
// when
var whenCommand = StartDay.command(calendarId.raw(), 2, 1, 1);
// then
var thenEvent = DayStarted.event(calendarId, Month.of(2), Week.of(1), Day.of(1));
fixture.given(givenEvents)
.when(whenCommand)
.expectEvents(thenEvent);
}
}