void () { final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("a.java", "class A{}"); Document document = file.getViewProvider().getDocument(); document.insertString(0, " "); PsiClass psiClass = file.getClasses()[0]; try { psiClass.addBefore(PsiParserFacade.getInstance(getProject()).createWhiteSpaceFromText(" "), psiClass.getLBrace()); fail(); } catch (IllegalStateException e) { assertEquals("Attempt to modify PSI for non-committed Document!", e.getMessage()); } assertEquals("class A{}", psiClass.getText()); assertEquals(" class A{}", document.getText()); }