public void testRemoveOverridersInspiteOfUnsafeUsages() throws Exception {
   myDoCompare = false;
   try {
     BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(true);
     doTest("A");
   } finally {
     BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(false);
   }
 }
示例#2
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(), ", "));
    }
  }
 public void testConflictingMethodName() throws Exception {
   try {
     doTestInplaceRename("bar");
   } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
     assertEquals(
         "Method bar() is already defined in the class <b><code>Foo</code></b>.", e.getMessage());
     checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
     return;
   }
   fail("Conflict was not detected");
 }
 public void testRenameMethodCollisionWithOtherSignature() throws Exception {
   try {
     doTest("foo2");
   } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
     Assert.assertEquals(
         "Method call would be linked to \"method <b><code>RenameTest.foo2(Long)</code></b>\" after rename",
         e.getMessage());
     return;
   }
   fail("Conflicts were not found");
 }
 public void testRenameLocalVariableHidesFieldInAnonymous() throws Exception {
   try {
     doTest("y");
   } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
     Assert.assertEquals(
         "There is already a field <b><code>y</code></b>. It will conflict with the renamed variable",
         e.getMessage());
     return;
   }
   fail("Conflicts were not found");
 }
 public void testImplicitCtrCall2() throws Exception {
   try {
     doTest("Super");
     fail();
   } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
     String message = e.getMessage();
     assertTrue(
         message,
         message.startsWith(
             "constructor <b><code>Super.Super()</code></b> has 1 usage that is not safe to delete"));
   }
 }
 private void doTest(
     final String sourceClassName,
     final String targetClassName,
     final String visibility,
     final String[] memberNames)
     throws Exception {
   try {
     doTestImpl(sourceClassName, targetClassName, visibility, memberNames);
   } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
     fail("Conflicts: " + toString(e.getMessages(), "\n"));
   }
 }
 public void testLocalVariableSideEffect() throws Exception {
   myDoCompare = false;
   try {
     doTest("Super");
     fail("Side effect was ignored");
   } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
     String message = e.getMessage();
     assertTrue(
         message,
         message.startsWith(
             "local variable <b><code>varName</code></b> has 1 usage that is not safe to delete.\n"
                 + "Of those 0 usages are in strings, comments, or non-code files."));
   }
 }
 private void doTestConflicts(
     final String sourceClassName,
     final String targetClassName,
     final String visibility,
     final String[] memberNames,
     String[] expectedConflicts)
     throws Exception {
   try {
     doTestImpl(sourceClassName, targetClassName, visibility, memberNames);
     fail("conflicts expected");
   } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
     assertSameElements(e.getMessages(), expectedConflicts);
   }
 }