Files
openide/platform/configuration-store-impl/testSrc/StorageManagerTest.kt
Vladimir Krivosheev 0e46c68bcd IJPL-136 cleanup
GitOrigin-RevId: 43808d0552ba6b2ce58f27e9eae6d043e817f2ae
2024-02-19 15:26:20 +00:00

54 lines
2.0 KiB
Kotlin

// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.configurationStore
import com.intellij.openapi.components.RoamingType
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.ProjectRule
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Before
import org.junit.ClassRule
import org.junit.Test
import java.nio.file.Path
import kotlin.properties.Delegates
class StorageManagerTest {
companion object {
private const val MACRO = "\$MACRO1$"
@JvmField @ClassRule val projectRule = ProjectRule()
}
private var storageManager: StateStorageManagerImpl by Delegates.notNull()
@Before
fun setUp() {
storageManager = StateStorageManagerImpl("foo", componentManager = null, controller = null)
storageManager.setMacros(listOf(Macro(MACRO, Path.of("/temp/m1"))))
}
@Test
fun createFileStateStorageMacroSubstituted() {
assertThat(storageManager.getOrCreateStorage("$MACRO/test.xml", RoamingType.DEFAULT)).isNotNull()
}
@Test
fun `collapse macro`() {
assertThat(storageManager.collapseMacro("/temp/m1/foo")).isEqualTo("$MACRO/foo")
assertThat(storageManager.collapseMacro("\\temp\\m1\\foo")).isEqualTo("/temp/m1/foo")
}
@Test
fun `create storage assertion thrown when unknown macro`() {
assertThatThrownBy { storageManager.getOrCreateStorage("\$UNKNOWN_MACRO$/test.xml", RoamingType.DEFAULT) }
.isInstanceOf(IllegalStateException::class.java)
.hasMessage("Cannot resolve \$UNKNOWN_MACRO\$/test.xml in [Macro(key=\$MACRO1\$, value=${FileUtil.toSystemDependentName("/temp/m1")})]")
}
@Test
fun `create file storage macro substituted when expansion has$`() {
storageManager.setMacros(listOf(Macro("\$DOLLAR_MACRO$", Path.of("/temp/d$"))))
assertThat(storageManager.getOrCreateStorage("\$DOLLAR_MACRO$/test.xml", RoamingType.DEFAULT)).isNotNull()
}
}