This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push:
new 47beebbdc1 make stream gobbler test specify which charset to use
(utf-8)
new 6eab504381 Merge branch 'master' of
https://gitbox.apache.org/repos/asf/brooklyn-server
47beebbdc1 is described below
commit 47beebbdc1618175a492d389bc346785f6fe623e
Author: Alex Heneveld <[email protected]>
AuthorDate: Mon Sep 4 11:49:02 2023 +0100
make stream gobbler test specify which charset to use (utf-8)
otherwise it fails if system default doesn't properly encode and decode
unicode chars
---
.../org/apache/brooklyn/util/stream/StreamGobblerTest.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git
a/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
b/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
index 1ad5b2ef97..67df4b8cf1 100644
---
a/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
+++
b/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
@@ -28,6 +28,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.*;
+import java.nio.charset.Charset;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
@@ -35,6 +36,11 @@ import static org.testng.Assert.assertFalse;
public class StreamGobblerTest {
private static final Logger LOG =
LoggerFactory.getLogger(StreamGobblerTest.class);
+ private static final String TEST_CHARSET_NAME =
+ "UTF-8";
+// "US-ASCII"; // fails
+
+ private static final Charset TEST_CHARSET =
Charset.forName(TEST_CHARSET_NAME);
private final String NL = Os.LINE_SEPARATOR;
@@ -43,7 +49,7 @@ public class StreamGobblerTest {
LOG.info("Processing text: '{}'", text);
ByteArrayOutputStream out = new ByteArrayOutputStream();
- ByteArrayInputStream in = new ByteArrayInputStream(text.getBytes());
+ ByteArrayInputStream in = new
ByteArrayInputStream(text.getBytes(TEST_CHARSET));
StreamGobbler streamGobbler = new StreamGobbler(in, out, (Logger)
null);
streamGobbler.start();
streamGobbler.join(5000);
@@ -52,7 +58,7 @@ public class StreamGobblerTest {
// approximate regex-- might not work for all whitespace combos
String expected = Strings.isBlank(text) ? "" :
text.replace("\t\r","\r").replaceAll("\r","\n") + NL;
- Assert.assertEquals(out.toString(), expected);
+ Assert.assertEquals(out.toString(TEST_CHARSET_NAME), expected);
}
@Test