@Test
public void testPrepareForDiffing_OneCompressedEntry_Changed() throws IOException {

  byte[] oldBytes = UnitTestZipArchive.makeTestZip(Collections.singletonList(ENTRY_LEVEL_6));
  File oldFile = store(oldBytes);
  byte[] newBytes = UnitTestZipArchive.makeTestZip(Collections.singletonList(ENTRY_LEVEL_9));
  File newFile = store(newBytes);
  PreDiffExecutor executor =
      new PreDiffExecutor.Builder()
          .readingOriginalFiles(oldFile, newFile)
          .writingDeltaFriendlyFiles(deltaFriendlyOldFile, deltaFriendlyNewFile)
          .build();
  PreDiffPlan plan = executor.prepareForDiffing();
  Assert.assertNotNull(plan);
  // The plan should be to uncompress the data in both the old and new files.
  Assert.assertEquals(1, plan.getOldFileUncompressionPlan().size());
  Assert.assertEquals(1, plan.getNewFileUncompressionPlan().size());
  Assert.assertEquals(1, plan.getDeltaFriendlyNewFileRecompressionPlan().size());
  // The delta-friendly files should be larger than the originals.
  Assert.assertTrue(oldFile.length() < deltaFriendlyOldFile.length());
  Assert.assertTrue(newFile.length() < deltaFriendlyNewFile.length());
  // Nitty-gritty, assert that the file content is exactly what is expected.
  // 1. Find the entry in the old file.
  // 2. Create a buffer to hold the expected data.
  // 3. Copy all the file data that PRECEDES the compressed data into the buffer.
  // 4. Copy the UNCOMPRESSED data from the unit test object into the buffer.
  // 5. Copy all the file data the FOLLOWS the compressed data into the buffer.
  // This should be exactly what is produced. Note that this is not a valid ZIP archive, as the
  // offsets and lengths in the zip metadata are no longer tied to the actual data. This is
  // normal and expected, since the delta-friendly file is not actually an archive anymore.
  { // Scoping block for sanity
    MinimalZipEntry oldEntry = findEntry(oldFile, ENTRY_LEVEL_6.path);
    ByteArrayOutputStream expectedDeltaFriendlyOldFileBytes = new ByteArrayOutputStream();
    expectedDeltaFriendlyOldFileBytes.write(
        oldBytes, 0, (int) oldEntry.getFileOffsetOfCompressedData());
    expectedDeltaFriendlyOldFileBytes.write(ENTRY_LEVEL_6.getUncompressedBinaryContent());
    int oldRemainderOffset =
        (int) (oldEntry.getFileOffsetOfCompressedData() + oldEntry.getCompressedSize());
    int oldRemainderLength = oldBytes.length - oldRemainderOffset;
    expectedDeltaFriendlyOldFileBytes.write(oldBytes, oldRemainderOffset, oldRemainderLength);
    byte[] expectedOld = expectedDeltaFriendlyOldFileBytes.toByteArray();
    byte[] actualOld = readFile(deltaFriendlyOldFile);
    Assert.assertArrayEquals(expectedOld, actualOld);
  }
  // Now do the same for the new file and new entry
  { // Scoping block for sanity
    MinimalZipEntry newEntry = findEntry(newFile, ENTRY_LEVEL_9.path);
    ByteArrayOutputStream expectedDeltaFriendlyNewFileBytes = new ByteArrayOutputStream();
    expectedDeltaFriendlyNewFileBytes.write(
        newBytes, 0, (int) newEntry.getFileOffsetOfCompressedData());
    expectedDeltaFriendlyNewFileBytes.write(ENTRY_LEVEL_9.getUncompressedBinaryContent());
    int newRemainderOffset =
        (int) (newEntry.getFileOffsetOfCompressedData() + newEntry.getCompressedSize());
    int newRemainderLength = newBytes.length - newRemainderOffset;
    expectedDeltaFriendlyNewFileBytes.write(newBytes, newRemainderOffset, newRemainderLength);
    byte[] expectedNew = expectedDeltaFriendlyNewFileBytes.toByteArray();
    byte[] actualNew = readFile(deltaFriendlyNewFile);
    Assert.assertArrayEquals(expectedNew, actualNew);
  }
}