@Test
public void testServerListHasChanged() throws Exception
{

    InstanceConfig config = new InstanceConfig()
    {
        @Override
        public String getString(StringConfigs config)
        {
            switch ( config )
            {
                case SERVERS_SPEC:
                {
                    return "S:1:foo,S:2:bar";
                }
            }
            return null;
        }
        @Override
        public int getInt(IntConfigs config)
        {
            return 0;
        }
    };
    Exhibitor mockExhibitor = makeMockExhibitor(config, "foo");
    MonitorRunningInstance monitor = new MonitorRunningInstance(mockExhibitor);
    StateAndLeader stateAndLeader = monitor.getStateAndLeader();
    InstanceState localCurrentInstanceState = new InstanceState(new ServerList(config.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(config));
    InstanceConfig newConfig = new InstanceConfig()
    {
        @Override
        public String getString(StringConfigs config)
        {
            switch ( config )
            {
                case SERVERS_SPEC:
                {
                    return "S:1:foo,S:2:bar,O:3:snafu"; // observer added
                }
            }
            return null;
        }
        @Override
        public int getInt(IntConfigs config)
        {
            return 0;
        }
    };
    InstanceState instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertFalse(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
    newConfig = new InstanceConfig()
    {
        @Override
        public String getString(StringConfigs config)
        {
            switch ( config )
            {
                case SERVERS_SPEC:
                {
                    return "S:1:foo,S:2:bar,S:3:snafu"; // standard added
                }
            }
            return null;
        }
        @Override
        public int getInt(IntConfigs config)
        {
            return 0;
        }
    };
    instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
    newConfig = new InstanceConfig()
    {
        @Override
        public String getString(StringConfigs config)
        {
            switch ( config )
            {
                case SERVERS_SPEC:
                {
                    return "O:1:foo,S:2:bar"; // "us" changed to observer
                }
            }
            return null;
        }
        @Override
        public int getInt(IntConfigs config)
        {
            return 0;
        }
    };
    instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
    newConfig = new InstanceConfig()
    {
        @Override
        public String getString(StringConfigs config)
        {
            switch ( config )
            {
                case SERVERS_SPEC:
                {
                    return "S:1:foo,O:2:bar"; // not-us changed to observer
                }
            }
            return null;
        }
        @Override
        public int getInt(IntConfigs config)
        {
            return 0;
        }
    };
    instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
}