77import java .io .InputStream ;
88import java .net .URISyntaxException ;
99import java .net .URL ;
10+ import java .nio .charset .StandardCharsets ;
1011import java .nio .file .Files ;
1112import java .nio .file .Path ;
1213import java .nio .file .Paths ;
@@ -34,7 +35,7 @@ class SetPropertiesCommandTest {
3435
3536 @ BeforeEach
3637 void setUp () throws IOException , URISyntaxException {
37- propertiesFile = preparePropertiesFile ();
38+ propertiesFile = preparePropertiesFile ("server.properties" );
3839
3940 final URL definitionsResource = getClass ().getResource ("/properties/property-definitions.json" );
4041 assertThat (definitionsResource ).isNotNull ();
@@ -173,6 +174,24 @@ void handlesModifiedCustomProperties() throws IOException {
173174 .containsEntry ("key2" , "value2" );
174175 }
175176
177+ @ Test
178+ void handlesExistingUnicodePropertyValue () throws IOException {
179+ final Path outputProperties = preparePropertiesFile ("with-unicode.txt" );
180+
181+ final int exitCode = new CommandLine (new SetPropertiesCommand ())
182+ .execute (
183+ "--custom-property" , "key1=value1" ,
184+ outputProperties .toString ()
185+ );
186+
187+ assertThat (exitCode ).isEqualTo (ExitCode .OK );
188+
189+ assertThat (outputProperties )
190+ .content (StandardCharsets .UTF_8 )
191+ .containsIgnoringNewLines ("motd=\\ u00A7c\\ u00A7lT\\ u00A76\\ u00A7le\\ u00A7e\\ u00A7ls\\ u00A7a\\ u00A7lt\\ u00A73\\ u00A7li\\ u00A79\\ u00A7ln\\ u00A75\\ u00A7lg \\ u00A76\\ u00A7l1\\ u00A7e\\ u00A7l2\\ u00A7a\\ u00A7l3" )
192+ .containsIgnoringNewLines ("key1=value1" );
193+ }
194+
176195 private void assertPropertiesEqualExcept (Properties properties , String ... propertiesToIgnore ) {
177196 final HashSet <Object > actualKeys = new HashSet <>(properties .keySet ());
178197 Arrays .asList (propertiesToIgnore ).forEach (actualKeys ::remove );
@@ -196,12 +215,13 @@ private Properties loadProperties() throws IOException {
196215 return properties ;
197216 }
198217
199- private Path preparePropertiesFile () throws IOException {
200- try (InputStream in = getClass ().getClassLoader ().getResourceAsStream ("properties/server.properties" )) {
201- assertThat (in ).isNotNull ();
202- final Path outFile = tempDir .resolve ("server.properties" );
203- Files .copy (in , outFile );
204- return outFile ;
218+ private Path preparePropertiesFile (String filename ) throws IOException {
219+ final URL resource = getClass ().getClassLoader ().getResource ("properties/" + filename );
220+ assertThat (resource ).isNotNull ();
221+ try {
222+ return Files .copy (Paths .get (resource .toURI ()), tempDir .resolve (filename ));
223+ } catch (URISyntaxException e ) {
224+ throw new RuntimeException (e );
205225 }
206226 }
207227}
0 commit comments