Skip to content

Commit 04955ba

Browse files
committed
Use valid input for testing byte conversion, as behaviour for invalid input is undefined.
Fixes test failure with IBM Java 1.6 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1383170 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1c10231 commit 04955ba

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/test/java/org/apache/commons/codec/binary/StringUtilsTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public class StringUtilsTest {
3333

3434
private static final byte[] BYTES_FIXTURE = {'a','b','c'};
3535

36+
// This is valid input for UTF-16BE
37+
private static final byte[] BYTES_FIXTURE_16BE = {0, 'a', 0, 'b', 0, 'c'};
38+
39+
// This is valid for UTF-16LE
40+
private static final byte[] BYTES_FIXTURE_16LE = {'a', 0, 'b', 0, 'c', 0};
41+
3642
private static final String STRING_FIXTURE = "ABC";
3743

3844
/**
@@ -171,17 +177,17 @@ public void testNewStringUtf16() throws UnsupportedEncodingException {
171177
public void testNewStringUtf16Be() throws UnsupportedEncodingException {
172178
String charsetName = "UTF-16BE";
173179
testNewString(charsetName);
174-
String expected = new String(BYTES_FIXTURE, charsetName);
175-
String actual = StringUtils.newStringUtf16Be(BYTES_FIXTURE);
180+
String expected = new String(BYTES_FIXTURE_16BE, charsetName);
181+
String actual = StringUtils.newStringUtf16Be(BYTES_FIXTURE_16BE);
176182
Assert.assertEquals(expected, actual);
177183
}
178184

179185
@Test
180186
public void testNewStringUtf16Le() throws UnsupportedEncodingException {
181187
String charsetName = "UTF-16LE";
182188
testNewString(charsetName);
183-
String expected = new String(BYTES_FIXTURE, charsetName);
184-
String actual = StringUtils.newStringUtf16Le(BYTES_FIXTURE);
189+
String expected = new String(BYTES_FIXTURE_16LE, charsetName);
190+
String actual = StringUtils.newStringUtf16Le(BYTES_FIXTURE_16LE);
185191
Assert.assertEquals(expected, actual);
186192
}
187193

0 commit comments

Comments
 (0)