@@ -51,6 +51,13 @@ public void setUp() {
5151 propertiesFileGenerator = new PropertiesFileGenerator (logInterface , buildFileChangeListener , CommitIdPropertiesOutputFormat .PROPERTIES , "" , "test" );
5252 }
5353
54+ /**
55+ * Replaces {@code \n} with the OS-specific line break characters.
56+ */
57+ private static String convertLineBreaks (String s ) {
58+ return s .replace ("\n " , System .lineSeparator ());
59+ }
60+
5461 @ Test
5562 public void generatedPropertiesFileDoesNotEscapeUnicode () throws GitCommitIdExecutionException , IOException {
5663 Properties properties = new Properties ();
@@ -62,12 +69,11 @@ public void generatedPropertiesFileDoesNotEscapeUnicode() throws GitCommitIdExec
6269 propertiesFileGenerator .maybeGeneratePropertiesFile (
6370 properties , temporaryFolder .getRoot (), propertiesPath .toFile (), UTF_8 , false );
6471
65- byte [] bytes = Files .readAllBytes (propertiesPath );
66- String actualContent = new String (bytes , UTF_8 );
67- String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
72+ String actualContent = Files .readString (propertiesPath , UTF_8 );
73+ String expectedContent = convertLineBreaks ("#Generated by Git-Commit-Id-Plugin\n "
6874 + "branch=develop\n "
6975 + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n "
70- + "commit.message.short=測試中文\n " ;
76+ + "commit.message.short=測試中文\n " ) ;
7177 assertEquals (expectedContent , actualContent );
7278 }
7379
@@ -82,12 +88,11 @@ public void generatedPropertiesFileEscapeUnicode() throws GitCommitIdExecutionEx
8288 propertiesFileGenerator .maybeGeneratePropertiesFile (
8389 properties , temporaryFolder .getRoot (), propertiesPath .toFile (), UTF_8 , true );
8490
85- byte [] bytes = Files .readAllBytes (propertiesPath );
86- String actualContent = new String (bytes , UTF_8 );
87- String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
91+ String actualContent = Files .readString (propertiesPath , UTF_8 );
92+ String expectedContent = convertLineBreaks ("#Generated by Git-Commit-Id-Plugin\n "
8893 + "branch=develop\n "
8994 + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n "
90- + "commit.message.short=\\ u6E2C\\ u8A66\\ u4E2D\\ u6587\n " ;
95+ + "commit.message.short=\\ u6E2C\\ u8A66\\ u4E2D\\ u6587\n " ) ;
9196 assertEquals (expectedContent , actualContent );
9297 }
9398
@@ -101,11 +106,10 @@ public void generatedPropertiesFileDoesNotContainDateComment() throws GitCommitI
101106 propertiesFileGenerator .maybeGeneratePropertiesFile (
102107 properties , temporaryFolder .getRoot (), propertiesPath .toFile (), UTF_8 , true );
103108
104- byte [] bytes = Files .readAllBytes (propertiesPath );
105- String actualContent = new String (bytes , UTF_8 );
106- String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
109+ String actualContent = Files .readString (propertiesPath , UTF_8 );
110+ String expectedContent = convertLineBreaks ("#Generated by Git-Commit-Id-Plugin\n "
107111 + "branch=develop\n "
108- + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " ;
112+ + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " ) ;
109113 assertEquals (expectedContent , actualContent );
110114 }
111115
@@ -123,11 +127,10 @@ public void rereadGeneratedPropertiesFile() throws GitCommitIdExecutionException
123127 propertiesFileGenerator .maybeGeneratePropertiesFile (
124128 properties , temporaryFolder .getRoot (), propertiesPath .toFile (), UTF_8 , true );
125129
126- byte [] bytes = Files .readAllBytes (propertiesPath );
127- String actualContent = new String (bytes , UTF_8 );
128- String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
130+ String actualContent = Files .readString (propertiesPath , UTF_8 );
131+ String expectedContent = convertLineBreaks ("#Generated by Git-Commit-Id-Plugin\n "
129132 + "branch=develop\n "
130- + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " ;
133+ + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " ) ;
131134 assertEquals (expectedContent , actualContent );
132135 }
133136
@@ -143,10 +146,9 @@ public void worksWithRelativeFileLocation() throws GitCommitIdExecutionException
143146
144147 Path absolutePath = temporaryFolder .getRoot ().toPath ().resolve ("src/blah/blub/git.properties" );
145148 assertTrue (absolutePath .toFile ().exists ());
146- byte [] bytes = Files .readAllBytes (absolutePath );
147- String actualContent = new String (bytes , UTF_8 );
148- String expectedContent = "#Generated by Git-Commit-Id-Plugin\n "
149- + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " ;
149+ String actualContent = Files .readString (absolutePath , UTF_8 );
150+ String expectedContent = convertLineBreaks ("#Generated by Git-Commit-Id-Plugin\n "
151+ + "commit.id.full=b5993378ffadd1f84dc8da220b9204d157ec0f29\n " );
150152 assertEquals (expectedContent , actualContent );
151153 }
152154}
0 commit comments