[Groovy] convert LiteralConstructorUsagesTest to Java (IDEA-327339)

GitOrigin-RevId: 48ba92ef8cd72086261be5f49b0c442799bdeaa3
This commit is contained in:
Bas Leijdekkers
2024-04-11 09:52:10 +00:00
committed by intellij-monorepo-bot
parent f8804e73c8
commit 4765439973
@@ -1,37 +1,38 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.groovy.lang
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.groovy.lang;
import com.intellij.psi.search.searches.MethodReferencesSearch
import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.plugins.groovy.LightGroovyTestCase
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
import org.jetbrains.plugins.groovy.LightGroovyTestCase;
class LiteralConstructorUsagesTest extends LightGroovyTestCase {
void testList_AsCast() throws Exception {
def foo = myFixture.addClass('class Foo { Foo() {} }')
myFixture.addFileToProject "a.groovy", "def x = [] as Foo"
assertOneElement(ReferencesSearch.search(foo.constructors[0]).findAll())
public class LiteralConstructorUsagesTest extends LightGroovyTestCase {
public void testList_AsCast() {
PsiClass foo = myFixture.addClass("class Foo { Foo() {} }");
myFixture.addFileToProject("a.groovy", "def x = [] as Foo");
assertOneElement(ReferencesSearch.search(foo.getConstructors()[0]).findAll());
}
void testMap_AsCast() throws Exception {
def foo = myFixture.addClass('class Foo { Foo() {} }')
myFixture.addFileToProject "a.groovy", "def x = [:] as Foo"
assertOneElement(ReferencesSearch.search(foo.constructors[0]).findAll())
public void testMap_AsCast() {
PsiClass foo = myFixture.addClass("class Foo { Foo() {} }");
myFixture.addFileToProject("a.groovy", "def x = [:] as Foo");
assertOneElement(ReferencesSearch.search(foo.getConstructors()[0]).findAll());
}
void testLiteralConstructorWithNamedArgs() {
myFixture.addFileToProject "a.groovy", """\
import groovy.transform.Immutable
public void testLiteralConstructorWithNamedArgs() {
myFixture.addFileToProject("a.groovy", """
import groovy.transform.Immutable
@Immutable class Money {
String currency
int amount
}
@Immutable class Money {
String currency
int amount
}
Money d = [amount: 100, currency:'USA']
"""
def constructors = myFixture.findClass("Money").constructors
assertEquals 0, MethodReferencesSearch.search(constructors[0]).size()
assertEquals 1, MethodReferencesSearch.search(constructors[1]).size()
Money d = [amount: 100, currency:'USA']
""");
PsiMethod[] constructors = myFixture.findClass("Money").getConstructors();
assertEmpty(MethodReferencesSearch.search(constructors[0]).findAll());
assertOneElement(MethodReferencesSearch.search(constructors[1]).findAll());
}
}