### Question:
StringIndexKey extends NativeIndexSingleValueKey<StringIndexKey> { void setBytesLength( int length ) { if ( bytesDereferenced || bytes == null || bytes.length < length ) { bytesDereferenced = false; bytes = new byte[length + length / 2]; } bytesLength = length; }  @Override Value asValue(); @Override String toString(); @Override void writeString( String value ); @Override void writeString( char value ); @Override void writeUTF8( byte[] bytes, int offset, int length );  }### Answer:
@Test void shouldReuseByteArrayForFairlySimilarSizedKeys() { StringIndexKey key = new StringIndexKey(); key.setBytesLength( 20 ); byte[] first = key.bytes; key.setBytesLength( 25 ); byte[] second = key.bytes; assertSame( first, second ); assertThat( first.length, greaterThanOrEqualTo( 25 ) ); }
@Test void shouldCreateNewByteArrayForVastlyDifferentKeySizes() { StringIndexKey key = new StringIndexKey(); key.setBytesLength( 20 ); byte[] first = key.bytes; key.setBytesLength( 100 ); byte[] second = key.bytes; assertNotSame( first, second ); assertThat( first.length, greaterThanOrEqualTo( 20 ) ); assertThat( second.length, greaterThanOrEqualTo( 100 ) ); }