You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by jd...@apache.org on 2026/07/19 12:54:12 UTC
(grails-intellij-plugin) branch main updated: Use a real JDK for GrailsCodecTest (needs Swing/AWT) on 2026.2
This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/grails-intellij-plugin.git
The following commit(s) were added to refs/heads/main by this push:
new bef3709 Use a real JDK for GrailsCodecTest (needs Swing/AWT) on 2026.2
bef3709 is described below
commit bef370915b9065aece97e3621645309ddace3a67
Author: James Daugherty <jd...@jdresources.net>
AuthorDate: Sun Jul 19 08:49:34 2026 -0400
Use a real JDK for GrailsCodecTest (needs Swing/AWT) on 2026.2
Make the test JDK in GrailsTestCase overridable via getTestJdk() (default Mock
JDK 11). GrailsCodecTest's MmmCodec returns javax.swing.JButton/JPanel, so
getBackground()/getUI() resolution needs java.awt/javax.swing, which the minimal
Mock JDK 11 omits; override getTestJdk() there to use a real JDK.
---
.../org/jetbrains/plugins/groovy/grails/GrailsCodecTest.java | 12 ++++++++++++
.../org/jetbrains/plugins/groovy/grails/GrailsTestCase.java | 12 +++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/test/org/jetbrains/plugins/groovy/grails/GrailsCodecTest.java b/test/org/jetbrains/plugins/groovy/grails/GrailsCodecTest.java
index 6761dd1..f0ca4bf 100644
--- a/test/org/jetbrains/plugins/groovy/grails/GrailsCodecTest.java
+++ b/test/org/jetbrains/plugins/groovy/grails/GrailsCodecTest.java
@@ -16,12 +16,24 @@
package org.jetbrains.plugins.groovy.grails;
+import com.intellij.openapi.projectRoots.JavaSdk;
+import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.psi.PsiFile;
+import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.usageView.UsageInfo;
+import org.jetbrains.annotations.NotNull;
import java.util.Collection;
+import java.util.function.Supplier;
public class GrailsCodecTest extends GrailsTestCase {
+ // MmmCodec returns javax.swing types (JButton/JPanel), so this test needs a real JDK:
+ // the minimal Mock JDK 11 omits javax.swing/java.awt, leaving getBackground()/getUI() unresolved.
+ @Override
+ protected @NotNull Supplier<Sdk> getTestJdk() {
+ return () -> JavaSdk.getInstance().createJdk("TEST_JDK", IdeaTestUtil.requireRealJdkHome(), false);
+ }
+
public void testHighlighting() {
myFixture.addFileToProject("grails-app/utils/ccc/MmmCodec.groovy", """
diff --git a/testFramework/src/org/jetbrains/plugins/groovy/grails/GrailsTestCase.java b/testFramework/src/org/jetbrains/plugins/groovy/grails/GrailsTestCase.java
index f0047c8..c68410c 100644
--- a/testFramework/src/org/jetbrains/plugins/groovy/grails/GrailsTestCase.java
+++ b/testFramework/src/org/jetbrains/plugins/groovy/grails/GrailsTestCase.java
@@ -246,6 +246,14 @@ public abstract class GrailsTestCase extends LightJavaCodeInsightFixtureTestCase
return false;
}
+ /**
+ * The JDK for the test project. Defaults to Mock JDK 11 (see {@link #getProjectDescriptor()});
+ * override to supply a real JDK when a test needs classes the minimal mock omits (e.g. Swing/AWT).
+ */
+ protected @NotNull java.util.function.Supplier<com.intellij.openapi.projectRoots.Sdk> getTestJdk() {
+ return IdeaTestUtil::getMockJdk11;
+ }
+
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
@@ -253,7 +261,9 @@ public abstract class GrailsTestCase extends LightJavaCodeInsightFixtureTestCase
// by default) no longer exists: mock JDKs with feature <= 9 resolve to a filesystem path that is
// not shipped with the platform distribution, so java.lang.*/java.util.* become unresolvable.
// Mock JDK 11+ is resolved from the artifacts repository instead, so pin it explicitly.
- return new DefaultLightProjectDescriptor(IdeaTestUtil::getMockJdk11) {
+ // Tests that need JDK classes absent from the minimal mock (e.g. javax.swing/java.awt) can
+ // override getTestJdk() to use a real JDK.
+ return new DefaultLightProjectDescriptor(getTestJdk()) {
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
super.configureModule(module, model, contentEntry);