-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathGitCommitIdMojoTest.java
More file actions
138 lines (129 loc) · 4.71 KB
/
GitCommitIdMojoTest.java
File metadata and controls
138 lines (129 loc) · 4.71 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
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* This file is part of git-commit-id-maven-plugin
* Originally invented by Konrad 'ktoso' Malawski <konrad.malawski@java.pl>
*
* git-commit-id-maven-plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* git-commit-id-maven-plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with git-commit-id-maven-plugin. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.project13.maven.git;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
import java.time.Instant;
import java.util.Date;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
import pl.project13.core.PropertiesFileGenerator;
/**
* Testcases to verify that the git-commit-id works properly.
*/
@RunWith(JUnitParamsRunner.class)
public class GitCommitIdMojoTest {
@Test
public void testCraftPropertiesOutputFileWithRelativePath() throws IOException {
File baseDir = new File(".");
String targetDir = baseDir.getCanonicalPath() + File.separator;
String generateGitPropertiesFilePath =
"target" + File.separator + "classes" + File.separator + "git.properties";
File generateGitPropertiesFile = new File(generateGitPropertiesFilePath);
File result =
PropertiesFileGenerator.craftPropertiesOutputFile(baseDir, generateGitPropertiesFile);
assertThat(result.getCanonicalPath())
.isEqualTo(
new File(targetDir)
.toPath()
.resolve(generateGitPropertiesFilePath)
.toFile()
.getCanonicalPath());
}
@Test
public void testCraftPropertiesOutputFileWithFullPath() throws IOException {
File baseDir = new File(".");
String targetDir = baseDir.getCanonicalPath() + File.separator;
String generateGitPropertiesFilePath =
targetDir + "target" + File.separator + "classes" + File.separator + "git.properties";
File generateGitPropertiesFile = new File(generateGitPropertiesFilePath);
File result =
PropertiesFileGenerator.craftPropertiesOutputFile(baseDir, generateGitPropertiesFile);
assertThat(result.getCanonicalPath())
.isEqualTo(
new File(targetDir)
.toPath()
.resolve(generateGitPropertiesFilePath)
.toFile()
.getCanonicalPath());
}
/**
* test cases for output timestamp parsing.
* This timestamp is configured for Reproducible Builds' archive entries
* (https://maven.apache.org/guides/mini/guide-reproducible-builds.html). The value from <code>
* ${project.build.outputTimestamp}</code> is either formatted as ISO 8601 <code>
* yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like <a
* href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>.
* When using ISO 8601 formatting please note that the entire expression must be entirely either
* in the basic format (20240215T135459+0100) or in the
* extended format (e.g. 2024-02-15T13:54:59+01:00).
* The maven plugin only supports the extended format.
*/
private Object[] parametersParseOutputTimestamp() {
return new Object[] {
// long since epoch
new Object[] {
"1644689403"
},
// Date and time with timezone:
new Object[] {
"2022-02-12T15:30+00:00"
},
new Object[] {
"2022-02-12T15:30:45-05:00"
},
new Object[] {
"2022-02-12T15:30:00+00:00"
},
new Object[] {
"2023-11-30T09:17:06+05:30"
},
new Object[] {
"2024-08-15T20:45:30-03:00"
},
new Object[] {
"2022-02-12T15:30:00Z"
},
new Object[] {
"2023-11-30T09:17:06+0100"
},
// Lowercase time designator
new Object[] {
"2019-03-26t14:00Z"
},
// Lowercase UTC designator
new Object[] {
"2019-03-26T14:00z"
},
// Hours-only offset
new Object[] {
"2019-03-26T10:00-04"
},
};
}
@Test
@Parameters(method = "parametersParseOutputTimestamp")
public void testParseOutputTimestamp(String input) {
Date actual = GitCommitIdMojo.parseOutputTimestamp(input);
assertThat(actual).isNotNull();
}
}