### Question:
ModifyOnce { public void set(final T data) { Preconditions.checkState(!modified, "Has already been modified once."); this.data = data; this.modified = true; } ModifyOnce();  ModifyOnce(final T defaultData); T get(); void set(final T data);  }### Answer:
@Test public void testThrowOnSecondModification() { final ModifyOnce<String> instance = new ModifyOnce<>(); instance.set("First modification"); expectedException.expect(IllegalStateException.class); instance.set("Second modification"); }