IDEA-125237 (Misordered 'assertEquals()' arguments: support non-primitives)

This commit is contained in:
Bas Leijdekkers
2014-05-19 22:00:01 +02:00
parent a4fcdde8bc
commit d4fd095f93
3 changed files with 22 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -185,7 +185,16 @@ public abstract class MisorderedAssertEqualsArgumentsInspectionBase extends Base
return;
}
if (ExpressionUtils.computeConstantExpression(actualArgument) == null) {
return;
if (actualArgument instanceof PsiReferenceExpression) {
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)actualArgument;
final PsiElement target = referenceExpression.resolve();
if (!(target instanceof PsiEnumConstant)) {
return;
}
}
else {
return;
}
}
registerMethodCallError(expression);
}
@@ -1,5 +1,7 @@
import org.junit.Assert;
import java.util.concurrent.TimeUnit;
class Simple {
public static final int EXPECTED = -9;
@@ -10,7 +12,14 @@ class Simple {
Assert.<warning descr="Arguments to 'assertEquals()' in wrong order">assertEquals</warning>(s, -1);
Assert.<warning descr="Arguments to 'assertSame()' in wrong order">assertSame</warning>(s, EXPECTED);
junit.framework.Assert.<warning descr="Arguments to 'failNotEquals()' in wrong order">failNotEquals</warning>("asdfasd", s, EXPECTED);
TimeUnit timeUnit = TimeUnit.HOURS;
Assert.<warning descr="Arguments to 'assertEquals()' in wrong order">assertEquals</warning>(timeUnit, TimeUnit.HOURS);
return null;
}
}
enum TimeUnit {
HOURS
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -31,6 +31,7 @@ public class MisorderedAssertEqualsParametersInspectionTest extends LightInspect
"package org.junit;" +
"public class Assert {" +
" static public void assertEquals(long expected, long actual) {}" +
" static public void assertEquals(Object expected, Object actual){}" +
" static public void assertSame(Object expected, Object actual) {}" +
"}",
"package junit.framework;" +