Skip to content

Commit e15c0a4

Browse files
committed
persistent state syntax
1 parent 81fa23a commit e15c0a4

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationFormatUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ enum class NotificationSeverity {
4141

4242
enum class NotificationScheduleType {
4343
STARTUP,
44-
EMERGENCY;
44+
EMERGENCY,
45+
;
4546

4647
companion object {
4748
fun fromString(value: String): NotificationScheduleType {

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPersistantState.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import com.intellij.openapi.components.Storage
1010

1111
@State(name = "notificationDismissals", storages = [Storage("aws.xml")])
1212
class NotificationDismissalState : PersistentStateComponent<NotificationDismissalConfiguration> {
13-
private var state = NotificationDismissalConfiguration()
13+
private val state = NotificationDismissalConfiguration()
1414

1515
override fun getState(): NotificationDismissalConfiguration = state
1616

1717
override fun loadState(state: NotificationDismissalConfiguration) {
18-
this.state = state
18+
this.state.dismissedNotificationIds.clear()
19+
this.state.dismissedNotificationIds.addAll(state.dismissedNotificationIds)
1920
}
2021

2122
fun isDismissed(notificationId: String): Boolean =
@@ -37,12 +38,12 @@ data class NotificationDismissalConfiguration(
3738

3839
@State(name = "notificationEtag", storages = [Storage("aws.xml")])
3940
class NotificationEtagState : PersistentStateComponent<NotificationEtagConfiguration> {
40-
private var state = NotificationEtagConfiguration()
41+
private val state = NotificationEtagConfiguration()
4142

4243
override fun getState(): NotificationEtagConfiguration = state
4344

4445
override fun loadState(state: NotificationEtagConfiguration) {
45-
this.state = state
46+
this.state.etag = state.etag
4647
}
4748

4849
var etag: String?

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/ProcessNotificationsBase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ProcessNotificationsBase(
4444
}
4545

4646
fun retrieveStartupAndEmergencyNotifications() {
47-
val isStartupPoll = isStartup.compareAndSet(true,false)
47+
val isStartupPoll = isStartup.compareAndSet(true, false)
4848
val notifications = getNotificationsFromFile()
4949
notifications?.let { notificationsList ->
5050
val activeNotifications = notificationsList.notifications

plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/notifications/ProcessNotificationsBaseTest.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
package software.aws.toolkits.jetbrains.core.notifications
55

6+
import com.intellij.openapi.project.Project
7+
import com.intellij.testFramework.ApplicationExtension
68
import io.mockk.every
79
import io.mockk.mockk
10+
import io.mockk.mockkObject
811
import io.mockk.spyk
9-
import io.mockk.verify
1012
import io.mockk.unmockkAll
11-
import io.mockk.mockkObject
13+
import io.mockk.verify
1214
import org.junit.jupiter.api.AfterEach
1315
import org.junit.jupiter.api.BeforeEach
1416
import org.junit.jupiter.api.Test
15-
import com.intellij.openapi.project.Project
16-
import com.intellij.testFramework.ApplicationExtension
1717
import org.junit.jupiter.api.extension.ExtendWith
1818
import java.util.concurrent.atomic.AtomicBoolean
1919

@@ -34,7 +34,6 @@ class ProcessNotificationsBaseTest {
3434
sut = spyk<ProcessNotificationsBase>(
3535
objToCopy = ProcessNotificationsBase(project)
3636
)
37-
3837
}
3938

4039
@Test
@@ -81,7 +80,6 @@ class ProcessNotificationsBaseTest {
8180
// second poll skips processing
8281
sut.retrieveStartupAndEmergencyNotifications()
8382

84-
8583
verify(exactly = 1) { sut.processNotification(project, any()) }
8684
}
8785

@@ -96,7 +94,7 @@ class ProcessNotificationsBaseTest {
9694

9795
@Test
9896
fun `empty notifications list is handled gracefully`() {
99-
every { sut["getNotificationsFromFile"]()} returns createNotificationsList()
97+
every { sut["getNotificationsFromFile"]() } returns createNotificationsList()
10098

10199
sut.retrieveStartupAndEmergencyNotifications()
102100

@@ -128,7 +126,7 @@ class ProcessNotificationsBaseTest {
128126
}
129127

130128
// Helper functions to create test data
131-
private fun createNotification(id: String, type: NotificationScheduleType) = NotificationData(
129+
private fun createNotification(id: String, type: NotificationScheduleType) = NotificationData(
132130
id = id,
133131
schedule = NotificationSchedule(type = type),
134132
severity = "INFO",
@@ -156,8 +154,6 @@ private fun createNotification(id: String, type: NotificationScheduleType) = Not
156154
value.set(true)
157155
}
158156

159-
160-
161157
@AfterEach
162158
fun tearDown() {
163159
unmockkAll()

0 commit comments

Comments
 (0)