Skip to content

Commit d72a854

Browse files
committed
rebuild tests
1 parent c4199d6 commit d72a854

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

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

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,55 @@
55

66
package io.openapiprocessor.intellij
77

8-
import com.intellij.openapi.vfs.VirtualFile
9-
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase5
10-
import com.intellij.testFramework.junit5.TestApplication
11-
import org.junit.jupiter.api.Assertions.assertEquals
8+
import com.intellij.openapi.vfs.VfsUtil.findFileByURL
9+
import com.intellij.openapi.vfs.VfsUtilCore.convertToURL
10+
import com.intellij.util.io.directoryContent
11+
import com.intellij.util.io.generateInVirtualTempDir
12+
import io.openapiprocessor.intellij.support.LightInsightTestCase
13+
import org.junit.jupiter.api.Assertions.*
1214
import org.junit.jupiter.api.Test
1315

14-
15-
@TestApplication
16-
class FileTypeSpec : LightJavaCodeInsightFixtureTestCase5() {
16+
class FileTypeSpec : LightInsightTestCase() {
1717

1818
override fun getTestDataPath(): String {
1919
return "src/test/testdata/filetype"
2020
}
2121

22-
private fun loadFile(path: String): VirtualFile {
23-
return fixture.configureByFile(path).virtualFile
22+
@Test
23+
fun `detects file type with 'yaml' extension`() {
24+
assertEquals(TypeMappingFileType.NAME, openFile("mapping.yaml").fileType.name)
2425
}
2526

2627
@Test
27-
fun `detects file type with 'yaml' extension`() {
28-
val mapping = loadFile("mapping.yaml")
29-
assertEquals(TypeMappingFileType.NAME, mapping.fileType.name)
28+
fun `detects file type with 'yml' extension`() {
29+
assertEquals(TypeMappingFileType.NAME, openFile("mapping.yml").fileType.name)
30+
}
31+
32+
@Test
33+
fun `ignores empty file`() {
34+
assertFalse(openFile("empty.yaml").fileType.name.startsWith(TypeMappingFileType.NAME))
35+
}
36+
37+
@Test
38+
fun `ignores directory`() {
39+
assertFalse(createDir("foo").fileType.name.startsWith(TypeMappingFileType.NAME))
40+
}
41+
42+
@Test
43+
fun `detects yaml in jar`() {
44+
val tmpDir = directoryContent {
45+
zip("yaml.jar") {
46+
dir("resources") {
47+
file("a.yaml", "openapi-processor-mapping: v2\n")
48+
}
49+
}
50+
}.generateInVirtualTempDir()
51+
52+
addJar(tmpDir.path, "yaml.jar")
53+
54+
val url = convertToURL("jar://${tmpDir.path}/yaml.jar!/resources/a.yaml")!!
55+
val yml = findFileByURL(url)
56+
57+
assertTrue(yml!!.fileType.name.startsWith(TypeMappingFileType.NAME))
3058
}
3159
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2025 https://github.com/openapi-processor/openapi-processor-intellij
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.intellij.support
7+
8+
import com.intellij.openapi.vfs.VfsUtil.getUrlForLibraryRoot
9+
import com.intellij.openapi.vfs.VirtualFile
10+
import com.intellij.testFramework.PsiTestUtil
11+
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase5
12+
import java.io.File
13+
14+
open class LightInsightTestCase: LightJavaCodeInsightFixtureTestCase5() {
15+
16+
fun openFile(path: String): VirtualFile {
17+
return fixture.configureByFile(path).virtualFile
18+
}
19+
20+
fun createDir(path: String): VirtualFile {
21+
return fixture.tempDirFixture.findOrCreateDir(path)
22+
}
23+
24+
fun addJar(path: String, name: String) {
25+
PsiTestUtil.addLibrary(
26+
fixture.module,
27+
name,
28+
getUrlForLibraryRoot(File("${path}/${name}"))
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)