}
@Test(groups = "fast")
public void testEnter() throws Exception {
// Verify no candidates
MockWatcher mockWatcher = new MockWatcher();
List<String> candidates = zk1.getChildren(electionRoot, mockWatcher);
Assert.assertTrue(candidates.isEmpty());
// Enter the candidate and run any callbacks
zkLeaderElection1.enter();
mockExecutor1.drain();
// Check that candidate is created
candidates = zk1.getChildren(electionRoot, null);
Assert.assertEquals(candidates.size(), 1);
// Check that candidate is elected
Assert.assertTrue(mockLeaderElectionCallback1.isElected());
mockLeaderElectionCallback1.resetElected();
Assert.assertEquals(zkLeaderElection1.getLeader(), candidates.get(0));
// Check data contents
String data = VariablePayload.decode(
zk1.getData(electionRoot + "/" + candidates.get(0), null, null)
);
Assert.assertEquals(data, testData1);
// Check that external watch was notified of candidate creation
Assert.assertEquals(mockWatcher.getEventQueue().size(), 1);
WatchedEvent watchedEvent = mockWatcher.getEventQueue().remove();
Assert.assertEquals(watchedEvent.getType(), EventType.NodeChildrenChanged);
Assert.assertEquals(watchedEvent.getPath(), electionRoot);
}