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

  final InputStream r = this.getClass().getResourceAsStream("/cover.png");
  final String s = withResource(r, new Function<InputStream, String>() {
    @Override
    public String apply(InputStream in) {
      return "read";
    }
  });
  assertEquals("read", s);
  // this will throw an IOException
  r.read();
}