-
Notifications
You must be signed in to change notification settings - Fork 82
/
TestSolution5DateTimePartials.java
147 lines (115 loc) · 4.45 KB
/
TestSolution5DateTimePartials.java
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package none.cvg.datetime;
import java.time.Clock;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.MonthDay;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* DateTime partials: Month, MonthDay, Year, YearMonth and DayOfWeek tests.
* <p>
* Note: We create a Clock instance in setup() used for some of the tests.
*
* @see Clock
* @see Month
* @see MonthDay
* @see Year
* @see YearMonth
* @see DayOfWeek
*/
@DisplayNameGeneration(DateTimeKataDisplayNames.class)
@DisplayName("Date and Time partials such as credit card expiration")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestSolution5DateTimePartials {
private Clock terminatorOriginalJudgementDay = null;
@BeforeEach
public void setup() {
Instant instant = Instant.parse("1997-08-29T06:14:30Z");
// We make an assumption for GMT -4 as the timezone for users of this test.
terminatorOriginalJudgementDay = Clock.fixed(instant, ZoneId.of("GMT-4"));
}
@Test
@Tag("PASSING")
@Order(1)
public void verifyMonth() {
LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);
// DONE: Replace the "null" below get a Month instance.
// Check: java.time.LocalDateTime.getMonth()
Month tOJMonth = tOJDateTime.getMonth();
assertEquals(Month.AUGUST,
tOJMonth,
"The Month enumeration should match August.");
}
@Test
@Tag("PASSING")
@Order(2)
public void verifyMonthDay() {
// Real world: Birthday or anniversary
// DONE: Replace the MonthDay.now() below get a MonthDay anniversary for the Judgement Day.
// Check: java.time.MonthDay.now(java.time.Clock)
MonthDay anniversaryofJudgementDay = MonthDay.now(terminatorOriginalJudgementDay);
assertEquals(Month.AUGUST,
anniversaryofJudgementDay.getMonth(),
"The month enumeration should match August.");
assertEquals(8,
anniversaryofJudgementDay.getMonthValue(),
"The month value should match 8.");
assertEquals(29,
anniversaryofJudgementDay.getDayOfMonth(),
"The date value should match 29.");
}
@Test
@Tag("PASSING")
@Order(3)
public void verifyYear() {
// Real world: Age or Year of occurrence.
// DONE: Replace the Year.now() below get a Year for the Judgement Day.
// Check: java.time.Year.now(java.time.Clock)
Year yearOfJudgementDay = Year.now(terminatorOriginalJudgementDay);
assertEquals(1997,
yearOfJudgementDay.getValue(),
"The year value should match 1997.");
}
@Test
@Tag("PASSING")
@Order(4)
public void verifyYearMonth() {
// Real world: CreditCard or Medicine expiration.
// DONE: Replace the YearMonth.now() below get a YearMonth for the Judgement Day.
// Check: java.time.YearMonth.now(java.time.Clock)
YearMonth yearMonthOfJudgementDay = YearMonth.now(terminatorOriginalJudgementDay);
assertEquals(Month.AUGUST,
yearMonthOfJudgementDay.getMonth(),
"The month enumeration should match August.");
assertEquals(8,
yearMonthOfJudgementDay.getMonthValue(),
"The month value should match 8.");
assertEquals(1997,
yearMonthOfJudgementDay.getYear(),
"The year value should match 1997.");
}
@Test
@Tag("PASSING")
@Order(5)
public void verifyDayOfWeek() {
LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);
// DONE: Replace the null below to get the Day Of Week from the tOJDateTime.
// Check: java.time.LocalDateTime.getDayOfWeek()
DayOfWeek dayOfWeek = tOJDateTime.getDayOfWeek();
assertEquals(DayOfWeek.FRIDAY,
dayOfWeek,
"The day of the week enumeration should match Friday.");
}
}