void (@NotNull JTextComponent editorComponent, CaretAction @NotNull ... caretActions) { /* * The implementation expects the following flow: * action.run() => caretUpdate() => returning control to the caller of action.run() */ final Ref<@Nullable CaretPos> caretUpdateNotification = new Ref<>(null); final int[] i = {0}; // a reference to a mutable int final CaretListener listener = (event) -> { assertNull("a new unexpected caretUpdateNotification at CaretAction #" + i[0] + ": " + caretUpdateNotification.get(), caretUpdateNotification.get()); caretUpdateNotification.set(new CaretPos(event.getDot(), event.getMark())); }; editorComponent.addCaretListener(listener); for (; i[0] < caretActions.length; ++i[0]) { caretActions[i[0]].action.run(); final var gotCaretUpdateNotification = caretUpdateNotification.get(); caretUpdateNotification.set(null); assertEquals("the wrong position(s) of the caret notification of CaretAction #" + i[0], caretActions[i[0]].caretUpdateNotification, gotCaretUpdateNotification); } editorComponent.removeCaretListener(listener); assertNull("a new unexpected caretUpdateNotification?", caretUpdateNotification.get()); }