### Question:
UTF8StringValue extends StringValue { @Override public TextValue substring( int start, int length ) { if ( start < 0 || length < 0 ) { throw new IndexOutOfBoundsException( "Cannot handle negative start index nor negative length" ); } if ( length == 0 ) { return StringValue.EMPTY; } int end = start + length; byte[] values = bytes; int count = 0, byteStart = -1, byteEnd = -1, i = offset, len = offset + byteLength; while ( i < len ) { if ( count == start ) { byteStart = i; } if ( count == end ) { byteEnd = i; break; } byte b = values[i]; if ( b >= 0 ) { i++; } while ( b < 0 ) { i++; b = (byte) (b << 1); } count++; } if ( byteEnd < 0 ) { byteEnd = len; } if ( byteStart < 0 ) { return StringValue.EMPTY; } return new UTF8StringValue( values, byteStart, byteEnd - byteStart ); } UTF8StringValue( byte[] bytes, int offset, int length ); @Override void writeTo( ValueWriter<E> writer ); @Override boolean equals( Value value ); @Override int length(); @Override int computeHash(); @Override long updateHash( HashFunction hashFunction, long hash ); @Override TextValue substring( int start, int length ); @Override TextValue trim(); @Override TextValue ltrim(); @Override TextValue rtrim(); @Override TextValue plus( TextValue other ); @Override boolean startsWith( TextValue other ); @Override boolean endsWith( TextValue other ); @SuppressWarnings( "StatementWithEmptyBody" ) @Override boolean contains( TextValue other ); @Override TextValue reverse(); @Override int compareTo( TextValue other ); static int byteArrayCompare( byte[] value1, byte[] value2 ); static int byteArrayCompare( byte[] value1, int value1Offset, int value1Length,
            byte[] value2, int value2Offset, int value2Length ); byte[] bytes();  }### Answer:
@Test void shouldSubstring() { String string = "ü"; TextValue utf8 = utf8Value( string.getBytes( UTF_8 ) ); assertThat( utf8.substring( 0, 1 ).stringValue(), equalTo( "ü" ) ); }
@Test void shouldHandleTooLargeStartPointInSubstring() { TextValue value = utf8Value( "hello".getBytes( UTF_8 ) ); TextValue substring = value.substring( 8, 5 ); assertThat( substring, equalTo( StringValue.EMPTY ) ); }
@Test void shouldHandleTooLargeLengthInSubstring() { TextValue value = utf8Value( "hello".getBytes( UTF_8 ) ); TextValue substring = value.substring( 3, 76 ); assertThat( substring.stringValue(), equalTo( "lo" ) ); }
@Test void shouldThrowOnNegativeStart() { TextValue value = utf8Value( "hello".getBytes( UTF_8 ) ); assertThrows( IndexOutOfBoundsException.class, () -> value.substring( -4, 3 ) ); }
@Test void shouldThrowOnNegativeLength() { TextValue value = utf8Value( "hello".getBytes( UTF_8 ) ); assertThrows( IndexOutOfBoundsException.class, () -> value.substring( 4, -3 ) ); }