Skip to content

Commit cab1e79

Browse files
committed
Yet more tweaking for #497/YAML test
1 parent 0ebda43 commit cab1e79

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/UnicodeYAMLRead497Test.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.ByteArrayInputStream;
44
import java.nio.charset.StandardCharsets;
5+
import java.util.Arrays;
56

67
import org.junit.jupiter.api.Test;
78

@@ -10,6 +11,7 @@
1011
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
1112
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
1213

14+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1315
import static org.junit.jupiter.api.Assertions.assertEquals;
1416

1517
// [dataformats-text#497]: 3-byte UTF-8 character at end of content
@@ -40,7 +42,7 @@ public void testUnicodeAtEnd() throws Exception
4042
_testUnicodeAtEnd(4097);
4143
}
4244

43-
void _testUnicodeAtEnd(int LEN) throws Exception
45+
private void _testUnicodeAtEnd(int LEN) throws Exception
4446
{
4547
StringBuilder sb = new StringBuilder(LEN + 2);
4648
sb.append("key: ");
@@ -53,20 +55,26 @@ void _testUnicodeAtEnd(int LEN) throws Exception
5355

5456
sb.append(valueBuffer);
5557
final byte[] doc = sb.toString().getBytes(StandardCharsets.UTF_8);
58+
final byte[] docOrig = Arrays.copyOf(doc, doc.length);
5659

5760
try (JsonParser p = MAPPER.createParser(doc)) {
58-
assertToken(JsonToken.START_OBJECT, p.nextToken());
59-
assertEquals("key", p.nextFieldName());
60-
assertToken(JsonToken.VALUE_STRING, p.nextToken());
61-
assertEquals(valueBuffer.toString(), p.getText());
61+
_checkDoc(p, valueBuffer.toString());
6262
}
6363

6464
try (JsonParser p = MAPPER.createParser(new ByteArrayInputStream(doc))) {
65-
assertToken(JsonToken.START_OBJECT, p.nextToken());
66-
assertEquals("key", p.nextFieldName());
67-
assertToken(JsonToken.VALUE_STRING, p.nextToken());
68-
assertEquals(valueBuffer.toString(), p.getText());
65+
_checkDoc(p, valueBuffer.toString());
6966
}
67+
68+
// Verify that original byte array was not modified
69+
assertArrayEquals(docOrig, doc);
7070
}
7171

72+
private void _checkDoc(JsonParser p, String value) throws Exception
73+
{
74+
assertToken(JsonToken.START_OBJECT, p.nextToken());
75+
assertEquals("key", p.nextFieldName());
76+
assertToken(JsonToken.VALUE_STRING, p.nextToken());
77+
assertEquals(value, p.getText());
78+
assertToken(JsonToken.END_OBJECT, p.nextToken());
79+
}
7280
}

0 commit comments

Comments
 (0)