### Question:
KeyValueWriter implements Closeable { public void writeData( BigEndianByteArrayBuffer key, BigEndianByteArrayBuffer value ) throws IOException { state.data( this ); assert key.size() == keySize; assert value.size() == valueSize; if ( key.allZeroes() ) { state = State.in_error; throw new IllegalArgumentException( "All-zero keys are not allowed." ); } if ( !write( key, value ) ) { state = State.in_error; throw new IllegalStateException( "MetadataCollector stopped on data field." ); } } 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 shouldRejectDataBeforeHeaders() throws Exception { key.putByte( 2, (byte) 0x77 ); try { writer.writeData( key, value ); fail( "expected exception" ); } catch ( IllegalStateException e ) { assertEquals( "Cannot write data when expecting format specifier.", e.getMessage() ); } }