void () { FoldingGroup group = FoldingGroup.newGroup("test"); FoldRegion[] regions = new FoldRegion[2]; myModel.runBatchFoldingOperation(() -> { regions[0] = myModel.createFoldRegion(1, 2, "a", group, false); regions[1] = myModel.createFoldRegion(3, 4, "b", group, false); }); assertNotNull(regions[0]); assertNotNull(regions[1]); List<FoldRegion> regionsInGroup = myModel.getGroupedRegions(group); assertTrue(regionsInGroup.size() == 2 && regionsInGroup.containsAll(Arrays.asList(regions))); runWriteCommand(() -> getEditor().getDocument().deleteString(0, 3)); assertFalse(regions[0].isValid()); assertTrue(regions[1].isValid()); List<FoldRegion> newRegionsInGroup = myModel.getGroupedRegions(group); assertEquals(Collections.singletonList(regions[1]), newRegionsInGroup); }