@@ -48,6 +48,44 @@ public void setUp() {
48
48
49
49
propertiesFileGenerator = new PropertiesFileGenerator (logInterface , buildFileChangeListener , "properties" , "" , "test" );
50
50
}
51
+
52
+ @ Test
53
+ public void generatedPropertiesFileDoesNotEscapeUnicode () throws GitCommitIdExecutionException , IOException {
54
+ Properties properties = new Properties ();
55
+ properties .put (GitCommitPropertyConstant .COMMIT_ID_FULL , "b5993378ffadd1f84dc8da220b9204d157ec0f29" );
56
+ properties .put (GitCommitPropertyConstant .BRANCH , "develop" );
57
+ properties .put (GitCommitPropertyConstant .COMMIT_MESSAGE_SHORT , "測試中文" );
58
+
59
+ Path propertiesPath = temporaryFolder .getRoot ().toPath ().resolve ("git.properties" );
60
+ propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 , false );
61
+
62
+ byte [] bytes = Files .readAllBytes (propertiesPath );
63
+ String actualContent = new String (bytes , UTF_8 );
64
+ String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
65
+ + "branch=develop\n "
66
+ + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n "
67
+ + "commit.message.short=測試中文\n " ;
68
+ assertEquals (expectedContent , actualContent );
69
+ }
70
+
71
+ @ Test
72
+ public void generatedPropertiesFileEscapeUnicode () throws GitCommitIdExecutionException , IOException {
73
+ Properties properties = new Properties ();
74
+ properties .put (GitCommitPropertyConstant .COMMIT_ID_FULL , "b5993378ffadd1f84dc8da220b9204d157ec0f29" );
75
+ properties .put (GitCommitPropertyConstant .BRANCH , "develop" );
76
+ properties .put (GitCommitPropertyConstant .COMMIT_MESSAGE_SHORT , "測試中文" );
77
+
78
+ Path propertiesPath = temporaryFolder .getRoot ().toPath ().resolve ("git.properties" );
79
+ propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 , true );
80
+
81
+ byte [] bytes = Files .readAllBytes (propertiesPath );
82
+ String actualContent = new String (bytes , UTF_8 );
83
+ String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
84
+ + "branch=develop\n "
85
+ + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n "
86
+ + "commit.message.short=\\ u6E2C\\ u8A66\\ u4E2D\\ u6587\n " ;
87
+ assertEquals (expectedContent , actualContent );
88
+ }
51
89
52
90
@ Test
53
91
public void generatedPropertiesFileDoesNotContainDateComment () throws GitCommitIdExecutionException , IOException {
@@ -56,7 +94,7 @@ public void generatedPropertiesFileDoesNotContainDateComment() throws GitCommitI
56
94
properties .put (GitCommitPropertyConstant .BRANCH , "develop" );
57
95
58
96
Path propertiesPath = temporaryFolder .getRoot ().toPath ().resolve ("git.properties" );
59
- propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 );
97
+ propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 , true );
60
98
61
99
byte [] bytes = Files .readAllBytes (propertiesPath );
62
100
String actualContent = new String (bytes , UTF_8 );
@@ -73,10 +111,10 @@ public void rereadGeneratedPropertiesFile() throws GitCommitIdExecutionException
73
111
properties .put (GitCommitPropertyConstant .BRANCH , "develop" );
74
112
75
113
Path propertiesPath = temporaryFolder .getRoot ().toPath ().resolve ("git.properties" );
76
- propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 );
114
+ propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 , true );
77
115
78
116
// Re-read the generated properties file.
79
- propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 );
117
+ propertiesFileGenerator .maybeGeneratePropertiesFile (properties , temporaryFolder .getRoot (), propertiesPath .getFileName ().toString (), UTF_8 , true );
80
118
81
119
byte [] bytes = Files .readAllBytes (propertiesPath );
82
120
String actualContent = new String (bytes , UTF_8 );
@@ -85,4 +123,4 @@ public void rereadGeneratedPropertiesFile() throws GitCommitIdExecutionException
85
123
+ "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " ;
86
124
assertEquals (expectedContent , actualContent );
87
125
}
88
- }
126
+ }
0 commit comments