CheckedDatastoreReaderWriter { Entity get(Key key) throws IOException { return call(() -> rw.get(key)); } CheckedDatastoreReaderWriter(DatastoreReaderWriter rw);   }
@Test public void getSingleShouldThrowCheckedException() throws IOException { when(rw.get(key1)).thenThrow(CAUSE); exception.expect(IOException.class); exception.expectCause(is((Throwable) CAUSE)); sut.get(key1); }
@Test public void getSingle() throws IOException { when(rw.get(key1)).thenReturn(entity1); assertThat(sut.get(key1), is(entity1)); verify(rw).get(key1); }
@Test public void getAndConsumeShouldThrowCheckedException() throws IOException { when(rw.get(key1, key2)).thenThrow(CAUSE); exception.expect(IOException.class); exception.expectCause(is((Throwable) CAUSE)); sut.get(List.of(key1, key2), entity -> fail()); }
@Test public void getAndConsume() throws IOException { when(rw.get(key1, key2)).thenReturn(Stream.of(entity1, entity2).iterator()); sut.get(List.of(key1, key2), entityConsumer); verify(rw).get(key1, key2); verify(entityConsumer).accept(entity1); verify(entityConsumer).accept(entity2); }
@Test public void getAndConsumeShouldPropagateIOException() throws IOException { final IOException cause = new IOException("foo"); doReturn(Stream.of(entity1, entity2).iterator()).when(rw).get(key1, key2); exception.expect(is(cause)); sut.get(List.of(key1, key2), entity -> { throw cause; }); }
@Test public void getAndConsumeShouldHandleForEachRemainingThrowing() throws IOException { doThrow(CAUSE).when(entityIterator).forEachRemaining(any()); doReturn(entityIterator).when(rw).get(key1, key2); exception.expect(IOException.class); exception.expectCause(is((Throwable) CAUSE)); sut.get(List.of(key1, key2), entity -> fail()); }
@Test public void getListShouldThrowCheckedException() throws IOException { when(rw.get(key1, key2)).thenThrow(CAUSE); exception.expect(IOException.class); exception.expectCause(is((Throwable) CAUSE)); sut.get(List.of(key1, key2)); }
@Test public void getList() throws IOException { when(rw.get(key1, key2)).thenReturn(Stream.of(entity1, entity2).iterator()); assertThat(sut.get(List.of(key1, key2)), is(List.of(entity1, entity2))); verify(rw).get(key1, key2); }