@Test(expected = AbortedScanException.class)
public void testProcessPackageUrl_abortOnRefreshFailure() throws Exception {

    final File testPackage = TestPackageUtil.prepareTestPackage("tmp_foo_bar.zip");
    final Session session = mock(Session.class);
    doThrow(RepositoryException.class).when(session).refresh(false);
    // the manager mock will only be accessed on a failure, so we need to be lenient with unused stubs checking
    final JcrPackageManager manager = mock(JcrPackageManager.class, withSettings().lenient());
    // if the method reaches the manager.upload() call, we have failed to discard our session changes
    // so we throw a NullPointerException since that is not expected for this test, and not caught by the
    // upload try block
    doThrow(NullPointerException.class).when(manager)
            .upload(any(InputStream.class), anyBoolean(), anyBoolean());
    builder().build().processPackageUrl(session, manager, false, testPackage.toURI().toURL());
}