@Test
public void testOnDataTreeChanged() throws Exception {

    TestKit kit = new TestKit(getSystem());
    new CandidateListChangeListener(kit.getRef(), "test").init(shardDataTree);
    String memberName1 = "member-1";
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName1));
    CandidateAdded candidateAdded = kit.expectMsgClass(CandidateAdded.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateAdded.getEntityPath());
    assertEquals("getNewCandidate", memberName1, candidateAdded.getNewCandidate());
    assertEquals("getAllCandidates", ImmutableSet.of(memberName1),
            ImmutableSet.copyOf(candidateAdded.getAllCandidates()));
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName1));
    kit.expectNoMessage(Duration.ofMillis(500));
    String memberName2 = "member-2";
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName2));
    candidateAdded = kit.expectMsgClass(CandidateAdded.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateAdded.getEntityPath());
    assertEquals("getNewCandidate", memberName2, candidateAdded.getNewCandidate());
    assertEquals("getAllCandidates", ImmutableSet.of(memberName1, memberName2),
            ImmutableSet.copyOf(candidateAdded.getAllCandidates()));
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID2, memberName1));
    candidateAdded = kit.expectMsgClass(CandidateAdded.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID2), candidateAdded.getEntityPath());
    assertEquals("getNewCandidate", memberName1, candidateAdded.getNewCandidate());
    assertEquals("getAllCandidates", ImmutableSet.of(memberName1),
            ImmutableSet.copyOf(candidateAdded.getAllCandidates()));
    deleteNode(candidatePath(ENTITY_TYPE, ENTITY_ID1, memberName1));
    CandidateRemoved candidateRemoved = kit.expectMsgClass(CandidateRemoved.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateRemoved.getEntityPath());
    assertEquals("getRemovedCandidate", memberName1, candidateRemoved.getRemovedCandidate());
    assertEquals("getRemainingCandidates", ImmutableSet.of(memberName2),
            ImmutableSet.copyOf(candidateRemoved.getRemainingCandidates()));
    deleteNode(candidatePath(ENTITY_TYPE, ENTITY_ID1, memberName2));
    candidateRemoved = kit.expectMsgClass(CandidateRemoved.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateRemoved.getEntityPath());
    assertEquals("getRemovedCandidate", memberName2, candidateRemoved.getRemovedCandidate());
    assertEquals("getRemainingCandidates", ImmutableSet.of(),
            ImmutableSet.copyOf(candidateRemoved.getRemainingCandidates()));
}