[java] IDEA-381003 Use MockJDK25 in tests

Remove explicitly mocked classes

GitOrigin-RevId: 7147da7d4f4b89630bb99e124b711387cffd3891
This commit is contained in:
Tagir Valeev
2025-10-22 09:25:20 +00:00
committed by intellij-monorepo-bot
parent 22285ff483
commit 917311bcab
8 changed files with 62 additions and 87 deletions
@@ -106,7 +106,6 @@ public class ExplicitToImplicitClassMigrationInspectionInspectionTest extends Li
}
private void doTest() {
MigrateToJavaLangIoInspectionTest.addIOClass(myFixture);
myFixture.enableInspections(new ExplicitToImplicitClassMigrationInspection());
myFixture.testHighlighting(true, false, true, "before" + getTestName(false) + ".java");
myFixture.checkPreviewAndLaunchAction(myFixture.findSingleIntention(
@@ -0,0 +1,29 @@
// 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.java.codeInspection;
import com.intellij.JavaTestUtil;
import com.intellij.codeInspection.MigrateFromJavaLangIoInspection;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
public class MigrateFromJavaLangIoInspection21Test extends LightJavaCodeInsightFixtureTestCase {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_21;
}
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath() + "/inspection/migrateFromJavaLangIo/";
}
public void testPrintUnresolved() {
myFixture.enableInspections(new MigrateFromJavaLangIoInspection());
myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java");
myFixture.checkPreviewAndLaunchAction(myFixture.findSingleIntention("Replace with 'System.out.print()'"));
myFixture.checkResultByFile("after" + getTestName(false) + ".java");
}
}
@@ -25,12 +25,9 @@ public class MigrateFromJavaLangIoInspectionTest extends LightJavaCodeInsightFix
}
public void testPrintlnResolved() {
MigrateToJavaLangIoInspectionTest.addIOClass(myFixture);
doTest("Replace with 'System.out.println()'");
}
public void testPrintUnresolved() { doTest("Replace with 'System.out.print()'"); }
public void testPrintArrayChar() {
doNotFind(getFixAllMessage());
}
@@ -46,7 +43,6 @@ public class MigrateFromJavaLangIoInspectionTest extends LightJavaCodeInsightFix
}
private void doNotFind(String message) {
MigrateToJavaLangIoInspectionTest.addIOClass(myFixture);
MigrateFromJavaLangIoInspection inspection = new MigrateFromJavaLangIoInspection();
myFixture.enableInspections(inspection);
myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java");
@@ -7,7 +7,6 @@ import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.MigrateToJavaLangIoInspection;
import com.intellij.java.JavaBundle;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture;
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
@@ -41,7 +40,6 @@ public class MigrateToJavaLangIoInspectionTest extends LightJavaCodeInsightFixtu
}
private void doNotFind(String message) {
addIOClass(myFixture);
MigrateToJavaLangIoInspection inspection = new MigrateToJavaLangIoInspection();
myFixture.enableInspections(inspection);
myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java");
@@ -50,21 +48,9 @@ public class MigrateToJavaLangIoInspectionTest extends LightJavaCodeInsightFixtu
}
private void doTest(String message) {
addIOClass(myFixture);
myFixture.enableInspections(new MigrateToJavaLangIoInspection());
myFixture.testHighlighting(true, true, true, "before" + getTestName(false) + ".java");
myFixture.checkPreviewAndLaunchAction(myFixture.findSingleIntention(message));
myFixture.checkResultByFile("after" + getTestName(false) + ".java");
}
public static void addIOClass(@NotNull JavaCodeInsightTestFixture fixture) {
fixture.addClass("""
package java.lang;
public final class IO {
public static void println(Object obj) {}
public static void println() {}
public static void print(Object obj) {}
}
""");
}
}
@@ -0,0 +1,27 @@
// 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 com.siyeh.ig.bugs;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.testFramework.LightProjectDescriptor;
import com.siyeh.ig.LightJavaInspectionTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ImplicitArrayToStringInspection25Test extends LightJavaInspectionTestCase {
public void testImplicitArrayToStringIO() {
doTest();
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_25;
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new ImplicitArrayToStringInspection();
}
}
@@ -2,9 +2,6 @@
package com.siyeh.ig.bugs;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.java.codeInspection.MigrateToJavaLangIoInspectionTest;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import com.siyeh.ig.LightJavaInspectionTestCase;
import org.jetbrains.annotations.NotNull;
@@ -16,13 +13,6 @@ public class ImplicitArrayToStringInspectionTest extends LightJavaInspectionTest
doTest();
}
public void testImplicitArrayToStringIO() {
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_25, () -> {
MigrateToJavaLangIoInspectionTest.addIOClass(myFixture);
doTest();
});
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
@@ -108,7 +108,8 @@ public final class IdeaTestUtil {
}
public static @NotNull Sdk getMockJdk(@NotNull JavaVersion version) {
int mockJdk = version.feature >= 21 ? 21 :
int mockJdk = version.feature >= 25 ? 25 :
version.feature >= 21 ? 21 :
version.feature >= 11 ? 11 :
version.feature >= 9 ? 9 :
version.feature >= 7 ? version.feature :
@@ -128,7 +129,7 @@ public final class IdeaTestUtil {
private static Sdk createMockJdkFromRepository(String name, int version) {
List<RemoteRepositoryDescription> repos = MavenDependencyUtil.getRemoteRepositoryDescriptions();
String coordinates = "org.jetbrains.mockjdk:" + MOCK_JDK_GROUP_ID + ":" + version + ".0";
String coordinates = "org.jetbrains.mockjdk:" + MOCK_JDK_GROUP_ID + ":" + version + ".0.0";
RepositoryLibraryProperties libraryProperties = new RepositoryLibraryProperties(coordinates, false);
Collection<OrderRoot> roots =
JarRepositoryManager.loadDependenciesModal(ProjectManager.getInstance().getDefaultProject(), libraryProperties, false, false, null,
@@ -260,7 +260,7 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() {
import java.time.Duration;
class Main {
{
static {
try {
Thread.sl<caret>eep(Duration.ofSeconds(5));
} catch (InterruptedException e) { }
@@ -325,14 +325,12 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() {
fun `test language level 24 with JDK 25`() {
myFixture.setLanguageLevel(LanguageLevel.JDK_24)
addPreviewFeature()
addStableValue()
myFixture.testHighlighting(JvmLanguage.JAVA, """
import java.util.concurrent.StructuredTaskScope;
import <error descr="java.util.concurrent.StructuredTaskScope is a preview API and is disabled by default">java.util.concurrent.StructuredTaskScope</error>;
class Main {
static void main() {
StructuredTaskScope a; // JEP 505
<error descr="java.util.concurrent.StructuredTaskScope is a preview API and is disabled by default">StructuredTaskScope</error> a; // JEP 505
<error descr="Usage of preview API documented as @since 25+"><error descr="java.lang.StableValue is a preview API and is disabled by default">StableValue<String></error></error> b = <error descr="Usage of preview API documented as @since 25+"><error descr="java.lang.StableValue is a preview API and is disabled by default">StableValue</error></error>.<caret>of("foo");
}
}
@@ -344,8 +342,6 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() {
fun `test language level 24 preview with JDK 25`() {
myFixture.setLanguageLevel(LanguageLevel.JDK_24_PREVIEW)
addPreviewFeature()
addStableValue()
myFixture.testHighlighting(JvmLanguage.JAVA, """
import java.util.concurrent.StructuredTaskScope;
@@ -360,53 +356,4 @@ class JavaJavaApiUsageInspectionTest : JavaApiUsageInspectionTestBase() {
myFixture.runQuickFix("Set language level to 25 (Preview) - Primitive Types in Patterns, etc.")
assertEquals(LanguageLevel.JDK_25_PREVIEW, LanguageLevelUtil.getEffectiveLanguageLevel(myFixture.module))
}
private fun addStableValue() {
myFixture.addClass("""
package java.lang;
import jdk.internal.javac.PreviewFeature;
/**
* @since 25
*/
@PreviewFeature(feature = PreviewFeature.Feature.STABLE_VALUES)
public class StableValue<T> {
private StableValue(T value) {}
public static <X> StableValue<X> of(X value) {
return new StableValue<>(value);
}
}
""".trimIndent())
}
private fun addPreviewFeature() {
// This code is copied from JDK sources
myFixture.addClass("""
package jdk.internal.javac;
import java.lang.annotation.*;
@Target({ElementType.METHOD,
ElementType.CONSTRUCTOR,
ElementType.FIELD,
ElementType.PACKAGE,
ElementType.TYPE})
// CLASS retention will hopefully be sufficient for the purposes at hand
@Retention(RetentionPolicy.RUNTIME)
// *Not* @Documented
public @interface PreviewFeature {
/**
* Name of the preview feature the annotated API is associated
* with.
*/
public Feature feature();
public enum Feature {
PEM_API,
STABLE_VALUES
}
}
""".trimIndent())
}
}