void (boolean checkForegroundColor, Segment @NotNull ... expectedSegments) { EditorEx editor = (EditorEx)getEditor(); IterationState.CaretData caretData = IterationState.createCaretData(editor); IterationState iterationState = new IterationState(editor, 0, editor.getDocument().getTextLength(), caretData, false, false, true, false); List<Segment> actualSegments = new ArrayList<>(); do { Segment segment = new Segment(iterationState.getStartOffset(), iterationState.getEndOffset(), checkForegroundColor ? iterationState.getMergedAttributes().getForegroundColor() : iterationState.getMergedAttributes().getBackgroundColor()); actualSegments.add(segment); iterationState.advance(); } while (!iterationState.atEnd()); Assert.assertArrayEquals(expectedSegments, actualSegments.toArray()); }