void () { setFileType(XmlFileType.INSTANCE); String text1 = "<rf oot><xc></root>"; String text2 = "<root><f xc></root>"; // moved "f " to another place prepareFile(text1, ""); Document document = myDummyFile.getViewProvider().getDocument(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { ((XmlFile)myDummyFile).getRootTag().replace(XmlElementFactory.getInstance(getProject()).createTagFromText(text2)); }); PsiTestUtil.checkFileStructure(myDummyFile); assertEquals(text2, myDummyFile.getText()); assertEquals(text2, document.getText()); }