EditableText { public void apply(TextChange textChange) { if (textChange.getVersion() != this.version) { throw new RuntimeException("The version of this text (" + version + ") is not the same as the version to which this change applies (" + textChange.getVersion() + ")."); } currentText = textChange.applyTo(currentText); version = version + 1; } EditableText(String s); TextChange insert(String toInsert, int position); String getText(); void apply(TextChange textChange); int getVersion(); TextChange delete(int start, int end);  }
@Test(expected = RuntimeException.class) public void shouldNotApplyChangeToOlderVersion() { text.apply(insertion(1, "edited ", 12)); }