@Test
public void testBuildWithErrorListener() throws Exception {

    final CompletableFuture<Map.Entry<String, String>> latch = new CompletableFuture<>();
    final ErrorListener errorListener = mock(ErrorListener.class);
    doAnswer(call -> latch.complete(toEntry(call.getArgument(1), call.getArgument(2))))
            .when(errorListener)
            .onJcrNamespaceRegistrationError(any(Throwable.class), anyString(), anyString());
    builder().withErrorListener(null).withErrorListener(errorListener)
            .withInitStage(new InitStage.Builder().withNs("jcr", "http://foo.com").build())
            .build().initAndInspect(session -> {
        assertEquals("jcr namespace is mapped correctly",
                NamespaceRegistry.NAMESPACE_JCR, session.getNamespaceURI("jcr"));
    });
    assertEquals("latch entry equals", toEntry("jcr", "http://foo.com"), latch.getNow(toEntry("", "")));
}