1+ /*
2+ * This file is part of git-commit-id-plugin by Konrad 'ktoso' Malawski <[email protected] > 3+ *
4+ * git-commit-id-plugin is free software: you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation, either version 3 of the License, or
7+ * (at your option) any later version.
8+ *
9+ * git-commit-id-plugin is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License
15+ * along with git-commit-id-plugin. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+ package pl .project13 .core ;
19+
20+ import org .junit .Before ;
21+ import org .junit .Rule ;
22+ import org .junit .Test ;
23+ import org .junit .rules .TemporaryFolder ;
24+ import org .sonatype .plexus .build .incremental .BuildContext ;
25+ import org .sonatype .plexus .build .incremental .DefaultBuildContext ;
26+ import pl .project13 .core .log .LoggerBridge ;
27+ import pl .project13 .core .log .StdOutLoggerBridge ;
28+
29+ import java .io .IOException ;
30+ import java .nio .charset .StandardCharsets ;
31+ import java .nio .file .Files ;
32+ import java .nio .file .Path ;
33+ import java .util .Properties ;
34+
35+ import static java .nio .charset .StandardCharsets .UTF_8 ;
36+ import static org .junit .Assert .assertEquals ;
37+
38+ public class PropertiesFileGeneratorTest {
39+ @ Rule
40+ public final TemporaryFolder temporaryFolder = new TemporaryFolder ();
41+
42+ private final LoggerBridge loggerBridge = new StdOutLoggerBridge (false );
43+ private final BuildContext buildContext = new DefaultBuildContext ();
44+
45+ private PropertiesFileGenerator propertiesFileGenerator ;
46+
47+ @ Before
48+ public void setUp () {
49+ propertiesFileGenerator = new PropertiesFileGenerator (loggerBridge , buildContext , "properties" , "" , "test" );
50+ }
51+
52+ @ Test
53+ public void generatedPropertiesFileDoesNotContainDateComment () throws GitCommitIdExecutionException , IOException {
54+ Properties properties = new Properties ();
55+ properties .put (GitCommitPropertyConstant .COMMIT_ID_FULL , "b5993378ffadd1f84dc8da220b9204d157ec0f29" );
56+ properties .put (GitCommitPropertyConstant .BRANCH , "develop" );
57+
58+ Path propertiesPath = temporaryFolder .getRoot ().toPath ().resolve ("git.properties" );
59+ propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 );
60+
61+ byte [] bytes = Files .readAllBytes (propertiesPath );
62+ String actualContent = new String (bytes , UTF_8 );
63+ String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
64+ + "branch=develop\n "
65+ + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " ;
66+ assertEquals (expectedContent , actualContent );
67+ }
68+ }
0 commit comments