@Test
public void testRegisterRoleChangeListener() {

    final ShardTestKit testKit = new ShardTestKit(getSystem());
    final TestActorRef<Shard> shard = actorFactory.createTestActor(
        newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
        "testRegisterRoleChangeListener");
    ShardTestKit.waitUntilLeader(shard);
    final ActorRef listener = getSystem().actorOf(MessageCollectorActor.props());
    shard.tell(new RegisterRoleChangeListener(), listener);
    MessageCollectorActor.expectFirstMatching(listener, RegisterRoleChangeListenerReply.class);
    ShardLeaderStateChanged leaderStateChanged = MessageCollectorActor.expectFirstMatching(listener,
        ShardLeaderStateChanged.class);
    assertTrue("getLocalShardDataTree present", leaderStateChanged.getLocalShardDataTree().isPresent());
    assertSame("getLocalShardDataTree", shard.underlyingActor().getDataStore().getDataTree(),
        leaderStateChanged.getLocalShardDataTree().get());
    MessageCollectorActor.clearMessages(listener);
    // Force a leader change
    shard.tell(new RequestVote(10000, "member2", 50, 50), testKit.getRef());
    leaderStateChanged = MessageCollectorActor.expectFirstMatching(listener, ShardLeaderStateChanged.class);
    assertFalse("getLocalShardDataTree present", leaderStateChanged.getLocalShardDataTree().isPresent());
}