IDEA-246542 Smart completion for org.junit.Assert.assertNotEquals arguments should be the same as for assertEquals

GitOrigin-RevId: 44ace68f6b6c16919e2e8c568feb1c0b85fea366
This commit is contained in:
Peter Gromov
2020-07-27 09:28:26 +02:00
committed by intellij-monorepo-bot
parent 9fdc3606bc
commit 7f7072f2fa
3 changed files with 19 additions and 1 deletions

View File

@@ -1196,7 +1196,8 @@ public final class ExpectedTypesProvider {
@NonNls final String name = method.getName();
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(containingClass.getProject());
int argCount = Math.max(index + 1, args.length);
if ("assertEquals".equals(name) || "assertSame".equals(name) && method.getParameterList().getParametersCount() == argCount) {
if (("assertEquals".equals(name) || "assertNotEquals".equals(name) || "assertSame".equals(name) || "assertNotSame".equals(name)) &&
method.getParameterList().getParametersCount() == argCount) {
if (argCount == 2 ||
argCount == 3 && method.getParameterList().getParameters()[0].getType().equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
int other = index == argCount - 1 ? index - 1 : index + 1;

View File

@@ -0,0 +1,11 @@
import java.io.File;
public class Aaaaaaa extends org.junit.Assert {
{
File boo;
int bar;
assertNotEquals(new File("x"), b<caret>);
}
}

View File

@@ -342,6 +342,12 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "boo", "bar")
}
@NeedsIndex.Full
void testAssertNotEquals() throws Throwable {
myFixture.addClass("package org.junit; public class Assert { public static void assertNotEquals(Object a, Object b) {} }")
checkPreferredItems(0, "boo", "bar")
}
@NeedsIndex.Full
void testPreferCollectionsEmptyList() throws Throwable {
myFixture.addClass("package foo; public class FList<T> implements java.util.List<T> { public static <T> FList<T> emptyList() {} }")