void () { PsiExpressionCodeFragment fragment = JavaCodeFragmentFactory.getInstance(getProject()).createExpressionCodeFragment("+ <caret>\"a\"", null, PsiType.getJavaLangObject(getPsiManager(), GlobalSearchScope.allScope(getProject())), true); myFile = fragment; Document document = Objects.requireNonNull(PsiDocumentManager.getInstance(getProject()).getDocument(fragment)); myEditor = EditorFactory.getInstance().createEditor(document, getProject(), JavaFileType.INSTANCE, false); ProperTextRange visibleRange = makeEditorWindowVisible(new Point(0, 0), myEditor); assertEquals(document.getTextLength(), visibleRange.getLength()); try { EditorInfo editorInfo = new EditorInfo(document.getText()); String newFileText = editorInfo.getNewFileText(); ApplicationManager.getApplication().runWriteAction(() -> { if (!document.getText().equals(newFileText)) { document.setText(newFileText); } editorInfo.applyToEditor(myEditor); }); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); HighlightInfo error = assertOneElement(highlightErrors()); assertEquals("Operator '+' cannot be applied to 'java.lang.String'", error.getDescription()); type(" "); HighlightInfo after = assertOneElement(highlightErrors()); assertEquals("Operator '+' cannot be applied to 'java.lang.String'", after.getDescription()); } finally { EditorFactory.getInstance().releaseEditor(myEditor); } }