void () { Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]"); final Editor editor = EditorFactory.getInstance().createEditor(document); try { final FoldRegion[] fold = new FoldRegion[1]; editor.getFoldingModel().runBatchFoldingOperation(() -> fold[0] = editor.getFoldingModel().addFoldRegion(0, 2, "")); RangeMarker marker = document.createRangeMarker(0, 2); deleteString(document, 1, 2); assertTrue(marker.isValid()); assertNotNull(fold[0]); } finally { EditorFactory.getInstance().releaseEditor(editor); } }