1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.basepom.mojo.propertyhelper.fields;
15
16 import static org.assertj.core.api.Assertions.assertThat;
17 import static org.basepom.mojo.propertyhelper.definitions.DefinitionHelper.dateDefinition;
18 import static org.basepom.mojo.propertyhelper.definitions.DefinitionHelper.setInitialValue;
19
20 import org.basepom.mojo.propertyhelper.FieldContext;
21 import org.basepom.mojo.propertyhelper.ValueCache;
22 import org.basepom.mojo.propertyhelper.ValueProvider.SingleValueProvider;
23 import org.basepom.mojo.propertyhelper.definitions.DateDefinition;
24
25 import java.time.Instant;
26 import java.time.ZoneId;
27 import java.time.ZonedDateTime;
28 import java.time.format.DateTimeFormatter;
29
30 import org.junit.jupiter.api.Test;
31
32 class TestDateFieldOverrides {
33
34 @Test
35 void testZeroValue() throws Exception {
36 DateDefinition dateDefinition = dateDefinition("hello");
37 setInitialValue(dateDefinition, "0");
38
39 ZonedDateTime localEpochTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0), ZoneId.systemDefault());
40
41 var context = FieldContext.forTesting();
42 ValueCache valueCache = new ValueCache();
43 var dateField = dateDefinition.createField(context, valueCache);
44 var value = dateField.getValue();
45
46 assertThat(value).isEqualTo(DateTimeFormatter.ISO_DATE_TIME.format(localEpochTime));
47 }
48
49 @Test
50 void testLoadedValueOverridesInitialValue() throws Exception {
51 DateDefinition dateDefinition = dateDefinition("hello");
52 setInitialValue(dateDefinition, "0");
53
54 ZonedDateTime localEpochPlusOneTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1), ZoneId.systemDefault());
55
56 var valueProvider = new SingleValueProvider();
57 valueProvider.setValue("1");
58 var dateField = DateField.forTesting(dateDefinition, valueProvider);
59
60 var value = dateField.getValue();
61
62 assertThat(value).isEqualTo(DateTimeFormatter.ISO_DATE_TIME.format(localEpochPlusOneTime));
63 }
64 }