void () { final VirtualFile vFile = myFixture.addFileToProject("Foo.test", "Foo").getVirtualFile(); assertEquals(PlainTextFileType.INSTANCE, vFile.getFileType()); final PsiSearchHelper helper = PsiSearchHelper.getInstance(getProject()); assertOneElement(helper.findFilesWithPlainTextWords("Foo")); final Document document = FileDocumentManager.getInstance().getDocument(vFile); //todo should file type be changed silently without events? //assertEquals(UnknownFileType.INSTANCE, vFile.getFileType()); final PsiFile file = PsiDocumentManager.getInstance(getProject()).getPsiFile(document); assertInstanceOf(file, PsiPlainTextFile.class); assertEquals("Foo", file.getText()); assertOneElement(helper.findFilesWithPlainTextWords("Foo")); WriteCommandAction.runWriteCommandAction(getProject(), () -> { document.insertString(0, " "); assertEquals("Foo", file.getText()); assertOneElement(helper.findFilesWithPlainTextWords("Foo")); FileDocumentManager.getInstance().saveDocument(document); assertEquals("Foo", file.getText()); assertOneElement(helper.findFilesWithPlainTextWords("Foo")); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); assertEquals(" Foo", file.getText()); assertOneElement(helper.findFilesWithPlainTextWords("Foo")); }); }