CommDeviceBuilder { public CommDevice build() { checkState(!used, "Only one communication device can be created per user, user: %s.", user); used = true; return new CommDevice(this); } CommDeviceBuilder(CommModel m, CommUser u); CommDeviceBuilder setReliability(double reliability); CommDeviceBuilder setMaxRange(double range); CommDevice build();  }
@Test public void testCanBuildOnlyOnce() { boolean fail = false; builder.build(); try { builder.build(); } catch (final IllegalStateException e) { fail = true; } assertTrue(fail); }