[groovy] tests: use GroovyLatestTest as base test class

GitOrigin-RevId: 5793e417b998010922b1c0ed0f25af6b63c8c9db
This commit is contained in:
Daniil Ovchinnikov
2019-11-07 02:40:58 +00:00
committed by intellij-monorepo-bot
parent a8fc2246e8
commit 924166e6f7
6 changed files with 76 additions and 149 deletions
@@ -2,35 +2,20 @@
package org.jetbrains.plugins.groovy.codeInsight.editorActions
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.EditorHintFixture
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.groovy.GroovyProjectDescriptors
import org.jetbrains.plugins.groovy.util.EdtRule
import org.jetbrains.plugins.groovy.util.FixtureRule
import org.jetbrains.plugins.groovy.util.GroovyLatestTest
import org.jetbrains.plugins.groovy.util.ResolveTest
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestName
import org.junit.rules.TestRule
import static com.intellij.util.ui.UIUtil.dispatchAllInvocationEvents
import static org.jetbrains.plugins.groovy.util.TestUtils.readInput
@CompileStatic
class GroovyParameterInfoHandlerTest implements ResolveTest {
class GroovyParameterInfoHandlerTest extends GroovyLatestTest implements ResolveTest {
public final FixtureRule myFixtureRule = new FixtureRule(GroovyProjectDescriptors.GROOVY_3_0, 'parameterInfo/')
public final TestName myNameRule = new TestName()
@Rule
public final TestRule myRules = RuleChain.outerRule(myNameRule).around(myFixtureRule).around(new EdtRule())
@NotNull
@Override
CodeInsightTestFixture getFixture() {
myFixtureRule.fixture
GroovyParameterInfoHandlerTest() {
super("parameterInfo/")
}
@Test
@@ -64,12 +49,11 @@ class GroovyParameterInfoHandlerTest implements ResolveTest {
}
private void testParameterHint() {
def name = myNameRule.methodName.split(" ")*.capitalize().join('').uncapitalize()
def testName = name + ".test"
def input = readInput("$fixture.testDataPath$testName")[0]
def name = testName.split(" ")*.capitalize().join('').uncapitalize() + ".test"
def input = readInput("$fixture.testDataPath$name")[0]
def hint = getParameterHint(input)
configureByText "$input\n-----\n$hint"
fixture.checkResultByFile(testName)
fixture.checkResultByFile(name)
}
private String getParameterHint(String text) {
@@ -0,0 +1,60 @@
// Copyright 2000-2019 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.dynamic
import com.intellij.psi.PsiType
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.groovy.annotator.intentions.QuickfixUtil
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DRootElement
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyNamesUtil
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil
import org.jetbrains.plugins.groovy.util.BaseTest
import org.jetbrains.plugins.groovy.util.GroovyLatestTest
import org.junit.Test
import static org.junit.Assert.assertNotNull
@CompileStatic
class DynamicTest extends GroovyLatestTest implements BaseTest {
DynamicTest() {
super("dynamic")
}
@Test
void method() {
fixture.enableInspections(new GrUnresolvedAccessInspection())
fixture.configureByFile(testName.capitalize() + ".groovy")
fixture.launchAction(fixture.findSingleIntention("Add Dynamic Method"))
GrReferenceExpression referenceExpression = elementUnderCaret(GrReferenceExpression.class)
final PsiType[] psiTypes = PsiUtil.getArgumentTypes(referenceExpression, false)
final String[] methodArgumentsNames = GroovyNamesUtil.getMethodArgumentsNames(getProject(), psiTypes)
final List<ParamInfo> pairs = QuickfixUtil.swapArgumentsAndTypes(methodArgumentsNames, psiTypes)
assertNotNull(getDClassElement().getMethod(referenceExpression.getReferenceName(), QuickfixUtil.getArgumentsTypes(pairs)))
}
@Test
void property() {
fixture.enableInspections(new GrUnresolvedAccessInspection())
fixture.configureByFile(testName.capitalize() + ".groovy")
fixture.launchAction(fixture.findSingleIntention("Add dynamic property"))
GrReferenceExpression referenceExpression = elementUnderCaret(GrReferenceExpression.class)
assertNotNull(getDClassElement().getPropertyByName(referenceExpression.getReferenceName()))
}
@NotNull
private DClassElement getDClassElement() {
final DRootElement rootElement = DynamicManager.getInstance(getProject()).getRootElement()
final DClassElement classElement = rootElement.getClassElement(testName.capitalize())
assertNotNull(classElement)
return classElement
}
}
@@ -1,71 +0,0 @@
// Copyright 2000-2019 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.dynamic;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiType;
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.annotator.intentions.QuickfixUtil;
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager;
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.ParamInfo;
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement;
import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DRootElement;
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyNamesUtil;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import org.jetbrains.plugins.groovy.util.BaseTest;
import org.jetbrains.plugins.groovy.util.TestUtils;
import java.util.List;
public class DynamicTest extends JavaCodeInsightFixtureTestCase implements BaseTest {
@NotNull
@Override
public CodeInsightTestFixture getFixture() {
return myFixture;
}
@NotNull
@Override
public Project getProject() {
return super.getProject();
}
@Override
protected String getBasePath() {
return TestUtils.getTestDataPath() + "dynamic/";
}
public void testMethod() {
myFixture.enableInspections(new GrUnresolvedAccessInspection());
myFixture.configureByFile(getTestName(false) + ".groovy");
myFixture.launchAction(myFixture.findSingleIntention("Add Dynamic Method"));
GrReferenceExpression referenceExpression = elementUnderCaret(GrReferenceExpression.class);
final PsiType[] psiTypes = PsiUtil.getArgumentTypes(referenceExpression, false);
final String[] methodArgumentsNames = GroovyNamesUtil.getMethodArgumentsNames(getProject(), psiTypes);
final List<ParamInfo> pairs = QuickfixUtil.swapArgumentsAndTypes(methodArgumentsNames, psiTypes);
assertNotNull(getDClassElement().getMethod(referenceExpression.getReferenceName(), QuickfixUtil.getArgumentsTypes(pairs)));
}
public void testProperty() {
myFixture.enableInspections(new GrUnresolvedAccessInspection());
myFixture.configureByFile(getTestName(false) + ".groovy");
myFixture.launchAction(myFixture.findSingleIntention("Add dynamic property"));
GrReferenceExpression referenceExpression = elementUnderCaret(GrReferenceExpression.class);
assertNotNull(getDClassElement().getPropertyByName(referenceExpression.getReferenceName()));
}
@NotNull
private DClassElement getDClassElement() {
final DRootElement rootElement = DynamicManager.getInstance(getProject()).getRootElement();
final DClassElement classElement = rootElement.getClassElement(getTestName(false));
assertNotNull(classElement);
return classElement;
}
}
@@ -1,28 +1,14 @@
// 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.
// Copyright 2000-2019 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.resolve
import com.intellij.openapi.util.RecursionManager
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.groovy.GroovyProjectDescriptors
import org.jetbrains.plugins.groovy.util.EdtRule
import org.jetbrains.plugins.groovy.util.FixtureRule
import org.jetbrains.plugins.groovy.util.GroovyLatestTest
import org.jetbrains.plugins.groovy.util.ResolveTest
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
@CompileStatic
class ResolveAssertionsTest implements ResolveTest {
public final FixtureRule myFixtureRule = new FixtureRule(GroovyProjectDescriptors.GROOVY_2_3, '')
public final @Rule TestRule myRules = RuleChain.outerRule(myFixtureRule).around(new EdtRule())
@NotNull
@Override
CodeInsightTestFixture getFixture() { myFixtureRule.fixture }
class ResolveAssertionsTest extends GroovyLatestTest implements ResolveTest {
@Test
void 'test substitutor is not computed within resolve'() {
@@ -1,29 +1,15 @@
// 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.
// Copyright 2000-2019 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.resolve
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.groovy.GroovyProjectDescriptors
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter
import org.jetbrains.plugins.groovy.util.EdtRule
import org.jetbrains.plugins.groovy.util.FixtureRule
import org.jetbrains.plugins.groovy.util.Groovy30Test
import org.jetbrains.plugins.groovy.util.ResolveTest
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
@CompileStatic
class ResolveLocalTest implements ResolveTest {
public final FixtureRule myFixtureRule = new FixtureRule(GroovyProjectDescriptors.GROOVY_3_0, '')
public final @Rule TestRule myRules = RuleChain.outerRule(myFixtureRule).around(new EdtRule())
@NotNull
@Override
CodeInsightTestFixture getFixture() { myFixtureRule.fixture }
class ResolveLocalTest extends Groovy30Test implements ResolveTest {
@Test
void 'resource variable from try block'() {
@@ -131,5 +117,4 @@ class ResolveLocalTest implements ResolveTest {
void 'local variable inside lambda'() {
resolveTest 'def l = a -> {def param; <caret>param }', GrVariable
}
}
@@ -1,35 +1,18 @@
// 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.
// Copyright 2000-2019 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.resolve
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.groovy.GroovyProjectDescriptors
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
import org.jetbrains.plugins.groovy.util.BaseTest
import org.jetbrains.plugins.groovy.util.EdtRule
import org.jetbrains.plugins.groovy.util.FixtureRule
import org.junit.Rule
import org.jetbrains.plugins.groovy.util.GroovyLatestTest
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestName
import org.junit.rules.TestRule
import static com.intellij.psi.CommonClassNames.JAVA_UTIL_ARRAY_LIST
import static org.jetbrains.plugins.groovy.LightGroovyTestCase.assertType
@CompileStatic
class SpreadOperatorTest implements BaseTest {
public final FixtureRule myFixtureRule = new FixtureRule(GroovyProjectDescriptors.GROOVY_3_0, '')
public final TestName myNameRule = new TestName()
public final @Rule TestRule myRules = RuleChain.outerRule(myNameRule).around(myFixtureRule).around(new EdtRule())
@NotNull
CodeInsightTestFixture getFixture() {
myFixtureRule.fixture
}
class SpreadOperatorTest extends GroovyLatestTest implements BaseTest {
@Test
void 'spread property'() {