mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-177054 Wrong warning on AssertJUnit.assertNotNull() from testng
This commit is contained in:
+3
-2
@@ -196,7 +196,8 @@ public class HardcodedContracts {
|
||||
}
|
||||
|
||||
private static boolean isJunit(String className) {
|
||||
return className.startsWith("junit.framework.") || className.startsWith("org.junit.");
|
||||
return className.startsWith("junit.framework.") || className.startsWith("org.junit.")
|
||||
|| className.equals("org.testng.AssertJUnit");
|
||||
}
|
||||
|
||||
private static boolean isJunit5(String className) {
|
||||
@@ -204,7 +205,7 @@ public class HardcodedContracts {
|
||||
}
|
||||
|
||||
private static boolean isTestng(String className) {
|
||||
return className.startsWith("org.testng.");
|
||||
return className.startsWith("org.testng.") && !className.equals("org.testng.AssertJUnit");
|
||||
}
|
||||
|
||||
private static boolean isNotNullMatcher(PsiExpression expr) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.testng.Assert;
|
||||
import org.testng.AssertJUnit;
|
||||
|
||||
class AssertTestNg {
|
||||
public void assertTestNgStyle(@Nullable String msg, @Nullable String obj, boolean x, boolean y)
|
||||
{
|
||||
Assert.assertNotNull(obj, msg);
|
||||
if (msg == null) {
|
||||
System.out.println("msg is null");
|
||||
}
|
||||
if (<warning descr="Condition 'obj == null' is always 'false'">obj == null</warning>) {
|
||||
System.out.println("obj is null");
|
||||
}
|
||||
Assert.assertTrue(x);
|
||||
if (<warning descr="Condition 'x' is always 'true'">x</warning>) {
|
||||
System.out.println("x is true");
|
||||
}
|
||||
Assert.assertTrue(y, msg);
|
||||
if (<warning descr="Condition 'y' is always 'true'">y</warning>) {
|
||||
System.out.println("x is true");
|
||||
}
|
||||
}
|
||||
|
||||
public void assertJUnitStyle(@Nullable String msg, @Nullable String obj, boolean x, boolean y)
|
||||
{
|
||||
AssertJUnit.assertNotNull(msg, obj);
|
||||
if (msg == null) {
|
||||
System.out.println("msg is null");
|
||||
}
|
||||
if (<warning descr="Condition 'obj == null' is always 'false'">obj == null</warning>) {
|
||||
System.out.println("obj is null");
|
||||
}
|
||||
AssertJUnit.assertTrue(x);
|
||||
if (<warning descr="Condition 'x' is always 'true'">x</warning>) {
|
||||
System.out.println("x is true");
|
||||
}
|
||||
AssertJUnit.assertTrue(msg, y);
|
||||
if (<warning descr="Condition 'y' is always 'true'">y</warning>) {
|
||||
System.out.println("x is true");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,4 +128,24 @@ public class HardcodedContractsTest extends DataFlowInspectionTestCase {
|
||||
checkHighlighting();
|
||||
}
|
||||
|
||||
public void testAssertTestNg() {
|
||||
myFixture.addClass("package org.testng;\n" +
|
||||
"\n" +
|
||||
"public class AssertJUnit {\n" +
|
||||
" static public void assertTrue(String message, boolean condition) {}\n" +
|
||||
" static public void assertTrue(boolean condition) {}\n" +
|
||||
" static public void assertNotNull(String message, Object object) {}\n" +
|
||||
" static public void assertNotNull(Object object) {}\n" +
|
||||
"}");
|
||||
myFixture.addClass("package org.testng;\n" +
|
||||
"\n" +
|
||||
"public class Assert {\n" +
|
||||
" static public void assertTrue(boolean condition, String message) {}\n" +
|
||||
" static public void assertTrue(boolean condition) {}\n" +
|
||||
" static public void assertNotNull(Object object, String message) {}\n" +
|
||||
" static public void assertNotNull(Object object) {}\n" +
|
||||
"}");
|
||||
checkHighlighting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user