Skip to content

Commit e027a1e

Browse files
committed
Fix detekt UnsafeCallOnNullableType in TelemetryHelperTest for 2025.3
Replace event!! with requireNotNull(event) to avoid unsafe null assertions. This follows the same pattern used in LoginBrowserTest.
1 parent 6bc594d commit e027a1e

File tree

1 file changed

+19
-13
lines changed
  • plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq

1 file changed

+19
-13
lines changed

plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/TelemetryHelperTest.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,18 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
149149
override fun setUp() {
150150
super.setUp()
151151
// Initialize mock managers using JUnit Rule pattern
152-
mockClientManager.apply(object : Statement() {
153-
override fun evaluate() {}
154-
}, org.junit.runner.Description.EMPTY).evaluate()
155-
mockTelemetryService.apply(object : Statement() {
156-
override fun evaluate() {}
157-
}, org.junit.runner.Description.EMPTY).evaluate()
152+
mockClientManager.apply(
153+
object : Statement() {
154+
override fun evaluate() {}
155+
},
156+
org.junit.runner.Description.EMPTY
157+
).evaluate()
158+
mockTelemetryService.apply(
159+
object : Statement() {
160+
override fun evaluate() {}
161+
},
162+
org.junit.runner.Description.EMPTY
163+
).evaluate()
158164
// set up sut
159165
appInitContext = AmazonQAppInitContext(
160166
project = project,
@@ -245,7 +251,7 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
245251
verify(mockBatcher).enqueue(capture())
246252
val event = firstValue.data.find { it.name == "amazonq_addMessage" }
247253
assertNotNull(event)
248-
assertThat(event!!)
254+
assertThat(requireNotNull(event))
249255
.matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversation id doesn't match")
250256
.matches({ it.metadata["cwsprChatMessageId"] == "messageId" }, "message id doesn't match")
251257
.matches(
@@ -329,7 +335,7 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
329335
verify(mockBatcher).enqueue(capture())
330336
val event = firstValue.data.find { it.name == "amazonq_interactWithMessage" }
331337
assertNotNull(event)
332-
assertThat(event!!)
338+
assertThat(requireNotNull(event))
333339
.matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversationId doesn't match")
334340
.matches({ it.metadata["cwsprChatMessageId"] == messageId }, "messageId doesn't match")
335341
.matches(
@@ -372,7 +378,7 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
372378
verify(mockBatcher).enqueue(capture())
373379
val event = firstValue.data.find { it.name == "amazonq_interactWithMessage" }
374380
assertNotNull(event)
375-
assertThat(event!!)
381+
assertThat(requireNotNull(event))
376382
.matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversationId doesn't match")
377383
.matches({ it.metadata["cwsprChatMessageId"] == messageId }, "messageId doesn't match")
378384
.matches(
@@ -430,7 +436,7 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
430436
verify(mockBatcher).enqueue(capture())
431437
val event = firstValue.data.find { it.name == "amazonq_interactWithMessage" }
432438
assertNotNull(event)
433-
assertThat(event!!)
439+
assertThat(requireNotNull(event))
434440
.matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversationId doesn't match")
435441
.matches({ it.metadata["cwsprChatMessageId"] == messageId }, "messageId doesn't match")
436442
.matches(
@@ -495,7 +501,7 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
495501
verify(mockBatcher).enqueue(capture())
496502
val event = firstValue.data.find { it.name == "amazonq_interactWithMessage" }
497503
assertNotNull(event)
498-
assertThat(event!!).matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversationId doesn't match")
504+
assertThat(requireNotNull(event)).matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversationId doesn't match")
499505
.matches({ it.metadata["cwsprChatMessageId"] == messageId }, "messageId doesn't match")
500506
.matches(
501507
{ it.metadata["cwsprChatInteractionType"] == CwsprChatInteractionType.InsertAtCursor.toString() },
@@ -554,7 +560,7 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
554560
verify(mockBatcher).enqueue(capture())
555561
val event = firstValue.data.find { it.name == "amazonq_interactWithMessage" }
556562
assertNotNull(event)
557-
assertThat(event!!).matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversationId doesn't match")
563+
assertThat(requireNotNull(event)).matches({ it.metadata["cwsprChatConversationId"] == conversationId }, "conversationId doesn't match")
558564
.matches({ it.metadata["cwsprChatMessageId"] == messageId }, "messageId doesn't match")
559565
.matches(
560566
{ it.metadata["cwsprChatInteractionType"] == CwsprChatInteractionType.ClickLink.toString() },
@@ -593,7 +599,7 @@ class TelemetryHelperTest : HeavyPlatformTestCase() {
593599
verify(mockBatcher, times(2)).enqueue(capture())
594600
val event = firstValue.data.find { it.name == "feedback_result" }
595601
assertNotNull(event)
596-
assertThat(event!!).matches { it.metadata["result"] == "Succeeded" }
602+
assertThat(requireNotNull(event)).matches { it.metadata["result"] == "Succeeded" }
597603
}
598604
}
599605
}

0 commit comments

Comments
 (0)