diff --git a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumApplicationScopeTest.kt b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumApplicationScopeTest.kt index 13f4f8e5bb..a271d53943 100644 --- a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumApplicationScopeTest.kt +++ b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumApplicationScopeTest.kt @@ -379,8 +379,8 @@ internal class RumApplicationScopeTest { val fakeEvents = forge.aList { forge.anyRumEvent( excluding = listOf( - RumRawEvent.ApplicationStarted::class.java, - RumRawEvent.SdkInit::class.java + RumRawEvent.ApplicationStarted::class, + RumRawEvent.SdkInit::class ) ) } @@ -428,8 +428,8 @@ internal class RumApplicationScopeTest { val fakeEvents = forge.aList { forge.anyRumEvent( excluding = listOf( - RumRawEvent.ApplicationStarted::class.java, - RumRawEvent.SdkInit::class.java + RumRawEvent.ApplicationStarted::class, + RumRawEvent.SdkInit::class ) ) } diff --git a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumRawEventExt.kt b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumRawEventExt.kt index 1db369cb73..0f10eaddb1 100644 --- a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumRawEventExt.kt +++ b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumRawEventExt.kt @@ -14,9 +14,9 @@ import com.datadog.android.rum.internal.domain.Time import com.datadog.tools.unit.forge.aThrowable import com.datadog.tools.unit.forge.exhaustiveAttributes import fr.xgouchet.elmyr.Forge -import java.lang.reflect.Type import java.net.URL import java.util.UUID +import kotlin.reflect.KClass internal fun Forge.interactiveRumRawEvent(): RumRawEvent { return anElementFrom( @@ -168,48 +168,50 @@ internal fun Forge.addCustomTimingEvent(): RumRawEvent.AddCustomTiming { internal fun Forge.validBackgroundEvent(): RumRawEvent { return this.anElementFrom( listOf( - startActionEvent(), - addErrorEvent(), - startResourceEvent() + { startActionEvent() }, + { addErrorEvent() }, + { startResourceEvent() } ) - ) + ).invoke() } internal fun Forge.invalidBackgroundEvent(): RumRawEvent { return this.anElementFrom( listOf( - addLongTaskEvent(), - stopActionEvent(), - stopResourceEvent(), - stopResourceWithErrorEvent(), - stopResourceWithStacktraceEvent(), - addViewLoadingTimeEvent() + { addLongTaskEvent() }, + { stopActionEvent() }, + { stopResourceEvent() }, + { stopResourceWithErrorEvent() }, + { stopResourceWithStacktraceEvent() }, + { addViewLoadingTimeEvent() } ) - ) -} - -internal fun Forge.anyRumEvent(excluding: List = listOf()): RumRawEvent { - val allEvents = listOf( - startViewEvent(), - stopViewEvent(), - startActionEvent(), - stopActionEvent(), - startResourceEvent(), - stopResourceEvent(), - stopResourceWithErrorEvent(), - stopResourceWithStacktraceEvent(), - addErrorEvent(), - addLongTaskEvent(), - addFeatureFlagEvaluationEvent(), - addCustomTimingEvent(), - updatePerformanceMetricEvent(), - addViewLoadingTimeEvent() + ).invoke() +} + +internal fun Forge.anyRumEvent(excluding: List> = listOf()): RumRawEvent { + fun strictSameTypePair(key: KClass, value: () -> T) = key to value + val allEventsFactories = mapOf, () -> RumRawEvent>( + strictSameTypePair(RumRawEvent.StartView::class, { startViewEvent() }), + strictSameTypePair(RumRawEvent.StopView::class, { stopViewEvent() }), + strictSameTypePair(RumRawEvent.StartAction::class, { startActionEvent() }), + strictSameTypePair(RumRawEvent.StopAction::class, { stopActionEvent() }), + strictSameTypePair(RumRawEvent.StartResource::class, { startResourceEvent() }), + strictSameTypePair(RumRawEvent.StopResource::class, { stopResourceEvent() }), + strictSameTypePair(RumRawEvent.StopResourceWithError::class, { stopResourceWithErrorEvent() }), + strictSameTypePair(RumRawEvent.StopResourceWithStackTrace::class, { stopResourceWithStacktraceEvent() }), + strictSameTypePair(RumRawEvent.AddError::class, { addErrorEvent() }), + strictSameTypePair(RumRawEvent.AddLongTask::class, { addLongTaskEvent() }), + strictSameTypePair(RumRawEvent.AddFeatureFlagEvaluation::class, { addFeatureFlagEvaluationEvent() }), + strictSameTypePair(RumRawEvent.AddCustomTiming::class, { addCustomTimingEvent() }), + strictSameTypePair(RumRawEvent.UpdatePerformanceMetric::class, { updatePerformanceMetricEvent() }), + strictSameTypePair(RumRawEvent.AddViewLoadingTime::class, { addViewLoadingTimeEvent() }) ) return this.anElementFrom( - allEvents.filter { - it.javaClass !in excluding - } - ) + allEventsFactories + .filter { !excluding.contains(it.key) } + .values + .toList() + ).invoke() } internal fun Forge.invalidAppLaunchEvent(): RumRawEvent { diff --git a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt index 01e5d61afd..08888e102d 100644 --- a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt +++ b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt @@ -962,14 +962,14 @@ internal class RumSessionScopeTest { initializeTestedScope(backgroundTrackingEnabled = false) val fakeNonInteractionEvent1 = forge.anyRumEvent( excluding = listOf( - RumRawEvent.StartView::class.java, - RumRawEvent.StartAction::class.java + RumRawEvent.StartView::class, + RumRawEvent.StartAction::class ) ) val fakeNonInteractionEvent2 = forge.anyRumEvent( excluding = listOf( - RumRawEvent.StartView::class.java, - RumRawEvent.StartAction::class.java + RumRawEvent.StartView::class, + RumRawEvent.StartAction::class ) ) testedScope.handleEvent(fakeNonInteractionEvent1, mockWriter) diff --git a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt index 8d8562fb3b..f385e7d372 100644 --- a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt +++ b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt @@ -9349,14 +9349,14 @@ internal class RumViewScopeTest { testedScope.handleEvent( forge.anyRumEvent( excluding = listOf( - RumRawEvent.StartView::class.java, - RumRawEvent.StopView::class.java, - RumRawEvent.StartAction::class.java, - RumRawEvent.StopAction::class.java, - RumRawEvent.StartResource::class.java, - RumRawEvent.StopResource::class.java, - RumRawEvent.StopResourceWithError::class.java, - RumRawEvent.StopResourceWithStackTrace::class.java + RumRawEvent.StartView::class, + RumRawEvent.StopView::class, + RumRawEvent.StartAction::class, + RumRawEvent.StopAction::class, + RumRawEvent.StartResource::class, + RumRawEvent.StopResource::class, + RumRawEvent.StopResourceWithError::class, + RumRawEvent.StopResourceWithStackTrace::class ) ), mockWriter