void () { @Language("JAVA") String initialText = """ class Test { void test1() { } void test2() { } } """; Function<String, FoldRegion> fold = methodName -> { String text = myFixture.getEditor().getDocument().getText(); int nameIndex = text.indexOf(methodName); int start = text.indexOf("{", nameIndex); int end = text.indexOf("}", start) + 1; FoldRegion[] regions = myFixture.getEditor().getFoldingModel().getAllFoldRegions(); for (FoldRegion region : regions) { if (region.getStartOffset() == start && region.getEndOffset() == end) { return region; } } fail("Can't find target fold region for method with name '" + methodName + "'. Registered regions: " + Arrays.toString(regions)); return null; }; configure(initialText); FoldingModelEx foldingModel = (FoldingModelEx)myFixture.getEditor().getFoldingModel(); foldingModel.runBatchFoldingOperation(() -> { fold.apply("test1").setExpanded(true); collapse(fold.apply("test2")); }); myFixture.getEditor().getCaretModel().moveToOffset(initialText.indexOf("void")); myFixture.performEditorAction("MoveStatementDown"); CodeFoldingManager.getInstance(getProject()).updateFoldRegions(myFixture.getEditor()); assertTrue(fold.apply("test1").isExpanded()); assertFalse(fold.apply("test2").isExpanded()); myFixture.performEditorAction("MoveStatementUp"); CodeFoldingManager.getInstance(getProject()).updateFoldRegions(myFixture.getEditor()); assertTrue(fold.apply("test1").isExpanded()); assertFalse(fold.apply("test2").isExpanded()); }