Skip to content

Commit f3099eb

Browse files
committed
chore: fix tests
Signed-off-by: Stephane Bouchet <[email protected]>
1 parent 321e86c commit f3099eb

File tree

10 files changed

+29
-16
lines changed

10 files changed

+29
-16
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ dependencies {
168168
// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+., and Java 21 for 2025.3+.
169169
kotlin {
170170
jvmToolchain {
171-
languageVersion = JavaLanguageVersion.of(21)
171+
languageVersion = JavaLanguageVersion.of(17)
172172
vendor = JvmVendorSpec.JETBRAINS
173173
}
174174
}

projects/lsp4mp/projects/maven/using-vertx/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
2121
<quarkus.platform.version>1.1.1.Final</quarkus.platform.version>
2222
<surefire-plugin.version>2.22.1</surefire-plugin.version>
23-
<quarkus.version>1.2.1.Final</quarkus.version>
24-
<docker-plugin.version>0.33.0</docker-plugin.version>
2523
</properties>
2624

2725
<dependencyManagement>

src/test/java/com/redhat/devtools/intellij/MavenModuleImportingTestCase.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package com.redhat.devtools.intellij;
1212

1313
import com.intellij.maven.testFramework.MavenImportingTestCase;
14+
import com.intellij.openapi.application.ApplicationManager;
1415
import com.intellij.openapi.module.Module;
1516
import com.intellij.openapi.module.ModuleManager;
1617
import com.intellij.openapi.project.Project;
@@ -23,6 +24,10 @@
2324
import com.intellij.testFramework.fixtures.*;
2425
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils;
2526
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl;
27+
import kotlin.coroutines.EmptyCoroutineContext;
28+
import kotlinx.coroutines.BuildersKt;
29+
import kotlinx.coroutines.CoroutineScopeKt;
30+
import kotlinx.coroutines.future.FutureKt;
2631
import org.apache.commons.io.FileUtils;
2732

2833
import java.io.File;
@@ -40,8 +45,8 @@ protected void setUpFixtures() throws Exception {
4045
final JavaTestFixtureFactory factory = JavaTestFixtureFactory.getFixtureFactory();
4146
myProjectBuilder.addModule(JavaModuleFixtureBuilder.class);
4247
IdeaProjectTestFixture myFixture = factory.createCodeInsightFixture(myProjectBuilder.getFixture());
43-
myFixture.setUp();
4448
setTestFixture(myFixture);
49+
myFixture.setUp();
4550
LanguageLevelProjectExtension.getInstance(myFixture.getProject()).setLanguageLevel(LanguageLevel.JDK_17);
4651
}
4752

@@ -59,9 +64,10 @@ protected List<Module> createMavenModules(List<File> projectDirs) throws Excepti
5964
for(File projectDir : projectDirs) {
6065
File moduleDir = new File(project.getBasePath(), projectDir.getName() + counter++);
6166
FileUtils.copyDirectory(projectDir, moduleDir);
62-
VirtualFile pomFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleDir).findFileByRelativePath("pom.xml");
67+
VirtualFile pomFile = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(moduleDir.toPath()).findFileByRelativePath("pom.xml");
6368
pomFiles.add(pomFile);
6469
}
70+
6571
// Calling the non-suspending importProjects method instead of the Kotlin suspending function
6672
// importProjectsAsync(file: VirtualFile) to prevent blocking unit tests starting from IntelliJ version 2024.2.
6773
importProjects(pomFiles.toArray(VirtualFile[]::new));
@@ -70,14 +76,19 @@ protected List<Module> createMavenModules(List<File> projectDirs) throws Excepti
7076
for(Module module : modules) {
7177
setupJdkForModule(module.getName());
7278
}
73-
// Starting from IntelliJ 2024.2, indexing runs asynchronously in a background thread, https://plugins.jetbrains.com/docs/intellij/testing-faq.html#how-to-handle-indexing.
74-
// Use the following method to ensure indexes are fully populated before proceeding.
75-
IndexingTestUtil.waitUntilIndexesAreReady(project);
76-
return Arrays.stream(modules).skip(1).toList();
79+
80+
// REVISIT: After calling setupJdkForModule() initialization appears to continue in the background
81+
// and a may cause a test to intermittently fail if it accesses the module too early. A 5-second wait
82+
// is hopefully long enough but would be preferable to synchronize on a completion event if one is
83+
// ever introduced in the future.
84+
// Thread.sleep(5000L);
85+
86+
return Arrays.stream(modules).toList();
7787
}
7888

7989
protected Module createMavenModule(File projectDir) throws Exception {
80-
return createMavenModules(Collections.singletonList(projectDir)).getLast();
90+
List<Module> modules = createMavenModules(Collections.singletonList(projectDir));
91+
return modules.get(modules.size() - 1);
8192
}
8293

8394
/**
@@ -104,6 +115,6 @@ protected Module createMavenModule(String name, String xml) throws Exception {
104115
}
105116

106117
protected IPsiUtils getJDTUtils() {
107-
return PsiUtilsLSImpl.getInstance(getTestFixture().getProject());
118+
return PsiUtilsLSImpl.getInstance(getProject());
108119
}
109120
}

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/LSP4MPMavenModuleImportingTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import com.intellij.openapi.module.Module;
1616
import com.intellij.openapi.progress.EmptyProgressIndicator;
17+
import com.intellij.testFramework.IndexingTestUtil;
1718
import com.redhat.devtools.intellij.MavenModuleImportingTestCase;
1819
import com.redhat.devtools.intellij.quarkus.QuarkusDeploymentSupport;
1920

@@ -33,6 +34,7 @@ protected Module loadMavenProject(String projectName, boolean collectAndAddQuark
3334
if(collectAndAddQuarkusDeploymentDependencies) {
3435
QuarkusDeploymentSupport.getInstance(getTestFixture().getProject()).updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
3536
}
37+
IndexingTestUtil.waitUntilIndexesAreReady(getProject());
3638
return module;
3739
}
3840
}

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerClassPathKindTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testconfigQuickstartTest() throws Exception {
7676
// GreetingResource
7777
// @ConfigProperty(name = "greeting.message")
7878
// String message;
79-
p(null, "greeting.message", "java.lang.String", null, false, "org.acme.config.GreetingResource",
79+
p(null, "greeting.message", "String", null, false, "org.acme.config.GreetingResource",
8080
"message", null, 0, null),
8181

8282
// @ConfigProperty(name = "greeting.suffix" , defaultValue="!")

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/PropertiesManagerLocationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
package com.redhat.devtools.intellij.lsp4mp4ij.psi.core;
1111

1212
import com.intellij.openapi.module.Module;
13-
import com.redhat.devtools.intellij.MavenModuleImportingTestCase;
13+
import com.intellij.testFramework.IndexingTestUtil;
1414
import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl;
1515
import org.eclipse.lsp4j.Location;
1616
import org.junit.Assert;

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/properties/ConfigItemIntBoolDefaultValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testConfigItemIntBoolDefaultValueTest() throws Exception {
5252
// @ConfigProperty(name = "greeting.constructor.message") String message,
5353
// @ConfigProperty(name = "greeting.constructor.suffix" , defaultValue="!") String suffix,
5454
// @ConfigProperty(name = "greeting.constructor.name") Optional<String> name)
55-
p(null, "greeting.constructor.message", "java.lang.String", null, false, "org.acme.config.GreetingConstructorResource",
55+
p(null, "greeting.constructor.message", "String", null, false, "org.acme.config.GreetingConstructorResource",
5656
null, "GreetingConstructorResource(Ljava/lang/String;Ljava/lang/String;Ljava/util/Optional;)V", 0, null),
5757

5858
p(null, "greeting.constructor.suffix", "java.lang.String", null, false, "org.acme.config.GreetingConstructorResource",

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/config/properties/MicroProfileConfigPropertyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void testConfigQuickstartFromClasspath() throws Exception {
4242
File f = MavenArtifactUtil.getArtifactFile(myProjectsManager.findProject(module).getLocalRepository(), new MavenId("io.quarkus:quarkus-core-deployment:1.1.0.Final"), "jar").toFile();
4343
assertNotNull("Test existing of quarkus-core-deployment*.jar", f);
4444

45-
assertProperties(infoFromClasspath, 244 /* properties from JAR */ + //
45+
assertProperties(infoFromClasspath, 257 /* properties from JAR */ + //
4646
31 /* properties from Java sources with ConfigProperty */ + //
4747
2 /* properties from Java sources with ConfigRoot */ + //
4848
7 /* static properties from microprofile-context-propagation-api */ +

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/configproperties/properties/MicroProfileConfigPropertiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void testConfigPropertiesFromJavaSources() throws Exception {
4343

4444
assertProperties(infoFromJavaSources, 17 /* properties from Java sources with ConfigProperties */,
4545

46-
p(null, "server.host", "java.lang.String", null, false, "org.acme.Details", "host", null, 0, null),
46+
p(null, "server.host", "String", null, false, "org.acme.Details", "host", null, 0, null),
4747
p(null, "server.port", "int", null, false, "org.acme.Details", "port", null, 0, null),
4848
p(null, "server.endpoint", "java.lang.String", null, false, "org.acme.Details", "endpoint", null, 0,
4949
null),

src/test/java/com/redhat/microprofile/psi/quarkus/QuarkusMavenModuleImportingTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import com.intellij.openapi.module.Module;
1515
import com.intellij.openapi.progress.EmptyProgressIndicator;
16+
import com.intellij.testFramework.IndexingTestUtil;
1617
import com.redhat.devtools.intellij.MavenModuleImportingTestCase;
1718
import com.redhat.devtools.intellij.quarkus.QuarkusDeploymentSupport;
1819

@@ -33,6 +34,7 @@ protected Module loadMavenProject(String projectName, boolean collectAndAddQuark
3334
if(collectAndAddQuarkusDeploymentDependencies) {
3435
QuarkusDeploymentSupport.getInstance(getTestFixture().getProject()).updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
3536
}
37+
IndexingTestUtil.waitUntilIndexesAreReady(getProject());
3638
return module;
3739
}
3840
}

0 commit comments

Comments
 (0)