### Question:
LedgerMetadataSerDe { public LedgerMetadata parseConfig(byte[] bytes, Optional<Long> metadataStoreCtime) throws IOException { if (log.isDebugEnabled()) { log.debug("Deserializing {}", Base64.getEncoder().encodeToString(bytes)); } try (ByteArrayInputStream is = new ByteArrayInputStream(bytes)) { int metadataFormatVersion = readHeader(is); if (log.isDebugEnabled()) { String contentStr = ""; if (metadataFormatVersion <= METADATA_FORMAT_VERSION_2) { contentStr = ", content: " + new String(bytes, UTF_8); } log.debug("Format version {} detected{}", metadataFormatVersion, contentStr); } switch (metadataFormatVersion) { case METADATA_FORMAT_VERSION_3: return parseVersion3Config(is, metadataStoreCtime); case METADATA_FORMAT_VERSION_2: return parseVersion2Config(is, metadataStoreCtime); case METADATA_FORMAT_VERSION_1: return parseVersion1Config(is); default: throw new IOException( String.format("Metadata version not compatible. Expected between %d and %d, but got %d", LOWEST_COMPAT_METADATA_FORMAT_VERSION, CURRENT_METADATA_FORMAT_VERSION, metadataFormatVersion)); } } }  byte[] serialize(LedgerMetadata metadata); LedgerMetadata parseConfig(byte[] bytes,
                                      Optional<Long> metadataStoreCtime); static final int METADATA_FORMAT_VERSION_1; static final int METADATA_FORMAT_VERSION_2; static final int METADATA_FORMAT_VERSION_3; static final int MAXIMUM_METADATA_FORMAT_VERSION; static final int CURRENT_METADATA_FORMAT_VERSION; }### Answer:
@Test(expected = IOException.class) public void testJunkSerDe() throws Exception { LedgerMetadataSerDe serDe = new LedgerMetadataSerDe(); String junk = ""; serDe.parseConfig(junk.getBytes(UTF_8), Optional.empty()); }
@Test(expected = IOException.class) public void testJunk2SerDe() throws Exception { byte[] randomBytes = new byte[1000]; new Random().nextBytes(randomBytes); LedgerMetadataSerDe serDe = new LedgerMetadataSerDe(); serDe.parseConfig(randomBytes, Optional.empty()); }
@Test(expected = IOException.class) public void testJunkVersionSerDe() throws Exception { byte[] junkVersion = "BookieMetadataFormatVersion\tfoobar\nblahblah".getBytes(UTF_8); LedgerMetadataSerDe serDe = new LedgerMetadataSerDe(); serDe.parseConfig(junkVersion, Optional.empty()); }
@Test(expected = IOException.class) public void testVeryLongVersionSerDe() throws Exception { byte[] veryLongVersion = "BookieMetadataFormatVersion\t123456789123456789\nblahblah".getBytes(UTF_8); LedgerMetadataSerDe serDe = new LedgerMetadataSerDe(); serDe.parseConfig(veryLongVersion, Optional.empty()); }