CommModel extends AbstractModel<CommUser> implements TickListener { void send(Message msg, double senderReliability) { if (msg.to().isPresent()) { if (usersDevices.containsKey(msg.to().get())) { final CommDevice recipient = usersDevices.get(msg.to().get()); doSend(msg, msg.to().get(), recipient, senderReliability); } } else { for (final Entry<CommUser, CommDevice> entry : usersDevices.entrySet()) { if (msg.from() != entry.getKey()) { doSend(msg, entry.getKey(), entry.getValue(), senderReliability); } } } } CommModel(RandomGenerator rng, Builder b); EventAPI getEventAPI(); @Override boolean register(CommUser commUser); @Override boolean unregister(CommUser commUser); boolean contains(CommUser commUser); double getDefaultReliability(); Optional<Double> getDefaultMaxRange(); @Override @Nonnull U get(Class<U> clazz); @Override void tick(TimeLapse timeLapse); @Override void afterTick(TimeLapse timeLapse); ImmutableBiMap<CommUser, CommDevice> getUsersAndDevices(); static Builder builder();  }
@Test public void testSendDirectMsgInputValidation() { boolean fail = false; try { agent1.device().send(Contents.YO, agent1); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); fail = false; final Agent unknown = new Agent(new Point(0, 0)); try { agent1.device().send(Contents.YO, unknown); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); }