Skip to content

Commit 88fae51

Browse files
author
TheSnoozer
committed
attempt to make tests work
1 parent 15f9901 commit 88fae51

File tree

1 file changed

+27
-86
lines changed

1 file changed

+27
-86
lines changed

src/test/java/pl/project13/maven/git/GitCommitIdMojoTest.java

Lines changed: 27 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
import java.io.File;
2424
import java.io.IOException;
25-
import java.time.Instant;
2625
import java.util.Date;
26+
2727
import junitparams.JUnitParamsRunner;
2828
import junitparams.Parameters;
29+
import org.joda.time.DateTime;
2930
import org.junit.Test;
3031
import org.junit.runner.RunWith;
3132
import pl.project13.core.PropertiesFileGenerator;
@@ -74,135 +75,75 @@ public void testCraftPropertiesOutputFileWithFullPath() throws IOException {
7475
}
7576

7677
private Object[] parametersParseOutputTimestamp() {
78+
/**
79+
* test cases for output timestamp parsing.
80+
* This timestamp is configured for Reproducible Builds' archive entries
81+
* (https://maven.apache.org/guides/mini/guide-reproducible-builds.html). The value from <code>
82+
* ${project.build.outputTimestamp}</code> is either formatted as ISO 8601 <code>
83+
* yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like <a
84+
* href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>.
85+
* When using ISO 8601 formatting please note that the entire expression must be entirely either
86+
* in the basic format (20240215T135459+0100) or in the
87+
* extended format (e.g. 2024-02-15T13:54:59+01:00).
88+
* The maven plugin only supports the extended format.
89+
*/
7790
return new Object[] {
7891
// long since epoch
7992
new Object[] {
8093
"1644689403",
81-
Instant.ofEpochMilli(1644689403000L)
82-
},
83-
// Date only:
84-
new Object[] {
85-
"2022-02",
86-
Instant.ofEpochMilli(1643670000000L)
87-
},
88-
new Object[] {
89-
"2022-02-12",
90-
Instant.ofEpochMilli(1644620400000L)
91-
},
92-
// Date and time:
93-
new Object[] {
94-
"2022-02-12T15:30",
95-
Instant.ofEpochMilli(1644676200000L)
96-
},
97-
new Object[] {
98-
"2022-02-12T15:30:45",
99-
Instant.ofEpochMilli(1644676245000L)
94+
new DateTime("2022-02-12T19:10:03").toDate()
10095
},
10196
// Date and time with timezone:
10297
new Object[] {
10398
"2022-02-12T15:30+00:00",
104-
Instant.ofEpochMilli(1644679800000L)
99+
new DateTime("2022-02-12T15:30:00+00:00").toDate()
105100
},
106101
new Object[] {
107102
"2022-02-12T15:30:45-05:00",
108-
Instant.ofEpochMilli(1644697845000L)
103+
new DateTime("2022-02-12T15:30:45-05:00").toDate()
109104
},
110105
new Object[] {
111106
"2022-02-12T15:30:00+00:00",
112-
Instant.ofEpochMilli(1644679800000L)
107+
new DateTime("2022-02-12T15:30:00+00:00").toDate()
113108
},
114109
new Object[] {
115110
"2023-11-30T09:17:06+05:30",
116-
Instant.ofEpochMilli(1701316026000L)
111+
new DateTime("2023-11-30T09:17:06+05:30").toDate()
117112
},
118113
new Object[] {
119114
"2024-08-15T20:45:30-03:00",
120-
Instant.ofEpochMilli(1723765530000L)
115+
new DateTime("2024-08-15T20:45:30-03:00").toDate()
121116
},
122117
new Object[] {
123118
"2022-02-12T15:30:00Z",
124-
Instant.ofEpochMilli(1644679800000L)
119+
new DateTime("2022-02-12T15:30:00Z").toDate()
125120
},
126-
// Not valid according to the ISO 8601 standard. The issue is with the time zone
127-
// representation. ISO 8601 uses a specific format for time zones, either as "Z" for UTC or
128-
// in the format "+HH:MM" or "-HH:MM" for the offset from UTC.
129-
// The time zone "EST" or "PST" does not follow this format.
130-
// new Object[] { "2023-11-30T09:17:06PST", null },
131-
// new Object[] { "2024-08-15T20:45:30EST", null },
132121
new Object[] {
133122
"2023-11-30T09:17:06+0100",
134-
Instant.ofEpochMilli(1701332226000L)
135-
},
136-
// Week date:
137-
new Object[] {
138-
"2022-W06",
139-
Instant.ofEpochMilli(1644188400000L)
140-
},
141-
new Object[] {
142-
"2022-W06-5",
143-
Instant.ofEpochMilli(1644534000000L)
144-
},
145-
// Week date with time:
146-
new Object[] {
147-
"2022-W06-5T15:30",
148-
Instant.ofEpochMilli(1644589800000L)
149-
},
150-
new Object[] {
151-
"2022-W06-5T15:30:45",
152-
Instant.ofEpochMilli(1644589845000L)
153-
},
154-
// https://tc39.es/proposal-uniform-interchange-date-parsing/cases.html
155-
// positive leap second
156-
// not working: new Object[] { "1972-06-30T23:59:60Z", null },
157-
// Too few fractional second digits
158-
new Object[] {
159-
"2019-03-26T14:00:00.9Z",
160-
Instant.ofEpochMilli(1553608800900L)
161-
},
162-
// Too many fractional second digits
163-
new Object[] {
164-
"2019-03-26T14:00:00.4999Z",
165-
Instant.ofEpochMilli(1553608800499L)
166-
},
167-
// Too many fractional second digits (pre-epoch)
168-
new Object[] {
169-
"1969-03-26T14:00:00.4999Z",
170-
Instant.ofEpochMilli(-24227999501L)
171-
},
172-
// Too many fractional second digits (BCE)
173-
new Object[] {
174-
"-000043-03-15T14:00:00.4999Z",
175-
Instant.ofEpochMilli(-63517773599501L)
123+
new DateTime("2023-11-30T09:17:06+01:00").toDate()
176124
},
177125
// Lowercase time designator
178126
new Object[] {
179127
"2019-03-26t14:00Z",
180-
Instant.ofEpochMilli(1553608800000L)
128+
new DateTime("2019-03-26T14:00Z").toDate()
181129
},
182130
// Lowercase UTC designator
183131
new Object[] {
184132
"2019-03-26T14:00z",
185-
Instant.ofEpochMilli(1553608800000L)
133+
new DateTime("2019-03-26T14:00:00Z").toDate()
186134
},
187135
// Hours-only offset
188136
new Object[] {
189137
"2019-03-26T10:00-04",
190-
Instant.ofEpochMilli(1553608800000L)
191-
},
192-
// Fractional minutes
193-
new Object[] {
194-
"2019-03-26T14:00.9Z",
195-
Instant.ofEpochMilli(1553608854000L)
138+
new DateTime("2019-03-26T10:00-04:00").toDate()
196139
},
197-
// ISO basic format date and time
198-
// not working: new Object[] { "20190326T1400Z", null },
199140
};
200141
}
201142

202143
@Test
203144
@Parameters(method = "parametersParseOutputTimestamp")
204-
public void testParseOutputTimestamp(String input, Instant expected) {
145+
public void testParseOutputTimestamp(String input, Date expected) {
205146
Date actual = GitCommitIdMojo.parseOutputTimestamp(input);
206-
assertThat(actual.toInstant()).isEqualTo(expected);
147+
assertThat(actual).isEqualTo(expected);
207148
}
208149
}

0 commit comments

Comments
 (0)