@Test(expected = IOException.class)
public void testCopySizeLimit() throws IOException {

    try {
        byte[] input = new byte[5000];
        ByteArrayInputStream in = new ByteArrayInputStream(input);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOHelper.copy(in, out, 400);
        fail("Should have thrown IOException but did not!");
    }
    catch(IOException e) {
        assertEquals("Size limit reached: 400 B", e.getMessage());
        throw e;
    }
}