### Question:
KeyValueWriter implements Closeable { public boolean writeHeader( BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value ) throws IOException { boolean result = state.header( this, value.allZeroes() || value.minusOneAtTheEnd() ); doWrite( key, value, State.done ); return result; } KeyValueWriter( MetadataCollector metadata, Writer writer ); static KeyValueWriter create(
            MetadataCollector metadata, FileSystemAbstraction fs, PageCache pages, File path, int pageSize ); boolean writeHeader( BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value ); void writeData( BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value ); KeyValueStoreFile openStoreFile(); @Override void close();  }### Answer:
@Test public void shouldAcceptNoHeadersAndNoData() throws Exception { value.putByte( 0, (byte) 0x7F ); value.putByte( 7, (byte) 0x7F ); assertTrue( "format specifier", writer.writeHeader( key, value ) ); assertTrue( "end-of-header marker", writer.writeHeader( key, value ) ); assertTrue( "end marker + number of data items", writer.writeHeader( key, value ) ); stub.assertData( new byte[]{0x00, 0, 0, 0, 0, 0, 0, 0x00, 0x7F, 0, 0, 0, 0, 0, 0, 0x7F, 0x00, 0, 0, 0, 0, 0, 0, 0x00, 0x00, 0, 0, 0, 0, 0, 0, 0x00, 0x00, 0, 0, 0, 0, 0, 0, 0x00, 0x00, 0, 0, 0, 0, 0, 0, 0x00, } ); }
@Test public void shouldRequireNonZeroFormatSpecifier() throws Exception { assertFalse( "format-specifier", writer.writeHeader( key, value ) ); }
@Test public void shouldRejectInvalidHeaderKeyWhenAssertionsAreEnabled() throws Exception { key.putByte( 3, (byte) 1 ); value.putByte( 0, (byte) 0x7F ); value.putByte( 7, (byte) 0x7F ); try { writer.writeHeader( key, value ); } catch ( AssertionError e ) { assertEquals( "key should have been cleared by previous call", e.getMessage() ); } }