Skip to content

Commit 17ebabf

Browse files
committed
migrate to junit 5
1 parent a6ae8ba commit 17ebabf

3 files changed

Lines changed: 75 additions & 62 deletions

File tree

src/test/kotlin-old/io/openapiprocessor/intellij/OpenApiPathLineMarkerSpec.kt

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/test/kotlin/io/openapiprocessor/intellij/MappingAnnotationLineMarkerSpec.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.testFramework.TestDataPath
1212
import com.intellij.testFramework.junit5.TestApplication
1313
import com.intellij.testFramework.junit5.fixture.*
1414
import com.intellij.testFramework.replaceService
15+
import com.intellij.testFramework.runInEdtAndGet
1516
import io.openapiprocessor.intellij.support.ModuleServiceStub
1617
import io.openapiprocessor.intellij.support.codeInsightFixture
1718
import io.openapiprocessor.intellij.support.psiTargets
@@ -50,10 +51,12 @@ class MappingAnnotationLineMarkerSpec {
5051
fun `adds navigation gutter icon to mapping annotation`() {
5152
val fixture = codeInsightFixture.get()
5253

53-
val file = VfsUtil.findRelativeFile(sourceRootFixture.get().virtualFile, "api", "Api.java")!!
54-
fixture.configureFromExistingVirtualFile(file)
54+
val gutters = runInEdtAndGet {
55+
val file = VfsUtil.findRelativeFile(sourceRootFixture.get().virtualFile, "api", "Api.java")!!
56+
fixture.configureFromExistingVirtualFile(file)
5557

56-
val gutters = fixture.findAllGutters("api/Api.java")
58+
return@runInEdtAndGet fixture.findAllGutters("api/Api.java")
59+
}
5760
assertEquals(2, gutters.size)
5861

5962
runReadAction {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2023 https://github.com/openapi-processor/openapi-processor-intellij
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.intellij
7+
8+
import com.intellij.openapi.application.runReadAction
9+
import com.intellij.openapi.vfs.VfsUtil
10+
import com.intellij.psi.PsiMethod
11+
import com.intellij.psi.impl.java.stubs.index.JavaMethodNameIndex
12+
import com.intellij.psi.search.GlobalSearchScope
13+
import com.intellij.testFramework.TestDataPath
14+
import com.intellij.testFramework.junit5.TestApplication
15+
import com.intellij.testFramework.junit5.fixture.*
16+
import com.intellij.testFramework.runInEdtAndGet
17+
import io.openapiprocessor.intellij.support.codeInsightFixture
18+
import io.openapiprocessor.intellij.support.methods
19+
import org.junit.jupiter.api.Assertions.assertEquals
20+
import org.junit.jupiter.api.Test
21+
import java.nio.file.Path
22+
23+
@TestApplication
24+
@TestDataPath($$"$PROJECT_ROOT/src/test/testdata/openapi-to-interface/paths")
25+
class OpenApiPathLineMarkerSpec {
26+
val tempPathFixture = tempPathFixture()
27+
val projectFixture = projectFixture(tempPathFixture, openAfterCreation = true)
28+
val moduleFixture = projectFixture.moduleFixture("main")
29+
30+
val sourceRootFixture = moduleFixture.sourceRootFixture(
31+
pathFixture = tempPathFixture,
32+
blueprintResourcePath = Path.of("src/test/testdata/openapi-to-interface/paths")
33+
)
34+
35+
val codeInsightFixture = codeInsightFixture(projectFixture, tempPathFixture)
36+
val disposableFixture = disposableFixture()
37+
38+
fun getMethod(name: String): PsiMethod {
39+
val project = projectFixture.get()
40+
41+
return JavaMethodNameIndex
42+
.getInstance()
43+
.getMethods(name, project, GlobalSearchScope.allScope(project))
44+
.first()
45+
}
46+
47+
@Test
48+
fun `adds navigation gutter icon to OpenAPI paths`() {
49+
val fixture = codeInsightFixture.get()
50+
51+
val gutters = runInEdtAndGet {
52+
val file = VfsUtil.findRelativeFile(sourceRootFixture.get().virtualFile, "openapi.yaml")!!
53+
fixture.configureFromExistingVirtualFile(file)
54+
55+
return@runInEdtAndGet fixture.findAllGutters("openapi.yaml")
56+
}
57+
58+
runReadAction {
59+
val expected = listOf(
60+
getMethod("postFoo"),
61+
getMethod("postBar")
62+
)
63+
64+
val methods = gutters.flatMap { it.methods }
65+
66+
assertEquals(expected, methods)
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)