void (final PsiFile file, final String text, String textAfter) { final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file); assert document != null; final EditorImpl editor; if (doCheckDocumentUpdate()) { editor =(EditorImpl)FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file.getVirtualFile(), 0), false); assert editor != null; if (myFile != null) { FileEditorManager.getInstance(getProject()).closeFile(myFile.getVirtualFile()); } myEditor = editor; myFile = file; } WriteCommandAction.runWriteCommandAction(getProject(), () -> { document.replaceString(0, document.getTextLength(), text); PsiDocumentManager.getInstance(getProject()).commitDocument(document); assertEquals(file.getText(), document.getText()); try { if (doReformatRangeTest) { CodeStyleManager.getInstance(getProject()) .reformatRange(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset()); } else if (myTextRange != null) { CodeStyleManager.getInstance(getProject()).reformatText(file, myTextRange.getStartOffset(), myTextRange.getEndOffset()); } else { CodeStyleManager.getInstance(getProject()) .reformatText(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset()); } } catch (IncorrectOperationException e) { fail(); } }); assertEquals(textAfter, document.getText()); PsiDocumentManager.getInstance(getProject()).commitDocument(document); assertEquals(textAfter, file.getText()); }