Skip to content

Commit

Permalink
Add test for writeToStream with offset and size
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Drwenski authored and tdrwenski committed May 23, 2024
1 parent e9c27a8 commit a95b04e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cdm/zarr/src/test/java/thredds/inventory/zarr/TestMFileZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ public void shouldWriteZipToStream() throws IOException {
assertThat(outputStream.size()).isEqualTo(mFile.getLength());
}
}

@Test
public void shouldWritePartialZipToStream() throws IOException {
try (ZipFile zipFile = createTemporaryZipFile("TestWritePartialZip", entrySize, numberOfEntries)) {
final MFileZip mFile = new MFileZip(zipFile.getName());
final int length = (int) mFile.getLength();

final int offset = 1;
final int maxBytes = 100;

final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

final int startPosition = Math.min(offset, length);
final int endPosition = Math.min(offset + maxBytes, length);

mFile.writeToStream(outputStream, offset, maxBytes);
assertThat(outputStream.size()).isEqualTo(Math.max(0, endPosition - startPosition));
}
}
}

public static class TestMFileZipNonParameterized {
Expand Down

0 comments on commit a95b04e

Please sign in to comment.