mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Java. Tests] IDEA-381948 IDEA-381948 Remove wrapper into the object class for JavaCodeInsightFixture
GitOrigin-RevId: 7e82b01fd5997479da037c54dbaeec4902aca1c1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab4f22e07a
commit
71ae5608f6
@@ -1,30 +1,50 @@
|
||||
// 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.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.siyeh.ig.migration;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.ide.impl.OpenProjectTask;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture;
|
||||
import com.intellij.testFramework.junit5.RunInEdt;
|
||||
import com.intellij.testFramework.junit5.TestApplication;
|
||||
import com.intellij.testFramework.junit5.fixture.TestFixture;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ForCanBeForeachInspectionTest extends LightJavaInspectionTestCase {
|
||||
import java.nio.file.Path;
|
||||
|
||||
public void testForCanBeForEach() {
|
||||
doTest();
|
||||
import static com.intellij.testFramework.JavaCodeInsightFixtureKt.javaCodeInsightFixture;
|
||||
import static com.intellij.testFramework.JavaCodeInsightFixtureKt.setUpJdk;
|
||||
import static com.intellij.testFramework.junit5.fixture.FixturesKt.*;
|
||||
|
||||
@TestApplication
|
||||
@RunInEdt(allMethods = false)
|
||||
@TestDataPath("$PROJECT_ROOT/community/java/java-tests/testData/ig/com/siyeh/igtest/migration/foreach")
|
||||
public class ForCanBeForeachInspectionTest {
|
||||
private static final TestFixture<Disposable> disposable = disposableFixture();
|
||||
private static final TestFixture<Path> tempDir = tempPathFixture();
|
||||
private static final TestFixture<Project> project = projectFixture(tempDir, OpenProjectTask.build(), true);
|
||||
private static final TestFixture<Module> module = moduleFixture(project, tempDir, true);
|
||||
|
||||
private final TestFixture<String> testName = testNameFixture(false);
|
||||
private final TestFixture<JavaCodeInsightTestFixture> fixture = javaCodeInsightFixture(project, tempDir);
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
setUpJdk(LanguageLevel.JDK_1_8, project.get(), module.get(), disposable.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new ForCanBeForeachInspection();
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
fixture.get().enableInspections(new ForCanBeForeachInspection());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/java/java-tests/testData/ig/com/siyeh/igtest/migration/foreach";
|
||||
@Test
|
||||
void forCanBeForEach() {
|
||||
fixture.get().testHighlighting(testName.get() + ".java");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,13 +2,13 @@
|
||||
package com.siyeh.ig.migration
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.JavaJUnit5Util.javaCodeInsightFixture
|
||||
import com.intellij.testFramework.JavaJUnit5Util.setUpJdk
|
||||
import com.intellij.testFramework.TestDataPath
|
||||
import com.intellij.testFramework.javaCodeInsightFixture
|
||||
import com.intellij.testFramework.junit5.RunInEdt
|
||||
import com.intellij.testFramework.junit5.RunMethodInEdt
|
||||
import com.intellij.testFramework.junit5.TestApplication
|
||||
import com.intellij.testFramework.junit5.fixture.*
|
||||
import com.intellij.testFramework.setUpJdk
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.testFramework
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.WriteAction
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.platform.testFramework.junit5.codeInsight.fixture.codeInsightFixture
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
import com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl
|
||||
import com.intellij.testFramework.junit5.fixture.TestFixture
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.nio.file.Path
|
||||
|
||||
object JavaJUnit5Util {
|
||||
/**
|
||||
* Creates [JavaCodeInsightTestFixture] fixture that can be used when running JUnit5 tests.
|
||||
*/
|
||||
@JvmStatic
|
||||
@TestOnly
|
||||
fun javaCodeInsightFixture(
|
||||
projectFixture: TestFixture<Project>,
|
||||
tempDirFixture: TestFixture<Path>,
|
||||
): TestFixture<JavaCodeInsightTestFixture> = codeInsightFixture(projectFixture, tempDirFixture, ::JavaCodeInsightTestFixtureImpl)
|
||||
|
||||
|
||||
/**
|
||||
* Configures jdk for the project and the module inside JUnit5 test.
|
||||
* This method should be called inside method annotated with [org.junit.jupiter.api.BeforeAll].
|
||||
*
|
||||
* @param level version of the JDK to be set
|
||||
*/
|
||||
@JvmStatic
|
||||
@TestOnly
|
||||
@RequiresEdt
|
||||
fun setUpJdk(level: LanguageLevel, project: Project, module: Module, disposable: Disposable) {
|
||||
val jdk = IdeaTestUtil.getMockJdk(level)
|
||||
WriteAction.runAndWait<Exception> {
|
||||
ProjectJdkTable.getInstance().addJdk(jdk, disposable)
|
||||
ProjectRootManager.getInstance(project).setProjectSdk(jdk)
|
||||
ModuleRootModificationUtil.setModuleSdk(module, jdk)
|
||||
}
|
||||
IndexingTestUtil.waitUntilIndexesAreReady(project)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.testFramework
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.WriteAction
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.platform.testFramework.junit5.codeInsight.fixture.codeInsightFixture
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
import com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl
|
||||
import com.intellij.testFramework.junit5.fixture.TestFixture
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* Creates [JavaCodeInsightTestFixture] fixture that can be used when running JUnit5 tests.
|
||||
*/
|
||||
@TestOnly
|
||||
fun javaCodeInsightFixture(
|
||||
projectFixture: TestFixture<Project>,
|
||||
tempDirFixture: TestFixture<Path>,
|
||||
): TestFixture<JavaCodeInsightTestFixture> = codeInsightFixture(projectFixture, tempDirFixture, ::JavaCodeInsightTestFixtureImpl)
|
||||
|
||||
|
||||
/**
|
||||
* Configures jdk for the project and the module inside JUnit5 test.
|
||||
* This method should be called inside method annotated with [org.junit.jupiter.api.BeforeAll].
|
||||
*
|
||||
* @param level version of the JDK to be set
|
||||
*/
|
||||
@TestOnly
|
||||
@RequiresEdt
|
||||
fun setUpJdk(level: LanguageLevel, project: Project, module: Module, disposable: Disposable) {
|
||||
val jdk = IdeaTestUtil.getMockJdk(level)
|
||||
WriteAction.runAndWait<Exception> {
|
||||
ProjectJdkTable.getInstance().addJdk(jdk, disposable)
|
||||
ProjectRootManager.getInstance(project).setProjectSdk(jdk)
|
||||
ModuleRootModificationUtil.setModuleSdk(module, jdk)
|
||||
}
|
||||
IndexingTestUtil.waitUntilIndexesAreReady(project)
|
||||
}
|
||||
Reference in New Issue
Block a user