Files
openide/plugins/settings-sync/tests/com/intellij/settingsSync/MergePluginsStateTest.kt
Kirill Likhodedov 28f8cd94f8 settings-sync: smartly resolve conflicts in plugins.json: IDEA-299213
Merge them as structures instead of simply preferring the 'last-modified' strategy.

GitOrigin-RevId: b5bd043d719914c21a9a9522788e894658cf9711
2023-01-17 10:51:47 +00:00

65 lines
1.8 KiB
Kotlin

package com.intellij.settingsSync
import com.intellij.openapi.extensions.PluginId
import com.intellij.settingsSync.plugins.SettingsSyncPluginsState
import com.intellij.settingsSync.plugins.SettingsSyncPluginsStateMerger.mergePluginStates
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
class MergePluginsStateTest {
@Test
fun `test merge plugins state`() {
val baseState = pluginStates {
"A" to true
"B" to true
"C" to true
}
// removed B, modified C, added D, added enabled E
val olderState = pluginStates {
"A" to true
"C" to false
"D" to true
"E" to true
}
// changed B, removed C, also added D, added disabled E
val newerState = pluginStates {
"A" to true
"B" to false
"D" to true
"E" to false
}
val actualMergedStates = mergePluginStates(baseState, olderState, newerState)
val expectedMergedState = pluginStates {
"A" to true
"B" to false // modification newer than removal
// no C because removal newer than modification
"D" to true // both added
"E" to false // disabled state is newer
}
assertPluginsState(expectedMergedState.plugins, actualMergedStates.plugins)
}
private fun pluginStates(build: StateBuilder.() -> Unit): SettingsSyncPluginsState {
val builder = StateBuilder()
builder.build()
return SettingsSyncPluginsState(builder.states)
}
private class StateBuilder {
val states = mutableMapOf<PluginId, SettingsSyncPluginsState.PluginData>()
infix fun String.to(enabled: Boolean) {
val pluginData = SettingsSyncPluginsState.PluginData(enabled)
val pluginId = PluginId.getId(this)
states[pluginId] = pluginData
}
}
}