public boolean tryAdd(final Agent agent)
    {
        Objects.requireNonNull(agent, "agent cannot be null");

        if (Status.ACTIVE != status)
        {
            throw new IllegalStateException("add called when not active");
        }

        return addAgent.compareAndSet(null, agent);
    }
@Test
    void shouldDetectConcurrentAdd()
    {
        final Agent mockAgentOne = mock(Agent.class);
        final Agent mockAgentTwo = mock(Agent.class);

        final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME, mockAgentOne, mockAgentTwo);
        final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent);
        invoker.start();

        assertTrue(compositeAgent.tryAdd(mockAgentOne));
        assertFalse(compositeAgent.tryAdd(mockAgentTwo));

        invoker.invoke();
        assertTrue(compositeAgent.tryAdd(mockAgentTwo));
    }