mirror of
https://github.com/corda/corda.git
synced 2025-01-19 11:16:54 +00:00
fix portability problem in Strings test
There was a test in Strings.java that assumed the default character encoding was UTF-8, which is an invalid assumption on some platforms (e.g. Windows). This modifies the test to specify the encoding explicitly.
This commit is contained in:
parent
81958144a1
commit
c35435e450
@ -24,6 +24,17 @@ public class PrintStream extends OutputStream {
|
||||
this.autoFlush = autoFlush;
|
||||
}
|
||||
|
||||
public PrintStream(OutputStream out, boolean autoFlush, String encoding)
|
||||
throws UnsupportedEncodingException
|
||||
{
|
||||
this.out = out;
|
||||
this.autoFlush = autoFlush;
|
||||
|
||||
if (! (encoding.equals("UTF-8") || encoding.equals("ISO-8859-1"))) {
|
||||
throw new UnsupportedEncodingException(encoding);
|
||||
}
|
||||
}
|
||||
|
||||
public PrintStream(OutputStream out) {
|
||||
this(out, false);
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ public class Strings {
|
||||
.equals("I enjoy grape nuts. do you? you do?"));
|
||||
|
||||
{ java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
|
||||
java.io.PrintStream pout = new java.io.PrintStream(bout);
|
||||
java.io.PrintStream pout = new java.io.PrintStream(bout, true, "UTF-8");
|
||||
String s = "I ♥ grape nuts";
|
||||
System.out.println(s);
|
||||
pout.println(s);
|
||||
@ -207,17 +207,14 @@ public class Strings {
|
||||
expect
|
||||
(arraysEqual
|
||||
(bout.toByteArray(),
|
||||
(s + System.getProperty("line.separator")).getBytes()));
|
||||
(s + System.getProperty("line.separator")).getBytes("UTF-8")));
|
||||
|
||||
// note that this effectively asserts that the VM's default
|
||||
// charset is UTF-8. If we want to make this test more
|
||||
// portable, we should specify the charset explicitly.
|
||||
expect
|
||||
(arraysEqual
|
||||
(bout.toByteArray(), append
|
||||
(new byte[] { 73, 32, -30, -103, -91, 32, 103, 114, 97, 112, 101,
|
||||
32, 110, 117, 116, 115 },
|
||||
System.getProperty("line.separator").getBytes())));
|
||||
System.getProperty("line.separator").getBytes("UTF-8"))));
|
||||
}
|
||||
|
||||
expect("abc".lastIndexOf('b', 100) == 1);
|
||||
|
Loading…
Reference in New Issue
Block a user