| 1 |
package org.jetbrains.plugins.template |
| 2 |
|
| 3 |
import com.intellij.ide.highlighter.XmlFileType |
| 4 |
import com.intellij.openapi.components.service |
| 5 |
import com.intellij.psi.xml.XmlFile |
| 6 |
import com.intellij.testFramework.TestDataPath |
| 7 |
import com.intellij.testFramework.fixtures.BasePlatformTestCase |
| 8 |
import com.intellij.util.PsiErrorElementUtil |
| 9 |
import org.jetbrains.plugins.template.services.MyProjectService |
| 10 |
|
| 11 |
@TestDataPath("\$CONTENT_ROOT/src/test/testData") |
| 12 |
class MyPluginTest : BasePlatformTestCase() { |
| 13 |
|
| 14 |
fun testXMLFile() { |
| 15 |
val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "<foo>bar</foo>") |
| 16 |
val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java) |
| 17 |
|
| 18 |
assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile)) |
| 19 |
|
| 20 |
assertNotNull(xmlFile.rootTag) |
| 21 |
|
| 22 |
xmlFile.rootTag?.let { |
| 23 |
assertEquals("foo", it.name) |
| 24 |
assertEquals("bar", it.value.text) |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
fun testRename() { |
| 29 |
myFixture.testRename("foo.xml", "foo_after.xml", "a2") |
| 30 |
} |
| 31 |
|
| 32 |
fun testProjectService() { |
| 33 |
val projectService = project.service<MyProjectService>() |
| 34 |
|
| 35 |
assertNotSame(projectService.getRandomNumber(), projectService.getRandomNumber()) |
| 36 |
} |
| 37 |
|
| 38 |
override fun getTestDataPath() = "src/test/testData/rename" |
| 39 |
} |