### Question:
NativeIndexHeaderReader implements Header.Reader { @Override public void read( ByteBuffer headerData ) { try { state = headerData.get(); if ( state == BYTE_FAILED ) { failureMessage = readFailureMessage( headerData ); } else { additionalReader.read( headerData ); } } catch ( BufferUnderflowException e ) { state = BYTE_FAILED; failureMessage = format( "Could not read header, most likely caused by index not being fully constructed. Index needs to be recreated. Stacktrace:%n%s", ExceptionUtils.getStackTrace( e ) ); } } NativeIndexHeaderReader( Header.Reader additionalReader ); @Override void read( ByteBuffer headerData );  }### Answer:
@Test void mustReportFailedIfNoHeader() { ByteBuffer emptyBuffer = ByteBuffer.wrap( new byte[0] ); NativeIndexHeaderReader nativeIndexHeaderReader = new NativeIndexHeaderReader( NO_HEADER_READER ); nativeIndexHeaderReader.read( emptyBuffer ); assertSame( BYTE_FAILED, nativeIndexHeaderReader.state ); assertThat( nativeIndexHeaderReader.failureMessage, containsString( "Could not read header, most likely caused by index not being fully constructed. Index needs to be recreated. Stacktrace:" ) ); }
@Test void mustReportFailedIfHeaderTooShort() { ByteBuffer emptyBuffer = ByteBuffer.wrap( new byte[1] ); NativeIndexHeaderReader nativeIndexHeaderReader = new NativeIndexHeaderReader( ByteBuffer::get ); nativeIndexHeaderReader.read( emptyBuffer ); assertSame( BYTE_FAILED, nativeIndexHeaderReader.state ); assertThat( nativeIndexHeaderReader.failureMessage, containsString( "Could not read header, most likely caused by index not being fully constructed. Index needs to be recreated. Stacktrace:" ) ); }
@Test void mustNotThrowIfHeaderLongEnough() { ByteBuffer emptyBuffer = ByteBuffer.wrap( new byte[1] ); NativeIndexHeaderReader nativeIndexHeaderReader = new NativeIndexHeaderReader( NO_HEADER_READER ); nativeIndexHeaderReader.read( emptyBuffer ); }