void () { final XmlTag aTag = XmlElementFactory.getInstance(getProject()).createTagFromText("<a><b/></a>"); final XmlTag bTag = aTag.findFirstSubTag("b"); WriteCommandAction.runWriteCommandAction(null, () -> { PsiElement cTag = bTag.replace(XmlElementFactory.getInstance(getProject()).createTagFromText("<c/>")); assertEquals(1, aTag.getSubTags().length); assertEquals(cTag, aTag.getSubTags()[0]); }); }