@Test
public void testApplyPatch_NewLengthNegative() throws Exception {

  createEmptyOldFile(10);
  InputStream patchIn =
      makePatch(
          SIGNATURE,
          -10, // newLength (illegal)
          10, // diffSegmentLength
          0, // copySegmentLength
          0, // offsetToNextInput
          new byte[10] // addends
          );
  ByteArrayOutputStream newData = new ByteArrayOutputStream();
  try {
    BsPatch.applyPatch(new RandomAccessFile(oldFile, "r"), newData, patchIn);
    Assert.fail("Read patch with negative newLength");
  } catch (PatchFormatException expected) {
    // No way to mock the internal logic, so resort to testing exception string for coverage
    String actual = expected.getMessage();
    Assert.assertEquals("bad newSize", actual);
  }
}