void (boolean eventSystemEnabled) { String text1 = "import a.Foo1Bar;"; String text2 = "import a.Foo2Bar;"; PsiFileFactory factory = PsiFileFactory.getInstance(myProject); PsiJavaFile file = (PsiJavaFile)factory .createFileFromText("a.java", JavaLanguage.INSTANCE, text2, eventSystemEnabled, false); Document document = file.getViewProvider().getDocument(); PsiImportStatement statement = file.getImportList().getImportStatements()[0]; SmartPsiFileRange pointer = getPointerManager().createSmartPsiFileRangePointer(file, statement.getImportReference().getTextRange()); WriteCommandAction.runWriteCommandAction(myProject, () -> { file.getImportList().add(createImportFromText(text1)); }); assertEquals(text2, statement.getText()); assertEquals(statement.getImportReference().getTextRange(), pointer.getRange()); assertTrue(document.getText(), document.getText().startsWith(text1)); }