public AgentInstance register(AgentRuntimeInfo runtimeInfo) {
        AgentInstance agentInstance = findAgentAndRefreshStatus(runtimeInfo.getUUId());
        if (!agentInstance.isRegistered()) {
            if (isMaxPendingAgentsLimitReached()) {
                throw new MaxPendingAgentsLimitReachedException(systemEnvironment.get(MAX_PENDING_AGENTS_ALLOWED));
            }
            agentInstance = AgentInstance.createFromLiveAgent(runtimeInfo, systemEnvironment, agentStatusChangeListener);
            this.add(agentInstance);
        }
        agentInstance.update(runtimeInfo);
        return agentInstance;
    }
@Test
    void registerShouldThrowExceptionWhenMaxPendingAgentsLimitIsReached() {
        Agent agent = new Agent("uuid2", "CCeDev01", "10.18.5.1");
        AgentInstances agentInstances = new AgentInstances(systemEnvironment, listener, pending());
        when(systemEnvironment.get(MAX_PENDING_AGENTS_ALLOWED)).thenReturn(1);

        MaxPendingAgentsLimitReachedException e = assertThrows(MaxPendingAgentsLimitReachedException.class,
                () -> agentInstances.register(fromServer(agent, false, "/var/lib", 0L, "linux")));
        assertThat(e.getMessage(), is("Max pending agents allowed 1, limit reached"));
    }