Esempio n. 1
0
  private void doTestFor(
      Map<String, PsiFile> pathToFile, final IntentionAction intentionAction, String fileText)
      throws Exception {
    String isApplicableString =
        InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ");
    boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");

    Assert.assertTrue(
        "isAvailable() for "
            + intentionAction.getClass()
            + " should return "
            + isApplicableExpected,
        isApplicableExpected == intentionAction.isAvailable(getProject(), getEditor(), getFile()));

    String intentionTextString =
        InTextDirectivesUtils.findStringWithPrefixes(fileText, "// INTENTION_TEXT: ");

    if (intentionTextString != null) {
      assertEquals("Intention text mismatch.", intentionTextString, intentionAction.getText());
    }

    String shouldFailString =
        InTextDirectivesUtils.findStringWithPrefixes(fileText, "// SHOULD_FAIL_WITH: ");

    try {
      if (isApplicableExpected) {
        ApplicationPackage.executeWriteCommand(
            getProject(),
            intentionAction.getText(),
            new Function0<Object>() {
              @Override
              public Object invoke() {
                intentionAction.invoke(getProject(), getEditor(), getFile());
                return null;
              }
            });
        // Don't bother checking if it should have failed.
        if (shouldFailString == null) {
          for (Map.Entry<String, PsiFile> entry : pathToFile.entrySet()) {
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            myFile = entry.getValue();
            String canonicalPathToExpectedFile =
                PathUtil.getCanonicalPath(entry.getKey() + ".after");

            checkResultByFile(canonicalPathToExpectedFile);
          }
        }
      }
      assertNull("Expected test to fail.", shouldFailString);
    } catch (IntentionTestException e) {
      assertEquals("Failure message mismatch.", shouldFailString, e.getMessage());
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
      assertEquals(
          "Failure message mismatch.", shouldFailString, StringUtil.join(e.getMessages(), ", "));
    }
  }
  @Nullable
  private IntentionAction doTestHighlightingAndGetQuickfix(
      @NotNull String message, @NotNull String filePath) throws IOException {
    doTestHighlighting(filePath);

    IntentionAction action = null;

    for (IntentionAction a : myFixture.getAvailableIntentions()) {
      if (message.equals(a.getText())) {
        action = a;
      }
    }
    return action;
  }
 public void testComments() {
   final String testName = getTestName(false);
   myFixture.configureByFile(getRelativePath() + "/" + testName + ".java");
   final String message =
       InspectionGadgetsBundle.message("constant.conditional.expression.simplify.quickfix");
   final List<IntentionAction> actions = myFixture.filterAvailableIntentions(message);
   assertFalse("No actions available", actions.isEmpty());
   for (IntentionAction action : actions) {
     if (action.getText().equals(message)) {
       myFixture.launchAction(action);
       myFixture.checkResultByFile(getRelativePath() + "/" + testName + ".after.java");
       break;
     }
   }
 }
 public SpellCheckerIntentionAction(IntentionAction intention) {
   super(intention.getText());
   this.intention = intention;
 }