void (@NotNull Project project, @NotNull String ext, @NotNull String before, @NotNull String after, @NotNull Action action) { String fileName = "FTU." + ext; FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName); FormatData data = extractFormatData(before); PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(fileName, fileType, data.text, System.currentTimeMillis(), true); PsiDocumentManager manager = PsiDocumentManager.getInstance(project); Document document = manager.getDocument(file); if (document == null) { throw new IllegalStateException("Document is null"); } TestFormatAction formatAction = ACTIONS.get(action); if (formatAction == null) { throw new IllegalStateException("Format action is null"); } WriteCommandAction.runWriteCommandAction(project, () -> formatAction.run(file, data.startOffset, data.endOffset)); Assert.assertEquals(after, document.getText()); }