diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertEqualsWithAssertLiteralIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertEqualsWithAssertLiteralIntention.java index cb27659e0cc2..e972b18665ae 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertEqualsWithAssertLiteralIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertEqualsWithAssertLiteralIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ package com.siyeh.ipp.junit; -import com.intellij.codeInsight.AnnotationUtil; import com.intellij.psi.*; +import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiTreeUtil; import com.siyeh.IntentionPowerPackBundle; import com.siyeh.ig.PsiReplacementUtil; @@ -86,11 +86,10 @@ public class ReplaceAssertEqualsWithAssertLiteralIntention extends MutablyNamedI final PsiElement qualifier = expression.getQualifier(); @NonNls final StringBuilder newExpression = new StringBuilder(); if (qualifier == null) { - final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(call, PsiMethod.class); - if (containingMethod != null && AnnotationUtil.isAnnotated(containingMethod, "org.junit.Test", true)) { - if (!ImportUtils.addStaticImport("org.junit.Assert", assertString, element)) { - newExpression.append("org.junit.Assert."); - } + final PsiClass containingClass = PsiTreeUtil.getParentOfType(element, PsiClass.class); + if (!InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert") && + !ImportUtils.addStaticImport("org.junit.Assert", assertString, element)) { + newExpression.append("org.junit.Assert."); } } else { diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/junit/replace_assert_equals_with_assert_literal/OutsideTestMethod.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/junit/replace_assert_equals_with_assert_literal/OutsideTestMethod.java new file mode 100644 index 000000000000..5af128b5478b --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/junit/replace_assert_equals_with_assert_literal/OutsideTestMethod.java @@ -0,0 +1,8 @@ +import static org.junit.Assert.assertEquals; + +class OutsideTestMethod { + + void m() { + assertEquals("asdf", null); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/junit/replace_assert_equals_with_assert_literal/OutsideTestMethod_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/junit/replace_assert_equals_with_assert_literal/OutsideTestMethod_after.java new file mode 100644 index 000000000000..e3291d9d271f --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/junit/replace_assert_equals_with_assert_literal/OutsideTestMethod_after.java @@ -0,0 +1,9 @@ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +class OutsideTestMethod { + + void m() { + assertNull("asdf"); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/junit/ReplaceAssertEqualsWithAssertLiteralIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/junit/ReplaceAssertEqualsWithAssertLiteralIntentionTest.java new file mode 100644 index 000000000000..529beaa1c348 --- /dev/null +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/junit/ReplaceAssertEqualsWithAssertLiteralIntentionTest.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ipp.junit; + +import com.siyeh.IntentionPowerPackBundle; +import com.siyeh.ipp.IPPTestCase; + +/** + * @see ReplaceAssertEqualsWithAssertLiteralIntention + * @author Bas Leijdekkers + */ +public class ReplaceAssertEqualsWithAssertLiteralIntentionTest extends IPPTestCase { + + public void testOutsideTestMethod() { doTest(); } + + @Override + protected void setUp() throws Exception { + super.setUp(); + myFixture.addClass("package org.junit;" + + "class Assert {" + + " static public void assertEquals(Object expected, Object actual) {}" + + "}"); + } + + @Override + protected String getRelativePath() { + return "junit/replace_assert_equals_with_assert_literal"; + } + + @Override + protected String getIntentionName() { + return IntentionPowerPackBundle.message("replace.assert.equals.with.assert.literal.intention.name", "assertNull"); + } +}