Repository: commons-io Updated Branches: refs/heads/master 9990c6669 -> 92a07f9aa
Missing Test Case for negative offset value (closes #41) The method copyLarge(InputStream input, InputStream output, int offset, buffer) copies the content of input into output. If offset is a positive number, it will skip a number of bytes from input equal to offset value. By performing mutation testing analysis we noticed that the copyLarge method was never tested for a negative value for offset. The added test call copyLarge with a negative value and check that the behavior is the same as for offset = 0, where no bytes are skipped from input. Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/92a07f9a Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/92a07f9a Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/92a07f9a Branch: refs/heads/master Commit: 92a07f9aa109f0f55af963f86e466c80718f9466 Parents: 9990c66 Author: Ioana Leontiuc <i.leont...@student.tudelft.nl> Authored: Wed Aug 2 16:09:30 2017 +0200 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Wed Aug 2 19:39:04 2017 +0200 ---------------------------------------------------------------------- .../org/apache/commons/io/IOUtilsTestCase.java | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-io/blob/92a07f9a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java index 4356467..bfbd6da 100644 --- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java +++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java @@ -1493,4 +1493,32 @@ public class IOUtilsTestCase extends FileBasedTestCase { assertSame(bw, IOUtils.buffer(bw)); assertSame(bw, IOUtils.buffer(bw, 1024)); } + + + @Test + public void testCopyLarge_SkipWithInvalidOffset() throws IOException { + ByteArrayInputStream is = null; + ByteArrayOutputStream os = null; + try { + // Create streams + is = new ByteArrayInputStream(iarr); + os = new ByteArrayOutputStream(); + + // Test our copy method + assertEquals(100, IOUtils.copyLarge(is, os, -10, 100)); + final byte[] oarr = os.toByteArray(); + + // check that output length is correct + assertEquals(100, oarr.length); + // check that output data corresponds to input data + assertEquals(1, oarr[1]); + assertEquals(79, oarr[79]); + assertEquals(-1, oarr[80]); + + } finally { + IOUtils.closeQuietly(is); + IOUtils.closeQuietly(os); + } + } + }