Skip to content

Commit aefe915

Browse files
committed
Adding unit test cases
1 parent 7df6549 commit aefe915

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class CodeWhispererConfigurable(private val project: Project) :
7373
textFieldWithBrowseButton(fileChooserDescriptor = fileChooserDescriptor)
7474
.bindText(
7575
{ LspSettings.getInstance().getArtifactPath() },
76-
{ LspSettings.getInstance().setExecutablePath(it.takeIf { v -> v.isNotBlank() }) }
76+
{ LspSettings.getInstance().setArtifactPath(it.takeIf { v -> v.isNotBlank() }) }
7777
)
7878
.applyToComponent {
7979
emptyText.text = "Choose a file to upload"

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class LspSettings : PersistentStateComponent<LspConfiguration> {
2525

2626
fun getArtifactPath() = state.artifactPath
2727

28-
fun setExecutablePath(artifactPath: String?) {
28+
fun setArtifactPath(artifactPath: String?) {
2929
if (artifactPath == null) {
3030
state.artifactPath = ""
3131
} else {
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.settings
5+
6+
import com.intellij.util.xmlb.XmlSerializer
7+
import org.assertj.core.api.Assertions.assertThat
8+
import org.jdom.output.XMLOutputter
9+
import org.junit.Before
10+
import org.junit.Test
11+
import software.aws.toolkits.jetbrains.utils.xmlElement
12+
13+
class LspSettingsTest {
14+
private lateinit var lspSettings: LspSettings
15+
16+
@Before
17+
fun setUp() {
18+
lspSettings = LspSettings()
19+
lspSettings.loadState(LspConfiguration())
20+
}
21+
22+
@Test
23+
fun `artifact path is empty by default`() {
24+
assertThat(lspSettings.getArtifactPath()).isEmpty()
25+
}
26+
27+
@Test
28+
fun `artifact path can be set`() {
29+
lspSettings.setArtifactPath("test\\lsp.js")
30+
assertThat(lspSettings.getArtifactPath()).isNotEmpty()
31+
assertThat(lspSettings.getArtifactPath()).isEqualTo("test\\lsp.js")
32+
}
33+
34+
@Test
35+
fun `artifact path cannot be null`() {
36+
lspSettings.setArtifactPath(null)
37+
assertThat(lspSettings.getArtifactPath()).isEmpty()
38+
}
39+
40+
@Test
41+
fun `serialize settings to ensure backwards compatibility`() {
42+
val element = xmlElement(
43+
"""
44+
<component name="LspSettings">
45+
</component>
46+
""".trimIndent()
47+
)
48+
lspSettings.setArtifactPath("temp\\lsp.js")
49+
50+
XmlSerializer.serializeInto(lspSettings.state, element)
51+
52+
val actual = XMLOutputter().outputString(element)
53+
54+
val expected = "<component name=\"LspSettings\">\n" +
55+
"<option name=\"artifactPath\" value=\"temp\\lsp.js\" /></component>"
56+
57+
assertThat(actual).isEqualTo(expected)
58+
}
59+
60+
@Test
61+
fun `deserialize empty settings to ensure backwards compatibility`() {
62+
val element = xmlElement(
63+
"""
64+
<component name="LspSettings">
65+
</component>
66+
"""
67+
)
68+
val actual = XmlSerializer.deserialize(element, LspConfiguration::class.java)
69+
assertThat(actual.artifactPath).isEmpty()
70+
}
71+
72+
@Test
73+
fun `deserialize existing settings to ensure backwards compatibility`() {
74+
val element = xmlElement(
75+
"""
76+
<component name="LspSettings">
77+
<option name="artifactPath" value='temp\lsp.js'/>
78+
</component>
79+
""".trimIndent()
80+
)
81+
val actual = XmlSerializer.deserialize(element, LspConfiguration::class.java)
82+
assertThat(actual.artifactPath).isNotEmpty()
83+
assertThat(actual.artifactPath).isEqualTo("temp\\lsp.js")
84+
}
85+
}

0 commit comments

Comments
 (0)