@Test
public void exceptionDueToCustomValidator() {

    new TestKit(actorSystem) {{
        final Props connectionActorProps =
                ConnectionPersistenceActor.props(TestConstants.createRandomConnectionId(),
                        TestConstants.dummyDittoProtocolSub(pubSubMediator), proxyActor,
                        mockClientActorPropsFactory,
                        (command, connection) -> {
                            throw ConnectionUnavailableException.newBuilder(connectionId)
                                    .dittoHeaders(command.getDittoHeaders())
                                    .message("not valid")
                                    .build();
                        });
        // create another actor because we want to test if the child is terminated
        final TestKit parent = new TestKit(actorSystem);
        final ActorRef connectionActorRef = watch(parent.childActorOf(connectionActorProps));
        // create connection
        connectionActorRef.tell(createConnection, parent.getRef());
        // expect ConnectionUnavailableException sent to parent
        final ConnectionUnavailableException exception =
                parent.expectMsgClass(ConnectionUnavailableException.class);
        assertThat(exception).hasMessageContaining("not valid");
        // do not expect passivation; it only happens for graceful shutdown.
    }};
}