@Test
public void modifyConnectionClosesAndRestartsClientActor() {

    new TestKit(actorSystem) {{
        final TestProbe mockClientProbe = TestProbe.apply(actorSystem);
        final TestProbe commandSender = TestProbe.apply(actorSystem);
        final AtomicReference<Connection> latestConnection = new AtomicReference<>();
        final ActorRef underTest =
                TestConstants.createConnectionSupervisorActor(connectionId,
                        actorSystem,
                        proxyActor, (connection, proxyActor, connectionActor) -> {
                            latestConnection.set(connection);
                            return MockClientActor.props(mockClientProbe.ref());
                        },
                        TestConstants.dummyDittoProtocolSub(pubSubMediator, dittoProtocolSubMock),
                        pubSubMediator);
        // create connection
        underTest.tell(createConnection, commandSender.ref());
        mockClientProbe.expectMsg(openConnection);
        commandSender.expectMsg(createConnectionResponse);
        final ActorRef clientActor = watch(mockClientProbe.sender());
        expectSubscribe(TWIN_AND_LIVE_EVENTS, SUBJECTS);
        // modify connection
        underTest.tell(modifyConnection, commandSender.ref());
        // modify triggers a CloseConnection
        mockClientProbe.expectMsg(CloseConnection.of(connectionId, DittoHeaders.empty()));
        // unsubscribe is called for topics of unmodified connection
        expectRemoveSubscriber(1);
        expectTerminated(clientActor);
        // and sends an open connection (if desired state is open)
        mockClientProbe.expectMsg(openConnection);
        // finally the response is sent
        commandSender.expectMsg(modifyConnectionResponse);
        // modified connection contains an additional target for messages
        expectSubscribe(TWIN_AND_LIVE_EVENTS_AND_MESSAGES, SUBJECTS);
        Awaitility.await().untilAtomic(latestConnection, CoreMatchers.is(modifyConnection.getConnection()));
    }};
}