CheckedDatastoreReaderWriter { static <T> T call(Supplier<T> f) throws IOException { try { return f.get(); } catch (DatastoreException e) { throw new DatastoreIOException(e); } catch (RuntimeIOException e) { throw e.getCause(); } } CheckedDatastoreReaderWriter(DatastoreReaderWriter rw);   }
@Test public void callShouldThrowCheckedException() throws IOException { exception.expect(IOException.class); exception.expectCause(is((Throwable) CAUSE)); CheckedDatastoreReaderWriter.call(() -> { throw CAUSE; }); }
@Test public void call() throws IOException { when(supplier.get()).thenReturn("foobar"); assertThat(CheckedDatastoreReaderWriter.call(supplier), is("foobar")); verify(supplier).get(); }
@Test public void callShouldPropagateIOException() throws IOException { final IOException cause = new IOException("foobar"); exception.expect(is(cause)); CheckedDatastoreReaderWriter.call(() -> { throw new RuntimeIOException(cause); }); }