1717import org .elasticsearch .core .CheckedConsumer ;
1818import org .elasticsearch .test .ESTestCase ;
1919import org .elasticsearch .xcontent .XContentBuilder ;
20+ import org .elasticsearch .xcontent .XContentString ;
2021import org .elasticsearch .xcontent .json .JsonXContent ;
2122import org .hamcrest .Matchers ;
2223
2324import java .io .IOException ;
24- import java .nio .ByteBuffer ;
2525import java .nio .charset .StandardCharsets ;
2626
2727public class ESUTF8StreamJsonParserTests extends ESTestCase {
@@ -35,8 +35,8 @@ private void testParseJson(String input, CheckedConsumer<ESUTF8StreamJsonParser,
3535 test .accept ((ESUTF8StreamJsonParser ) parser );
3636 }
3737
38- private void assertTextRef (ByteBuffer textRef , String expectedValue ) {
39- assertThat (textRef , Matchers .equalTo (StandardCharsets . UTF_8 . encode (expectedValue )));
38+ private void assertTextRef (XContentString . UTF8Bytes textRef , String expectedValue ) {
39+ assertThat (textRef , Matchers .equalTo (new XContentString . UTF8Bytes (expectedValue . getBytes ( StandardCharsets . UTF_8 ) )));
4040 }
4141
4242 public void testGetValueAsText () throws IOException {
@@ -45,10 +45,10 @@ public void testGetValueAsText() throws IOException {
4545 assertThat (parser .nextFieldName (), Matchers .equalTo ("foo" ));
4646 assertThat (parser .nextValue (), Matchers .equalTo (JsonToken .VALUE_STRING ));
4747
48- ByteBuffer textRef = parser .getValueAsText ().bytes ();
48+ var textRef = parser .getValueAsText ().bytes ();
4949 assertThat (textRef , Matchers .notNullValue ());
50- assertThat (textRef .arrayOffset () + textRef . position (), Matchers .equalTo (9 ));
51- assertThat (textRef .limit (), Matchers .equalTo (12 ));
50+ assertThat (textRef .offset (), Matchers .equalTo (9 ));
51+ assertThat (textRef .offset () + textRef . length (), Matchers .equalTo (12 ));
5252 assertTextRef (textRef , "bar" );
5353
5454 assertThat (parser .getValueAsString (), Matchers .equalTo ("bar" ));
@@ -82,28 +82,28 @@ public void testGetValueAsText() throws IOException {
8282
8383 assertThat (parser .nextValue (), Matchers .equalTo (JsonToken .VALUE_STRING ));
8484 {
85- ByteBuffer textRef = parser .getValueAsText ().bytes ();
85+ var textRef = parser .getValueAsText ().bytes ();
8686 assertThat (textRef , Matchers .notNullValue ());
87- assertThat (textRef .arrayOffset () + textRef . position (), Matchers .equalTo (10 ));
88- assertThat (textRef .limit (), Matchers .equalTo (15 ));
87+ assertThat (textRef .offset (), Matchers .equalTo (10 ));
88+ assertThat (textRef .offset () + textRef . length (), Matchers .equalTo (15 ));
8989 assertTextRef (textRef , "lorem" );
9090 }
9191
9292 assertThat (parser .nextValue (), Matchers .equalTo (JsonToken .VALUE_STRING ));
9393 {
94- ByteBuffer textRef = parser .getValueAsText ().bytes ();
94+ var textRef = parser .getValueAsText ().bytes ();
9595 assertThat (textRef , Matchers .notNullValue ());
96- assertThat (textRef .arrayOffset () + textRef . position (), Matchers .equalTo (19 ));
97- assertThat (textRef .limit (), Matchers .equalTo (24 ));
96+ assertThat (textRef .offset (), Matchers .equalTo (19 ));
97+ assertThat (textRef .offset () + textRef . length (), Matchers .equalTo (24 ));
9898 assertTextRef (textRef , "ipsum" );
9999 }
100100
101101 assertThat (parser .nextValue (), Matchers .equalTo (JsonToken .VALUE_STRING ));
102102 {
103- ByteBuffer textRef = parser .getValueAsText ().bytes ();
103+ var textRef = parser .getValueAsText ().bytes ();
104104 assertThat (textRef , Matchers .notNullValue ());
105- assertThat (textRef .arrayOffset () + textRef . position (), Matchers .equalTo (28 ));
106- assertThat (textRef .limit (), Matchers .equalTo (33 ));
105+ assertThat (textRef .offset (), Matchers .equalTo (28 ));
106+ assertThat (textRef .offset () + textRef . length (), Matchers .equalTo (33 ));
107107 assertTextRef (textRef , "dolor" );
108108 }
109109
0 commit comments