-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFinishDayTest.java
More file actions
67 lines (55 loc) · 2.2 KB
/
FinishDayTest.java
File metadata and controls
67 lines (55 loc) · 2.2 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
package com.dddheroes.heroesofddd.calendar.write.finishday;
import com.dddheroes.heroesofddd.calendar.events.DayFinished;
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.DayStarted;
import com.dddheroes.heroesofddd.shared.domain.DomainRule;
import org.axonframework.modelling.command.AggregateNotFoundException;
import org.junit.jupiter.api.*;
import java.util.List;
public class FinishDayTest extends CalendarTest {
@Test
void givenNoPreviousDay_WhenFinishDay_ThenException() {
// given
var calendarId = CalendarId.random();
// when
var whenCommand = FinishDay.command(calendarId.raw(), 1, 1, 1);
// then
fixture.givenNoPriorActivity()
.when(whenCommand)
.expectException(AggregateNotFoundException.class);
}
@Test
void givenDayStarted_WhenFinishCurrentDay_ThenSuccess() {
// given
var calendarId = CalendarId.random();
var givenEvents = List.of(
DayStarted.event(calendarId, Month.of(1), Week.of(1), Day.of(1))
);
// when
var whenCommand = FinishDay.command(calendarId.raw(), 1, 1, 1);
// then
var thenEvent = DayFinished.event(calendarId, Month.of(1), Week.of(1), Day.of(1));
fixture.given(givenEvents)
.when(whenCommand)
.expectEvents(thenEvent);
}
@Test
void givenDayStarted_WhenFinishNotCurrent_ThenException() {
// given
var calendarId = CalendarId.random();
var givenEvents = List.of(
DayStarted.event(calendarId, Month.of(1), Week.of(1), Day.of(1))
);
// when
var whenCommand = FinishDay.command(calendarId.raw(), 1, 1, 2);
// then
fixture.given(givenEvents)
.when(whenCommand)
.expectException(DomainRule.ViolatedException.class)
.expectExceptionMessage("Can only finish current day");
}
}