@Test
public void shouldThrowStorageExceptionIfExceptionThrownInCallToInitialize() {

    // create a broken snapshotsStore that we will use to test the DB failure out on
    DBI brokenDBI = mock(DBI.class);
    OnDiskSnapshotsStore brokenSnapshotStore = new OnDiskSnapshotsStore(brokenDBI, snapshotsDirectory.getAbsolutePath());
    // fail the moment a handle is requested
    IllegalArgumentException failure = new IllegalArgumentException("failed!");
    when(brokenDBI.open()).thenThrow(failure);
    when(brokenDBI.withHandle(any(HandleCallback.class))).thenCallRealMethod(); // calling the real method will trigger the call to open() above and cause execute the 'catch' etc. logic
    // attempt to initialize
    // we should throw an exception the moment we attempt to create the table
    boolean exceptionThrown = false;
    try {
        brokenSnapshotStore.initialize();
    } catch (StorageException e) {
        exceptionThrown = true;
        assertThat(e.getCause(), Matchers.<Throwable>sameInstance(failure));
    }
    // the initialization should have failed
    assertThat(exceptionThrown, is(true));
}