assertEquals(0, agent1.device().getReceivedCount()); assertEquals(0, agent1.device().getUnreadCount()); assertEquals(1, rangedNoPos.device().getOutbox().size()); assertEquals(0, ranged.device().getReceivedCount()); assertEquals(0, noPos.device().getReceivedCount()); assertEquals(2, rangedNoPos.device().getOutbox().size()); final List<Message> msgs = rangedNoPos.device().getOutbox(); assertFalse(msgs.get(0).isBroadcast()); assertTrue(msgs.get(1).isBroadcast()); assertEquals(1, ranged.device().getOutbox().size()); model.afterTick(TimeLapseFactory.create(0, 100)); assertEquals(1, rangedNoPos.device().getReceivedCount());
/** * Tests what happens if an agent no longer has a position. */ @Test public void testSenderIsRemovedDuringSend() { final Agent a = new Agent(new Point(0, 0)); final Agent b = new RangedAgent(new Point(0, 0), 5); model.register(a); model.register(b); // a is removed during the same tick as that it sends a message, this // doesn't matter since it has no range, therefore it sends anyway. a.device().broadcast(Contents.YO); a.setPosition(null); model.afterTick(TimeLapseFactory.create(0, 100)); assertEquals(1, agent1.device().getReceivedCount()); // b is removed during the same tick as that is sends a message, since it is // a ranged device the message is not sent and will stay in the outbox. b.device().broadcast(Contents.YO); b.setPosition(null); model.afterTick(TimeLapseFactory.create(0, 100)); assertEquals(1, agent1.device().getReceivedCount()); assertEquals(1, b.device().getOutbox().size()); }