@Test
public void testGetConnection() {

    //set up data tree mock
    final CursorAwareDataTreeModification modification = mock(CursorAwareDataTreeModification.class);
    when(modification.readNode(YangInstanceIdentifier.empty())).thenReturn(Optional.empty());
    final DataTreeSnapshot snapshot = mock(DataTreeSnapshot.class);
    when(snapshot.newModification()).thenReturn(modification);
    final DataTree dataTree = mock(DataTree.class);
    when(dataTree.takeSnapshot()).thenReturn(snapshot);
    final TestProbe backendProbe = new TestProbe(system, "backend");
    final long shard = 0L;
    behavior.createTransaction().read(YangInstanceIdentifier.empty());
    final AbstractClientConnection<ShardBackendInfo> connection = behavior.getConnection(shard);
    //check cached connection for same shard
    Assert.assertSame(connection, behavior.getConnection(shard));
    final ConnectClientRequest connectClientRequest = actorContextProbe.expectMsgClass(ConnectClientRequest.class);
    Assert.assertEquals(CLIENT_ID, connectClientRequest.getTarget());
    final long sequence = 0L;
    Assert.assertEquals(sequence, connectClientRequest.getSequence());
    actorContextProbe.reply(new ConnectClientSuccess(CLIENT_ID, sequence, backendProbe.ref(),
            Collections.emptyList(), dataTree, 3));
    Assert.assertEquals(clientActorProbe.ref(), connection.localActor());
    //capture and execute command passed to client context
    final InternalCommand<ShardBackendInfo> command = clientActorProbe.expectMsgClass(InternalCommand.class);
    command.execute(behavior);
    //check, whether command was reaplayed
    verify(modification).readNode(YangInstanceIdentifier.empty());
}