@Test
public void testProcessSubpackage_onSubpackageException() throws Exception {

    final JcrPackageManager manager = mock(JcrPackageManager.class);
    doThrow(RepositoryException.class).when(manager).open(any(PackageId.class));
    final PackageId root = PackageId.fromString("my_packages:subsubtest");
    final PackageId sub1 = PackageId.fromString("my_packages:subtest");
    final Session session = mock(Session.class);
    final CompletableFuture<Exception> eLatch = new CompletableFuture<>();
    final CompletableFuture<PackageId> idLatch = new CompletableFuture<>();
    final ErrorListener errorListener = mock(ErrorListener.class);
    doAnswer(call -> {
        eLatch.complete(call.getArgument(0, Exception.class));
        idLatch.complete(call.getArgument(1, PackageId.class));
        return true;
    }).when(errorListener).onSubpackageException(any(Exception.class), any(PackageId.class));
    builder().withErrorListener(errorListener).build()
            .processSubpackage(session, manager, sub1, root, false);
    assertTrue("error is of type", eLatch.getNow(null) instanceof RepositoryException);
    assertEquals("package id is", sub1, idLatch.getNow(null));
}