public void testClientCommandSenderStateListener() throws Exception {
AgentMain agent1 = m_agent1Test.createAgent(true);
m_agent2Test.createAgent(true);
final Boolean[] state = new Boolean[1];
ClientCommandSenderStateListener listener = new ClientCommandSenderStateListener() {
public boolean stoppedSending(ClientCommandSender sender) {
state[0] = Boolean.FALSE;
return true;
}
public boolean startedSending(ClientCommandSender sender) {
state[0] = Boolean.TRUE;
return true;
}
};
assert state[0] == null : "This was just to prove we are null at the start - very weird for this to fail";
assert agent1.getClientCommandSender().isSending() : "Setup of this test should have started the sender";
agent1.getClientCommandSender().addStateListener(listener, false);
assert state[0] == null : "We told it not to notify us immediately - should not have called the listener";
agent1.getClientCommandSender().removeStateListener(listener);
agent1.getClientCommandSender().addStateListener(listener, true);
assert state[0].booleanValue() : "Listener should have been told the sender is sending";
agent1.getClientCommandSender().stopSending(false);
assert !state[0].booleanValue() : "Listener should have told us we are no longer sending";
agent1.getClientCommandSender().startSending();
assert state[0].booleanValue() : "Listener should have told us we are sending again";
agent1.getClientCommandSender().removeStateListener(listener);
ClientCommandSenderStateListener one_time_listener = new ClientCommandSenderStateListener() {
public boolean stoppedSending(ClientCommandSender sender) {
state[0] = Boolean.FALSE;
return false;
}