|
5 | 5 |
|
6 | 6 | package io.openapiprocessor.intellij |
7 | 7 |
|
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.* |
12 | 14 | import org.junit.jupiter.api.Test |
13 | 15 |
|
14 | | - |
15 | | -@TestApplication |
16 | | -class FileTypeSpec : LightJavaCodeInsightFixtureTestCase5() { |
| 16 | +class FileTypeSpec : LightInsightTestCase() { |
17 | 17 |
|
18 | 18 | override fun getTestDataPath(): String { |
19 | 19 | return "src/test/testdata/filetype" |
20 | 20 | } |
21 | 21 |
|
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) |
24 | 25 | } |
25 | 26 |
|
26 | 27 | @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)) |
30 | 58 | } |
31 | 59 | } |
0 commit comments