@Test
public void testSwitchBehavior() {

    String persistenceId = factory.generateActorId("leader-");
    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    config.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
    config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    config.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS));
    config.setSnapshotBatchCount(5);
    DataPersistenceProvider dataPersistenceProvider = createProvider();
    Map<String, String> peerAddresses = ImmutableMap.<String, String>builder().build();
    TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(
            MockRaftActor.props(persistenceId, peerAddresses, config, dataPersistenceProvider), persistenceId);
    MockRaftActor leaderActor = mockActorRef.underlyingActor();
    leaderActor.waitForRecoveryComplete();
    leaderActor.handleCommand(new SwitchBehavior(RaftState.Follower, 100));
    assertEquals(100, leaderActor.getRaftActorContext().getTermInformation().getCurrentTerm());
    assertEquals(RaftState.Follower, leaderActor.getCurrentBehavior().state());
    leaderActor.handleCommand(new SwitchBehavior(RaftState.Leader, 110));
    assertEquals(110, leaderActor.getRaftActorContext().getTermInformation().getCurrentTerm());
    assertEquals(RaftState.Leader, leaderActor.getCurrentBehavior().state());
    leaderActor.handleCommand(new SwitchBehavior(RaftState.Candidate, 125));
    assertEquals(110, leaderActor.getRaftActorContext().getTermInformation().getCurrentTerm());
    assertEquals(RaftState.Leader, leaderActor.getCurrentBehavior().state());
    leaderActor.handleCommand(new SwitchBehavior(RaftState.IsolatedLeader, 125));
    assertEquals(110, leaderActor.getRaftActorContext().getTermInformation().getCurrentTerm());
    assertEquals(RaftState.Leader, leaderActor.getCurrentBehavior().state());
}