private void doPrepareErrorTest(final String expectedMessage) throws Exception {
   String expectedError = null;
   try {
     doExitPointsTest(false);
   } catch (PrepareFailedException ex) {
     expectedError = ex.getMessage();
   }
   assertEquals(expectedMessage, expectedError);
 }
  private void invokeOnElements(
      @NotNull final Project project,
      @NotNull final Editor editor,
      @NotNull PsiFile file,
      @NotNull PsiElement[] elements) {
    if (elements.length == 0) {
      String message =
          RefactoringBundle.getCannotRefactorMessage(
              RefactoringBundle.message(
                  "selected.block.should.represent.a.set.of.statements.or.an.expression"));
      CommonRefactoringUtil.showErrorHint(
          project,
          editor,
          message,
          ExtractMethodObjectProcessor.REFACTORING_NAME,
          HelpID.EXTRACT_METHOD_OBJECT);
      return;
    }

    final ExtractMethodObjectProcessor processor =
        new ExtractMethodObjectProcessor(project, editor, elements, "");
    final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor =
        processor.getExtractProcessor();
    try {
      if (!extractProcessor.prepare()) return;
    } catch (PrepareFailedException e) {
      CommonRefactoringUtil.showErrorHint(
          project,
          editor,
          e.getMessage(),
          ExtractMethodObjectProcessor.REFACTORING_NAME,
          HelpID.EXTRACT_METHOD_OBJECT);
      ExtractMethodHandler.highlightPrepareError(e, file, editor, project);
      return;
    }

    if (!CommonRefactoringUtil.checkReadOnlyStatus(
        project, extractProcessor.getTargetClass().getContainingFile())) return;
    if (extractProcessor.showDialog()) {
      run(project, editor, processor, extractProcessor);
    }
  }