public void testAutoImportWorksWhenITypeSpaceAfterClassName() throws Throwable {
    @NonNls String text = "class S { ArrayList<caret> }";
    configureByText(StdFileTypes.JAVA, text);

    boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
    CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);

    try {
      doHighlighting();
      // caret is too close
      assertEmpty(((PsiJavaFile) getFile()).getImportList().getAllImportStatements());

      type(" ");

      PsiJavaCodeReferenceElement element =
          (PsiJavaCodeReferenceElement)
              getFile().findReferenceAt(getEditor().getCaretModel().getOffset() - 2);
      ImportClassFix fix = new ImportClassFix(element);
      ImportClassFixBase.Result result = fix.doFix(getEditor(), false, false);
      assertEquals(ImportClassFixBase.Result.CLASS_AUTO_IMPORTED, result);

      assertNotSame(0, ((PsiJavaFile) getFile()).getImportList().getAllImportStatements().length);
    } finally {
      CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
    }
  }
  public void testAutoImportSkipsClassReferenceInMethodPosition() throws Throwable {
    @NonNls
    String text =
        "package x; import java.util.HashMap; class S { HashMap<String,String> f(){ return  Hash<caret>Map <String, String >();} }  ";
    configureByText(StdFileTypes.JAVA, text);

    boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
    CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);

    try {
      List<HighlightInfo> errs = highlightErrors();
      assertTrue(errs.size() > 1);

      PsiJavaFile javaFile = (PsiJavaFile) getFile();
      assertEquals(1, javaFile.getImportList().getAllImportStatements().length);

      PsiReference ref = javaFile.findReferenceAt(getEditor().getCaretModel().getOffset());
      ImportClassFix fix = new ImportClassFix((PsiJavaCodeReferenceElement) ref);
      assertFalse(fix.isAvailable(getProject(), getEditor(), getFile()));
    } finally {
      CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
    }
  }