CommModel extends AbstractModel<CommUser> implements TickListener { @Override public boolean register(CommUser commUser) { checkArgument(!contains(commUser), "%s is already registered.", commUser); if (unregisteredUsersDevices.containsKey(commUser)) { final CommDevice dev = unregisteredUsersDevices.remove(commUser); dev.register(); addDevice(dev, commUser); } else { final CommDeviceBuilder builder = CommDevice.builder(this, commUser) .setReliability(defaultReliability); commUser.setCommDevice(builder); checkState( builder.isUsed(), "%s is not implemented correctly, a CommDevice must be constructed in" + " setCommDevice()", commUser); } return true; } 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 testRegister() { assertTrue(model.contains(agent1)); boolean fail = false; try { model.register(agent1); } catch (final IllegalArgumentException e) { fail = true; } assertTrue(fail); }