void (@NotNull TreeTest test, boolean strict, int keepSelectionLevel, @NotNull Runnable onDone) { test.getTree().addTreeExpansionListener(new TreeExpansionListener() { @Override public void treeCollapsed(TreeExpansionEvent event) { } @Override public void treeExpanded(TreeExpansionEvent event) { throw new UnsupportedOperationException("do not expand while collapse"); } }); TreeUtil.collapseAll(test.getTree(), strict, keepSelectionLevel); onDone.run(); }