Files
openide/plugins/configuration-script/test/ComponentStateTest.kt
Alexey Belkov 9b5e8782f3 Run Kotlin inspection "Redundant nullable return type" on whole project
Plus some minor cleanups due to changed nullability.

GitOrigin-RevId: 406cf3bb86a9d1d57aa088bc0ff43cca5a8c2254
2022-05-27 22:07:13 +00:00

46 lines
1.4 KiB
Kotlin

package com.intellij.configurationScript
import com.intellij.openapi.components.BaseState
import com.intellij.testFramework.ProjectRule
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.util.ReflectionUtil
import org.intellij.lang.annotations.Language
import org.junit.ClassRule
import org.junit.Test
import org.snakeyaml.engine.v2.nodes.NodeTuple
class ComponentStateTest {
companion object {
@JvmField
@ClassRule
val projectRule = ProjectRule()
}
@Test
fun read() {
val result = doReadComponentConfiguration("versionControl.git", """
versionControl:
git:
updateMethod: rebase
""")
assertThat(result.updateMethod).isEqualTo(UpdateMethod.REBASE)
}
}
@Suppress("SameParameterValue")
private fun doReadComponentConfiguration(namePath: String, @Language("YAML") data: String): TestState {
return readComponentConfiguration(findValueNodeByPath(namePath, doRead(data.trimIndent().reader())!!.value)!!, TestState::class.java)
}
private fun <T : BaseState> readComponentConfiguration(nodes: List<NodeTuple>, stateClass: Class<out T>): T {
return readIntoObject(ReflectionUtil.newInstance(stateClass), nodes)
}
private class TestState : BaseState() {
var updateMethod by enum(UpdateMethod.BRANCH_DEFAULT)
}
@Suppress("unused")
private enum class UpdateMethod {
BRANCH_DEFAULT, MERGE, REBASE
}