From 61f058e40ae291976f987f52f2ea4f7649cf273c Mon Sep 17 00:00:00 2001 From: Pascal Essiembre Date: Mon, 14 Aug 2023 01:56:08 -0400 Subject: [PATCH] Minor regression fix. --- .../norconex/commons/lang/map/Properties.java | 4 +- .../commons/lang/exec/SystemCommandTest.java | 38 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/norconex/commons/lang/map/Properties.java b/src/main/java/com/norconex/commons/lang/map/Properties.java index 305089da..e740e799 100644 --- a/src/main/java/com/norconex/commons/lang/map/Properties.java +++ b/src/main/java/com/norconex/commons/lang/map/Properties.java @@ -49,7 +49,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.set.ListOrderedSet; import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.ReaderInputStream; import org.apache.commons.io.output.WriterOutputStream; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -716,7 +715,8 @@ private synchronized void loadFromJavaUtilProperties( if (input instanceof Reader reader) { if (isXML) { - p.loadFromXML(new ReaderInputStream(reader, UTF_8)); + p.loadFromXML(IOUtils.toInputStream( + IOUtils.toString(reader), UTF_8)); } else { p.load(reader); } diff --git a/src/test/java/com/norconex/commons/lang/exec/SystemCommandTest.java b/src/test/java/com/norconex/commons/lang/exec/SystemCommandTest.java index 09895262..ee701cbe 100644 --- a/src/test/java/com/norconex/commons/lang/exec/SystemCommandTest.java +++ b/src/test/java/com/norconex/commons/lang/exec/SystemCommandTest.java @@ -46,12 +46,12 @@ class SystemCommandTest { @Test void testInFileOutFile() throws IOException, SystemCommandException { - File inFile = inputAsFile(); - File outFile = newTempFile(); + var inFile = inputAsFile(); + var outFile = newTempFile(); - SystemCommand cmd = ExternalApp.newSystemCommand( + var cmd = ExternalApp.newSystemCommand( ExternalApp.TYPE_INFILE_OUTFILE, inFile, outFile); - ExternalAppListener l = addEnvAndListener(cmd); + var l = addEnvAndListener(cmd); cmd.execute(); Assertions.assertEquals( @@ -63,11 +63,11 @@ void testInFileOutFile() throws IOException, SystemCommandException { @Test void testInFileStdout() throws IOException, SystemCommandException { - File inFile = inputAsFile(); + var inFile = inputAsFile(); - SystemCommand cmd = ExternalApp.newSystemCommand( + var cmd = ExternalApp.newSystemCommand( ExternalApp.TYPE_INFILE_STDOUT, inFile); - ExternalAppListener l = addEnvAndListener(cmd); + var l = addEnvAndListener(cmd); cmd.execute(); Assertions.assertEquals(expectedOutputAsString(), l.getStdoutContent()); Assertions.assertTrue( @@ -76,12 +76,12 @@ void testInFileStdout() throws IOException, SystemCommandException { @Test void testStdinOutFile() throws IOException, SystemCommandException { - InputStream input = inputAsStream(); - File outFile = newTempFile(); + var input = inputAsStream(); + var outFile = newTempFile(); - SystemCommand cmd = ExternalApp.newSystemCommand( + var cmd = ExternalApp.newSystemCommand( ExternalApp.TYPE_STDIN_OUTFILE, outFile); - ExternalAppListener l = addEnvAndListener(cmd); + var l = addEnvAndListener(cmd); cmd.execute(input); input.close(); Assertions.assertEquals(expectedOutputAsString(), fileAsString(outFile)); @@ -91,10 +91,10 @@ void testStdinOutFile() throws IOException, SystemCommandException { @Test void testStdinStdout() throws IOException, SystemCommandException { - InputStream input = inputAsStream(); - SystemCommand cmd = ExternalApp.newSystemCommand( + var input = inputAsStream(); + var cmd = ExternalApp.newSystemCommand( ExternalApp.TYPE_STDIN_STDOUT); - ExternalAppListener l = addEnvAndListener(cmd); + var l = addEnvAndListener(cmd); cmd.execute(input); input.close(); Assertions.assertEquals(expectedOutputAsString(), l.getStdoutContent()); @@ -104,9 +104,9 @@ void testStdinStdout() throws IOException, SystemCommandException { @Test void testDefaultsNullErrors() { - SystemCommand cmd = new SystemCommand("blah"); + var cmd = new SystemCommand("blah"); - ExternalAppListener l = addEnvAndListener(cmd); + var l = addEnvAndListener(cmd); assertThat(cmd.getOutputListeners()).hasSize(1); assertThat(cmd.getErrorListeners()).hasSize(1); cmd.removeOutputListener(l); @@ -134,7 +134,7 @@ void testDefaultsNullErrors() { } private File inputAsFile() throws IOException { - File inFile = newTempFile(); + var inFile = newTempFile(); FileUtils.copyInputStreamToFile( getClass().getResourceAsStream(IN_FILE_PATH), inFile); return inFile; @@ -150,7 +150,7 @@ private String expectedOutputAsString() throws IOException { EXPECTED_OUT_FILE_PATH), StandardCharsets.UTF_8); } private File newTempFile() throws IOException { - File file = Files.createTempFile( + var file = Files.createTempFile( tempFolder, "SystemCommandTest", null).toFile(); if (!file.exists()) { // Just making sure it exists @@ -167,7 +167,7 @@ private ExternalAppListener addEnvAndListener(SystemCommand cmd) { envs.put(ExternalApp.ENV_STDERR_AFTER, ExternalApp.ENV_STDERR_AFTER); cmd.setEnvironmentVariables(envs); - ExternalAppListener l = new ExternalAppListener(); + var l = new ExternalAppListener(); cmd.addErrorListener(l); cmd.addOutputListener(l); return l;