File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
libs/x-content/src/test/java/org/elasticsearch/xcontent Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -163,4 +163,28 @@ public void testCompareTo() {
163163 }
164164 }
165165
166+ public void testRandomized () {
167+ int stringLength = randomInt (128 );
168+ String value = randomUnicodeOfLength (stringLength );
169+ byte [] encodedArr = value .getBytes (StandardCharsets .UTF_8 );
170+ var encoded = new XContentString .UTF8Bytes (encodedArr );
171+
172+ Text text = switch (randomInt (2 )) {
173+ case 0 -> new Text (value );
174+ case 1 -> new Text (encoded );
175+ default -> new Text (encoded , stringLength );
176+ };
177+
178+ for (int i = 0 ; i < 20 ; i ++) {
179+ switch (randomInt (5 )) {
180+ case 0 -> assertEquals (encoded , text .bytes ());
181+ case 1 -> assertSame (text .bytes (), text .bytes ());
182+ case 2 -> assertEquals (value , text .string ());
183+ case 3 -> assertEquals (value , text .toString ());
184+ case 4 -> assertEquals (stringLength , text .stringLength ());
185+ case 5 -> assertEquals (new Text (value ), text );
186+ }
187+ }
188+ }
189+
166190}
You can’t perform that action at this time.
0 commit comments