package com.intellij.codeInsight.template;

import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;

public class TemplateBuilderTest extends LightCodeInsightFixtureTestCase {
  public void testRunInlineTemplate() throws Throwable {
    TemplateManagerImpl.setTemplateTesting(myFixture.getProject(), getTestRootDisposable());
    myFixture.configureByText("a.java", "class A {\n" +
                                        "  public String tes<caret>t() {\n" +
                                        "  }\n" +
                                        "}");
    new WriteCommandAction.Simple<Void>(myFixture.getProject(), myFixture.getFile()) {
      @Override
      protected void run() throws Throwable {
        TemplateBuilderFactory.getInstance().createTemplateBuilder(myFixture.getElementAtCaret())
          .run(myFixture.getEditor(), true);
      }
    }.execute();
    myFixture.checkResult("class A {\n" +
                          "  <caret>public String test() {\n" +
                          "  }\n" +
                          "}");
  }
}

@@ -700,12 +700,8 @@
     
-new 
 Writ
@@ -719,20 +719,29 @@
 ion.
-Simple%3CVoid%3E
+runWriteCommandAction
 (myF
@@ -765,28 +765,22 @@
 (), 
-myFixture.getFi
+new Runnab
 le()
-)
  %7B%0A 
@@ -805,16 +805,13 @@
    p
-rotected
+ublic
  voi
@@ -817,33 +817,16 @@
 id run()
- throws Throwable
  %7B%0A     
@@ -917,27 +917,16 @@
 Caret())
-%0A          
 .run(myF
@@ -969,17 +969,8 @@
    %7D
-.execute(
 );%0A 

Use WriteCommandAction.runWriteCommandAction