@@ -78,6 +78,7 @@ import org.mockito.kotlin.doThrow
78
78
import org.mockito.kotlin.eq
79
79
import org.mockito.kotlin.mock
80
80
import org.mockito.kotlin.verify
81
+ import org.mockito.kotlin.verifyNoInteractions
81
82
import org.mockito.kotlin.whenever
82
83
import org.mockito.quality.Strictness
83
84
import java.util.Locale
@@ -86,6 +87,7 @@ import java.util.concurrent.CancellationException
86
87
import java.util.concurrent.ExecutionException
87
88
import java.util.concurrent.Future
88
89
import java.util.concurrent.RejectedExecutionException
90
+ import java.util.concurrent.atomic.AtomicBoolean
89
91
90
92
@Extensions(
91
93
ExtendWith (MockitoExtension ::class ),
@@ -144,6 +146,7 @@ internal class SdkFeatureTest {
144
146
whenever(coreFeature.mockInstance.batchProcessingLevel)
145
147
.thenReturn(fakeCoreBatchProcessingLevel)
146
148
whenever(coreFeature.mockTrackingConsentProvider.getConsent()) doReturn fakeConsent
149
+ whenever(coreFeature.mockInstance.initialized) doReturn AtomicBoolean (true )
147
150
whenever(mockWrappedFeature.name) doReturn fakeFeatureName
148
151
whenever(mockWrappedFeature.requestFactory) doReturn mock()
149
152
whenever(mockWrappedFeature.storageConfiguration) doReturn fakeStorageConfiguration
@@ -512,6 +515,22 @@ internal class SdkFeatureTest {
512
515
)
513
516
}
514
517
518
+ @Test
519
+ fun `M not provide write context W withWriteContext(callback) { CoreFeature is not initialized }` (
520
+ @StringForgery fakeWithFeatureContexts : Set <String >
521
+ ) {
522
+ // Given
523
+ testedFeature.storage = mockStorage
524
+ val callback = mock< (DatadogContext , EventWriteScope ) -> Unit > ()
525
+ whenever(coreFeature.mockInstance.initialized) doReturn AtomicBoolean (false )
526
+
527
+ // When
528
+ testedFeature.withWriteContext(fakeWithFeatureContexts, callback = callback)
529
+
530
+ // Then
531
+ verifyNoInteractions(callback, mockContextProvider, mockStorage)
532
+ }
533
+
515
534
@Test
516
535
fun `M provide Datadog context W withContext(callback)` (
517
536
@Forgery fakeContext : DatadogContext ,
@@ -529,6 +548,22 @@ internal class SdkFeatureTest {
529
548
verify(callback).invoke(fakeContext)
530
549
}
531
550
551
+ @Test
552
+ fun `M not provide Datadog context W withContext(callback) { CoreFeature is not initialized }` (
553
+ @StringForgery fakeWithFeatureContexts : Set <String >
554
+ ) {
555
+ // Given
556
+ testedFeature.storage = mockStorage
557
+ val callback = mock< (DatadogContext ) -> Unit > ()
558
+ whenever(coreFeature.mockInstance.initialized) doReturn AtomicBoolean (false )
559
+
560
+ // When
561
+ testedFeature.withContext(fakeWithFeatureContexts, callback = callback)
562
+
563
+ // Then
564
+ verifyNoInteractions(callback, mockContextProvider)
565
+ }
566
+
532
567
@Test
533
568
fun `M provide write context W getWriteContextSync()` (
534
569
@Forgery fakeContext : DatadogContext ,
@@ -610,6 +645,19 @@ internal class SdkFeatureTest {
610
645
assertThat(writeContext).isNull()
611
646
}
612
647
648
+ @Test
649
+ fun `M provide null write context W getWriteContextSync() { CoreFeature is not initialized }` () {
650
+ // Given
651
+ whenever(coreFeature.mockInstance.initialized) doReturn AtomicBoolean (false )
652
+
653
+ // When
654
+ val writeContext = testedFeature.getWriteContextSync()
655
+
656
+ // Then
657
+ assertThat(writeContext).isNull()
658
+ verifyNoInteractions(mockContextProvider, mockStorage)
659
+ }
660
+
613
661
@Test
614
662
fun `M send event W sendEvent(event)` () {
615
663
// Given
0 commit comments