@Test
public void testParseCentralDirectoryEntry() throws Exception {

  ByteArrayInputStream in = new ByteArrayInputStream(unitTestZipArchive);
  in.mark(unitTestZipArchive.length);
  int eocdOffset = MinimalZipParser.locateStartOfEocd(unitTestZipArchive);
  Assert.assertEquals(eocdOffset, in.skip(eocdOffset));
  MinimalCentralDirectoryMetadata metadata = MinimalZipParser.parseEocd(in);
  in.reset();
  Assert.assertEquals(
      metadata.getOffsetOfCentralDirectory(), in.skip(metadata.getOffsetOfCentralDirectory()));
  // Read each entry and verify all fields *except* the value returned by
  // MinimalZipEntry.getFileOffsetOfCompressedData(), as that has yet to be computed.
  for (UnitTestZipEntry expectedEntry : UnitTestZipArchive.allEntriesInFileOrder) {
    MinimalZipEntry parsed = MinimalZipParser.parseCentralDirectoryEntry(in);
    Assert.assertEquals(expectedEntry.path, parsed.getFileName());
    // Verify that the local signature header is at the calculated position
    byte[] expectedSignatureBlock = new byte[] {0x50, 0x4b, 0x03, 0x04};
    for (int index = 0; index < 4; index++) {
      byte actualByte = unitTestZipArchive[((int) parsed.getFileOffsetOfLocalEntry()) + index];
      Assert.assertEquals(expectedSignatureBlock[index], actualByte);
    }
    if (expectedEntry.level > 0) {
      Assert.assertEquals(8 /* deflate */, parsed.getCompressionMethod());
    } else {
      Assert.assertEquals(0 /* store */, parsed.getCompressionMethod());
    }
    byte[] uncompressedContent = expectedEntry.getUncompressedBinaryContent();
    Assert.assertEquals(uncompressedContent.length, parsed.getUncompressedSize());
    CRC32 crc32 = new CRC32();
    crc32.update(uncompressedContent);
    Assert.assertEquals(crc32.getValue(), parsed.getCrc32OfUncompressedData());
    byte[] compressedContent = expectedEntry.getCompressedBinaryContent();
    Assert.assertEquals(compressedContent.length, parsed.getCompressedSize());
  }
}