Skip to content

Commit 5ab65fe

Browse files
committed
Migrate ImageVector PSI to JUnit 5
1 parent 6ab9d13 commit 5ab65fe

File tree

4 files changed

+40
-55
lines changed

4 files changed

+40
-55
lines changed

sdk/intellij/psi/imagevector/build.gradle.kts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.valkyrie.compose)
77
alias(libs.plugins.jetbrains.intellij.module)
88
alias(libs.plugins.valkyrie.kover)
9+
alias(libs.plugins.buildconfig)
910
}
1011

1112
sourceSets {
@@ -14,6 +15,20 @@ sourceSets {
1415
}
1516
}
1617

18+
buildConfig.sourceSets.getByName("test") {
19+
useKotlinOutput {
20+
topLevelConstants = true
21+
}
22+
packageName = "io.github.composegears.valkyrie.psi"
23+
24+
val path = project.layout.buildDirectory.dir("resources/test").get().asFile.absolutePath
25+
buildConfigField<String>("TEST_DATA_PATH", path)
26+
}
27+
28+
tasks.test {
29+
systemProperty("idea.kotlin.plugin.use.k2", "true")
30+
}
31+
1732
configurations {
1833
testImplementation {
1934
exclude(group = "org.jetbrains.kotlinx")
@@ -26,15 +41,13 @@ dependencies {
2641

2742
compileOnly(compose.runtime)
2843

44+
testImplementation(testFixtures(projects.sdk.intellij.testFixtures))
2945
testImplementation(compose.ui)
3046
testImplementation(projects.sdk.ir.compose)
3147
testImplementation(projects.components.test.resourceLoader)
32-
testImplementation(libs.bundles.test)
48+
testImplementation(libs.assertk)
3349
testRuntimeOnly(libs.junit.launcher)
3450

35-
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#junit5-test-framework-refers-to-junit4
36-
testRuntimeOnly(libs.junit4)
37-
3851
intellijPlatform {
3952
testFramework(TestFrameworkType.Platform)
4053
testFramework(TestFrameworkType.JUnit5)

sdk/intellij/psi/imagevector/src/test/kotlin/io/github/composegears/valkyrie/sdk/intellij/psi/imagevector/KtFileToImageVectorParserTest.kt

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package io.github.composegears.valkyrie.sdk.intellij.psi.imagevector
22

33
import assertk.assertThat
44
import assertk.assertions.isEqualTo
5-
import com.intellij.openapi.project.Project
6-
import com.intellij.testFramework.ProjectExtension
5+
import com.intellij.testFramework.junit5.TestApplication
76
import com.intellij.testFramework.runInEdtAndGet
7+
import io.github.composegears.valkyrie.psi.TEST_DATA_PATH
88
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.common.ParseType
9-
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.common.createKtFile
10-
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.common.toKtFile
119
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedAllGroupParams
1210
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedAllPathParams
1311
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedClipPathGradient
@@ -24,31 +22,21 @@ import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.Exp
2422
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedMaterialIconWithoutParam2
2523
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedRadialGradient
2624
import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedSinglePath
25+
import io.github.composegears.valkyrie.sdk.intellij.testfixtures.KotlinCodeInsightTest
2726
import io.github.composegears.valkyrie.sdk.ir.compose.toComposeImageVector
27+
import org.jetbrains.kotlin.psi.KtFile
2828
import org.junit.jupiter.api.Test
29-
import org.junit.jupiter.api.extension.RegisterExtension
3029
import org.junit.jupiter.params.ParameterizedClass
3130
import org.junit.jupiter.params.provider.EnumSource
3231

32+
@TestApplication
3333
@ParameterizedClass
3434
@EnumSource(value = ParseType::class)
35-
class KtFileToImageVectorParserTest(
36-
private val parseType: ParseType,
37-
) {
38-
39-
companion object {
40-
@JvmField
41-
@RegisterExtension
42-
val projectExtension = ProjectExtension()
43-
}
44-
45-
private val project: Project
46-
get() = projectExtension.project
35+
class KtFileToImageVectorParserTest(private val parseType: ParseType) : KotlinCodeInsightTest() {
4736

4837
@Test
4938
fun `empty image vector`() = runInEdtAndGet {
5039
val ktFile = parseType.toKtFile(
51-
project = project,
5240
pathToLazy = "lazy/EmptyImageVector.kt",
5341
pathToBacking = "backing/EmptyImageVector.kt",
5442
)
@@ -60,7 +48,6 @@ class KtFileToImageVectorParserTest(
6048
@Test
6149
fun `empty paths`() = runInEdtAndGet {
6250
val ktFile = parseType.toKtFile(
63-
project = project,
6451
pathToLazy = "lazy/EmptyPaths.kt",
6552
pathToBacking = "backing/EmptyPaths.kt",
6653
)
@@ -72,7 +59,6 @@ class KtFileToImageVectorParserTest(
7259
@Test
7360
fun `parse all path params`() = runInEdtAndGet {
7461
val ktFile = parseType.toKtFile(
75-
project = project,
7662
pathToLazy = "lazy/AllPathParams.kt",
7763
pathToBacking = "backing/AllPathParams.kt",
7864
)
@@ -83,39 +69,39 @@ class KtFileToImageVectorParserTest(
8369

8470
@Test
8571
fun `parse material icon`() = runInEdtAndGet {
86-
val ktFile = project.createKtFile(from = "backing/MaterialIcon.all.kt")
72+
val ktFile = loadKtFile("backing/MaterialIcon.all.kt")
8773
val imageVector = ImageVectorPsiParser.parseToIrImageVector(ktFile)?.toComposeImageVector()
8874

8975
assertThat(imageVector).isEqualTo(ExpectedMaterialIcon)
9076
}
9177

9278
@Test
9379
fun `parse material icon without param`() = runInEdtAndGet {
94-
val ktFile = project.createKtFile(from = "backing/MaterialIcon.all.without.param.kt")
80+
val ktFile = loadKtFile("backing/MaterialIcon.all.without.param.kt")
9581
val imageVector = ImageVectorPsiParser.parseToIrImageVector(ktFile)?.toComposeImageVector()
9682

9783
assertThat(imageVector).isEqualTo(ExpectedMaterialIconWithoutParam)
9884
}
9985

10086
@Test
10187
fun `parse material icon with several materialPath`() = runInEdtAndGet {
102-
val ktFile = project.createKtFile(from = "backing/MaterialIcon.several.materialpath.kt")
88+
val ktFile = loadKtFile("backing/MaterialIcon.several.materialpath.kt")
10389
val imageVector = ImageVectorPsiParser.parseToIrImageVector(ktFile)?.toComposeImageVector()
10490

10591
assertThat(imageVector).isEqualTo(ExpectedMaterialIconWithoutParam2)
10692
}
10793

10894
@Test
10995
fun `parse material icon only with materialPath`() = runInEdtAndGet {
110-
val ktFile = project.createKtFile(from = "backing/MaterialIcon.material.path.kt")
96+
val ktFile = loadKtFile("backing/MaterialIcon.material.path.kt")
11197
val imageVector = ImageVectorPsiParser.parseToIrImageVector(ktFile)?.toComposeImageVector()
11298

11399
assertThat(imageVector).isEqualTo(ExpectedMaterialIconOnlyWithPath)
114100
}
115101

116102
@Test
117103
fun `parse icon with import member`() = runInEdtAndGet {
118-
val ktFile = project.createKtFile(from = "backing/IconWithImportMember.kt")
104+
val ktFile = loadKtFile("backing/IconWithImportMember.kt")
119105
val imageVector = ImageVectorPsiParser.parseToIrImageVector(ktFile)?.toComposeImageVector()
120106

121107
assertThat(imageVector).isEqualTo(ExpectedIconWithImportMember)
@@ -124,7 +110,6 @@ class KtFileToImageVectorParserTest(
124110
@Test
125111
fun `parse icon with group`() = runInEdtAndGet {
126112
val ktFile = parseType.toKtFile(
127-
project = project,
128113
pathToLazy = "lazy/IconWithGroup.kt",
129114
pathToBacking = "backing/IconWithGroup.kt",
130115
)
@@ -136,7 +121,6 @@ class KtFileToImageVectorParserTest(
136121
@Test
137122
fun `parse single path property`() = runInEdtAndGet {
138123
val ktFile = parseType.toKtFile(
139-
project = project,
140124
pathToLazy = "lazy/SinglePath.kt",
141125
pathToBacking = "backing/SinglePath.kt",
142126
)
@@ -148,7 +132,6 @@ class KtFileToImageVectorParserTest(
148132
@Test
149133
fun `parse all group params`() = runInEdtAndGet {
150134
val ktFile = parseType.toKtFile(
151-
project = project,
152135
pathToLazy = "imagevector/kt/lazy/AllGroupParams.kt",
153136
pathToBacking = "imagevector/kt/backing/AllGroupParams.kt",
154137
)
@@ -160,7 +143,6 @@ class KtFileToImageVectorParserTest(
160143
@Test
161144
fun `parse compose color`() = runInEdtAndGet {
162145
val ktFile = parseType.toKtFile(
163-
project = project,
164146
pathToLazy = "imagevector/kt/lazy/ComposeColor.kt",
165147
pathToBacking = "imagevector/kt/backing/ComposeColor.kt",
166148
)
@@ -172,7 +154,6 @@ class KtFileToImageVectorParserTest(
172154
@Test
173155
fun `parse icon with linear gradient`() = runInEdtAndGet {
174156
val ktFile = parseType.toKtFile(
175-
project = project,
176157
pathToLazy = "imagevector/kt/backing/LinearGradient.kt",
177158
pathToBacking = "imagevector/kt/lazy/LinearGradient.kt",
178159
)
@@ -184,7 +165,6 @@ class KtFileToImageVectorParserTest(
184165
@Test
185166
fun `parse icon with linear gradient and stroke`() = runInEdtAndGet {
186167
val ktFile = parseType.toKtFile(
187-
project = project,
188168
pathToLazy = "imagevector/kt/backing/LinearGradientWithStroke.kt",
189169
pathToBacking = "imagevector/kt/lazy/LinearGradientWithStroke.kt",
190170
)
@@ -196,7 +176,6 @@ class KtFileToImageVectorParserTest(
196176
@Test
197177
fun `parse linear gradient with clip path`() = runInEdtAndGet {
198178
val ktFile = parseType.toKtFile(
199-
project = project,
200179
pathToLazy = "imagevector/kt/lazy/ClipPathGradient.kt",
201180
pathToBacking = "imagevector/kt/backing/ClipPathGradient.kt",
202181
)
@@ -208,12 +187,22 @@ class KtFileToImageVectorParserTest(
208187
@Test
209188
fun `parse icon with radial gradient`() = runInEdtAndGet {
210189
val ktFile = parseType.toKtFile(
211-
project = project,
212190
pathToLazy = "imagevector/kt/backing/RadialGradient.kt",
213191
pathToBacking = "imagevector/kt/lazy/RadialGradient.kt",
214192
)
215193
val imageVector = ImageVectorPsiParser.parseToIrImageVector(ktFile)?.toComposeImageVector()
216194

217195
assertThat(imageVector).isEqualTo(ExpectedRadialGradient)
218196
}
197+
198+
// Use path for build folder with all generated test resources
199+
override val testDataPath: String = TEST_DATA_PATH
200+
201+
fun ParseType.toKtFile(
202+
pathToLazy: String,
203+
pathToBacking: String,
204+
): KtFile = when (this) {
205+
ParseType.Lazy -> loadKtFile(pathToLazy)
206+
ParseType.Backing -> loadKtFile(pathToBacking)
207+
}
219208
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
package io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.common
22

3-
import com.intellij.openapi.project.Project
4-
import org.jetbrains.kotlin.psi.KtFile
5-
63
enum class ParseType {
74
Lazy,
85
Backing,
96
}
10-
11-
fun ParseType.toKtFile(
12-
project: Project,
13-
pathToLazy: String,
14-
pathToBacking: String,
15-
): KtFile = when (this) {
16-
ParseType.Lazy -> project.createKtFile(pathToLazy)
17-
ParseType.Backing -> project.createKtFile(pathToBacking)
18-
}

sdk/intellij/test-fixtures/src/testFixtures/kotlin/io/github/composegears/valkyrie/sdk/intellij/testfixtures/KotlinCodeInsightTest.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.github.composegears.valkyrie.sdk.intellij.testfixtures
22

3-
import com.intellij.openapi.application.runInEdt
43
import com.intellij.openapi.vfs.LocalFileSystem
5-
import com.intellij.testFramework.LightPlatformTestCase
64
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
75
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
86
import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl
@@ -45,10 +43,7 @@ abstract class KotlinCodeInsightTest {
4543

4644
@AfterEach
4745
internal fun tearDownEdt() {
48-
runInEdt {
49-
fixture.tearDown()
50-
LightPlatformTestCase.closeAndDeleteProject()
51-
}
46+
fixture.tearDown()
5247
}
5348

5449
protected fun loadKtFile(fileName: String): KtFile {

0 commit comments

Comments
 (0)