diff --git a/packages/core/android/build.gradle b/packages/core/android/build.gradle index f2aff0433..10b8a18e7 100644 --- a/packages/core/android/build.gradle +++ b/packages/core/android/build.gradle @@ -12,7 +12,7 @@ buildscript { classpath 'com.android.tools.build:gradle:7.2.2' // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.1" + classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.1" classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.0" classpath 'com.github.bjoernq:unmockplugin:0.7.9' } @@ -207,7 +207,6 @@ ktlint { outputToConsole.set(true) ignoreFailures.set(false) enableExperimentalRules.set(false) - additionalEditorconfigFile.set(file("${project.rootDir}/script/config/.editorconfig")) filter { exclude("**/generated/**") include("**/kotlin/**") diff --git a/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt b/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt index 42687a692..7c26f4b75 100644 --- a/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt +++ b/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt @@ -16,7 +16,7 @@ import com.facebook.react.bridge.ReadableMap * The entry point to use Datadog's Trace feature. */ class DdTrace( - reactContext: ReactApplicationContext, + reactContext: ReactApplicationContext ) : ReactContextBaseJavaModule(reactContext) { private val implementation = DdTraceImplementation() diff --git a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt index a328cecbc..b9c3797d2 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt @@ -6,10 +6,12 @@ package com.datadog.reactnative -import com.datadog.android.api.SdkCore -import com.datadog.android.rum.* +import com.datadog.android.rum.RumActionType +import com.datadog.android.rum.RumAttributes +import com.datadog.android.rum.RumErrorSource +import com.datadog.android.rum.RumMonitor +import com.datadog.android.rum.RumResourceKind import com.datadog.tools.unit.forge.BaseConfigurator -import com.datadog.tools.unit.setStaticValue import com.datadog.tools.unit.toReadableMap import com.facebook.react.bridge.Promise import com.nhaarman.mockitokotlin2.doReturn @@ -129,8 +131,11 @@ internal class DdRumTest { // When testedDdRum.addAction( - type.name, name, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + type.name, + name, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -166,8 +171,11 @@ internal class DdRumTest { // When testedDdRum.startAction( - type.name, name, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + type.name, + name, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -203,8 +211,11 @@ internal class DdRumTest { // When testedDdRum.stopAction( - type.name, name, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + type.name, + name, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -241,8 +252,12 @@ internal class DdRumTest { // When testedDdRum.startResource( - key, method, url, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + key, + method, + url, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -360,8 +375,12 @@ internal class DdRumTest { // When testedDdRum.addError( - message, source.name, stackTrace, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + message, + source.name, + stackTrace, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -381,8 +400,12 @@ internal class DdRumTest { // When testedDdRum.addError( - message, source, stackTrace, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + message, + source, + stackTrace, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -396,7 +419,6 @@ internal class DdRumTest { @Test fun `M call addTiming W addTiming()`(@StringForgery timing: String) { - // When testedDdRum.addTiming(timing, mockPromise) @@ -406,7 +428,6 @@ internal class DdRumTest { @Test fun `M call stopSession W stopSession()`() { - // When testedDdRum.stopSession(mockPromise) diff --git a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt index e83a8a77a..2d2654384 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt @@ -16,7 +16,9 @@ import com.datadog.android.core.configuration.UploadFrequency import com.datadog.android.event.EventMapper import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent -import com.datadog.android.rum.* +import com.datadog.android.rum.RumConfiguration +import com.datadog.android.rum.RumPerformanceMetric +import com.datadog.android.rum._RumInternalProxy import com.datadog.android.rum.configuration.VitalsUpdateFrequency import com.datadog.android.rum.model.ActionEvent import com.datadog.android.rum.model.ResourceEvent @@ -24,9 +26,13 @@ import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy import com.datadog.android.telemetry.model.TelemetryConfigurationEvent import com.datadog.android.trace.TraceConfiguration import com.datadog.android.trace.TracingHeaderType -import com.datadog.tools.unit.* import com.datadog.tools.unit.GenericAssert.Companion.assertThat +import com.datadog.tools.unit.MockRumMonitor import com.datadog.tools.unit.forge.BaseConfigurator +import com.datadog.tools.unit.setStaticValue +import com.datadog.tools.unit.toReadableArray +import com.datadog.tools.unit.toReadableJavaOnlyMap +import com.datadog.tools.unit.toReadableMap import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReadableMap @@ -58,7 +64,6 @@ import fr.xgouchet.elmyr.junit5.ForgeExtension import java.net.InetSocketAddress import java.net.Proxy import java.util.Locale -import java.util.concurrent.atomic.AtomicBoolean import java.util.stream.Stream import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach @@ -317,7 +322,6 @@ internal class DdSdkTest { .hasField("featureConfiguration") { it.hasFieldEqualTo("sampleRate", expectedRumSampleRate) } - } // endregion @@ -1134,6 +1138,7 @@ internal class DdSdkTest { it.hasFieldEqualTo("userActionTracking", true) } } + @Test fun `𝕄 initialize native SDK 𝕎 initialize() {sdk verbosity}`( @Forgery configuration: DdSdkConfiguration, @@ -1257,12 +1262,12 @@ internal class DdSdkTest { verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } assertThat(rumConfigCaptor.firstValue) - .hasField("featureConfiguration") { rumConfig -> + .hasField("featureConfiguration") { rumConfig -> rumConfig.hasField("longTaskTrackingStrategy") { longTaskTrackingStrategy -> longTaskTrackingStrategy .isInstanceOf( "com.datadog.android.rum.internal.instrumentation." + - "MainLooperLongTaskStrategy" + "MainLooperLongTaskStrategy" ) .hasFieldEqualTo("thresholdMs", threshold.toLong()) } @@ -1298,7 +1303,7 @@ internal class DdSdkTest { verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } assertThat(rumConfigCaptor.firstValue) - .hasField("featureConfiguration") { rumConfig -> + .hasField("featureConfiguration") { rumConfig -> rumConfig.doesNotHaveField("longTaskTrackingStrategy") } } @@ -1378,7 +1383,7 @@ internal class DdSdkTest { Pair( forge.aStringMatching("[a-z]+\\.[a-z]{3}"), setOf( - TracingHeaderType.DATADOG, + TracingHeaderType.DATADOG ) ) } @@ -1441,9 +1446,9 @@ internal class DdSdkTest { host, setOf( TracingHeaderType.DATADOG, - TracingHeaderType.B3, + TracingHeaderType.B3 ) - ), + ) ) val firstPartyHosts = mutableListOf() @@ -1451,7 +1456,7 @@ internal class DdSdkTest { mapOf( "match" to host, "propagatorTypes" to listOf( - TracingHeaderType.DATADOG.name.lowercase(), + TracingHeaderType.DATADOG.name.lowercase() ).toReadableArray() ).toReadableMap() ) @@ -1459,7 +1464,7 @@ internal class DdSdkTest { mapOf( "match" to host, "propagatorTypes" to listOf( - TracingHeaderType.B3.name.lowercase(), + TracingHeaderType.B3.name.lowercase() ).toReadableArray() ).toReadableMap() ) @@ -1507,7 +1512,7 @@ internal class DdSdkTest { ) { // Given val bridgeConfiguration = configuration.copy( - uploadFrequency = input, + uploadFrequency = input ) val sdkConfigCaptor = argumentCaptor() val rumConfigCaptor = argumentCaptor() @@ -1546,7 +1551,7 @@ internal class DdSdkTest { ) { // Given val bridgeConfiguration = configuration.copy( - batchSize = input, + batchSize = input ) val sdkConfigCaptor = argumentCaptor() val rumConfigCaptor = argumentCaptor() @@ -1584,7 +1589,7 @@ internal class DdSdkTest { // Given val trackBackgroundEvents = forge.aNullable { forge.aBool() } val bridgeConfiguration = configuration.copy( - trackBackgroundEvents = trackBackgroundEvents, + trackBackgroundEvents = trackBackgroundEvents ) val sdkConfigCaptor = argumentCaptor() val rumConfigCaptor = argumentCaptor() @@ -1751,7 +1756,7 @@ internal class DdSdkTest { // Given val bridgeConfiguration = configuration.copy( vitalsUpdateFrequency = "AVERAGE", - longTaskThresholdMs = (threshold / 1_000_000).toDouble(), + longTaskThresholdMs = (threshold / 1_000_000).toDouble() ) val frameDurationNs = threshold + frameDurationOverThreshold @@ -1788,7 +1793,7 @@ internal class DdSdkTest { // Given val bridgeConfiguration = configuration.copy( vitalsUpdateFrequency = "NEVER", - longTaskThresholdMs = (threshold / 1_000_000).toDouble(), + longTaskThresholdMs = (threshold / 1_000_000).toDouble() ) val frameDurationNs = threshold + frameDurationOverThreshold @@ -1912,7 +1917,9 @@ internal class DdSdkTest { assertThat(rumConfigCaptor.firstValue) .hasField("featureConfiguration") { val configurationMapper = it - .getActualValue>("telemetryConfigurationMapper") + .getActualValue>( + "telemetryConfigurationMapper" + ) val result = configurationMapper.map(telemetryConfigurationEvent)!! assertThat(result.telemetry.configuration.trackNativeErrors!!).isEqualTo( trackNativeErrors @@ -1942,7 +1949,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a resource mapper that does not drop resources 𝕎 initialize() {}`( - @Forgery resourceEvent: ResourceEvent, + @Forgery resourceEvent: ResourceEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -1975,7 +1982,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a resource mapper that drops flagged resources 𝕎 initialize() {}`( - @Forgery resourceEvent: ResourceEvent, + @Forgery resourceEvent: ResourceEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -2013,7 +2020,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a action mapper that does not drop actions 𝕎 initialize() {}`( - @Forgery actionEvent: ActionEvent, + @Forgery actionEvent: ActionEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -2046,7 +2053,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a action mapper that drops flagged actions 𝕎 initialize() {}`( - @Forgery actionEvent: ActionEvent, + @Forgery actionEvent: ActionEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -2272,7 +2279,6 @@ internal class DdSdkTest { @Test fun `𝕄 build Granted consent 𝕎 buildTrackingConsent {granted}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom("granted", "GRANTED") @@ -2284,7 +2290,6 @@ internal class DdSdkTest { @Test fun `𝕄 build Pending consent 𝕎 buildTrackingConsent {pending}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom("pending", "PENDING") @@ -2296,7 +2301,6 @@ internal class DdSdkTest { @Test fun `𝕄 build Granted consent 𝕎 buildTrackingConsent {not_granted}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom("not_granted", "NOT_GRANTED") @@ -2308,7 +2312,6 @@ internal class DdSdkTest { @Test fun `𝕄 build default Pending consent 𝕎 buildTrackingConsent {any}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom(null, "some-type") @@ -2320,7 +2323,6 @@ internal class DdSdkTest { @Test fun `𝕄 call setTrackingConsent 𝕎 setTrackingConsent ()`(forge: Forge) { - // Given val consent = forge.anElementFrom("pending", "granted", "not_granted") @@ -2335,7 +2337,6 @@ internal class DdSdkTest { fun `𝕄 not build proxy config 𝕎 no proxy config specified`( @Forgery configuration: DdSdkConfiguration ) { - // Given val config = configuration.copy(additionalConfig = null) @@ -2526,7 +2527,7 @@ internal class DdSdkTest { return Stream.of( Arguments.of("SMALL", BatchSize.SMALL), Arguments.of("MEDIUM", BatchSize.MEDIUM), - Arguments.of("LARGE", BatchSize.LARGE), + Arguments.of("LARGE", BatchSize.LARGE) ) } @@ -2535,7 +2536,7 @@ internal class DdSdkTest { return Stream.of( Arguments.of("RARE", UploadFrequency.RARE), Arguments.of("AVERAGE", UploadFrequency.AVERAGE), - Arguments.of("FREQUENT", UploadFrequency.FREQUENT), + Arguments.of("FREQUENT", UploadFrequency.FREQUENT) ) } } diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt index 46d39b825..2ae8cfd50 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt @@ -2,20 +2,34 @@ package com.datadog.tools.unit import com.datadog.android.rum.RumMonitor -class MockRumMonitor: RumMonitor { +class MockRumMonitor : RumMonitor { override var debug = false override fun _getInternal(): com.datadog.android.rum._RumInternalProxy? { return null } - override fun addAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun addAction( + type: com.datadog.android.rum.RumActionType, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} override fun addAttribute(key: kotlin.String, value: kotlin.Any?): kotlin.Unit {} - override fun addError(message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, throwable: kotlin.Throwable?, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun addError( + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + throwable: kotlin.Throwable?, + attributes: kotlin.collections.Map + ): kotlin.Unit {} - override fun addErrorWithStacktrace(message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, stacktrace: kotlin.String?, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun addErrorWithStacktrace( + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + stacktrace: kotlin.String?, + attributes: kotlin.collections.Map + ): kotlin.Unit {} override fun addFeatureFlagEvaluation(name: kotlin.String, value: kotlin.Any): kotlin.Unit {} @@ -29,21 +43,62 @@ class MockRumMonitor: RumMonitor { override fun removeAttribute(key: kotlin.String): kotlin.Unit {} - override fun startAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun startResource(key: kotlin.String, method: kotlin.String, url: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun startView(key: kotlin.Any, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopResource(key: kotlin.String, statusCode: kotlin.Int?, size: kotlin.Long?, kind: com.datadog.android.rum.RumResourceKind, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopResourceWithError(key: kotlin.String, statusCode: kotlin.Int?, message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, stackTrace: kotlin.String, errorType: kotlin.String?, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopResourceWithError(key: kotlin.String, statusCode: kotlin.Int?, message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, throwable: kotlin.Throwable, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun startAction( + type: com.datadog.android.rum.RumActionType, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun startResource( + key: kotlin.String, + method: kotlin.String, + url: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun startView( + key: kotlin.Any, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopAction( + type: com.datadog.android.rum.RumActionType, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopResource( + key: kotlin.String, + statusCode: kotlin.Int?, + size: kotlin.Long?, + kind: com.datadog.android.rum.RumResourceKind, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopResourceWithError( + key: kotlin.String, + statusCode: kotlin.Int?, + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + stackTrace: kotlin.String, + errorType: kotlin.String?, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopResourceWithError( + key: kotlin.String, + statusCode: kotlin.Int?, + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + throwable: kotlin.Throwable, + attributes: kotlin.collections.Map + ): kotlin.Unit {} override fun stopSession(): kotlin.Unit {} - override fun stopView(key: kotlin.Any, attributes: kotlin.collections.Map): kotlin.Unit {} -} \ No newline at end of file + override fun stopView( + key: kotlin.Any, + attributes: kotlin.collections.Map + ): kotlin.Unit {} +} diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt index 291c840f8..49beb4465 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt @@ -81,7 +81,6 @@ inline fun getStaticValue( * @param fieldName the name of the field */ inline fun Class.getStaticValue(fieldName: String): R { - val field = getDeclaredField(fieldName) // make it accessible diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt index e39a24f3c..994f28703 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt @@ -92,7 +92,7 @@ internal class ActionEventForgeryFactory : name = forge.anAlphabeticalString(), model = forge.anAlphabeticalString(), brand = forge.anAlphabeticalString(), - type = forge.aValueFrom(ActionEvent.DeviceType::class.java), + type = forge.aValueFrom(ActionEvent.DeviceType::class.java) ), context = ActionEvent.Context( additionalProperties = mutableMapOf() diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt index 6ca158254..5294931b1 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt @@ -63,9 +63,9 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory { trackInteractions = forge.aBool(), trackNetworkRequests = forge.aBool(), reactVersion = forge.aString(), - reactNativeVersion = forge.aString(), + reactNativeVersion = forge.aString() ), - trackFrustrations = forge.aNullable { aBool() }, + trackFrustrations = forge.aNullable { aBool() } ) } } diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt index 6cfaf3930..dae18a67d 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt @@ -100,7 +100,7 @@ internal class ResourceEventForgeryFactory : name = forge.anAlphabeticalString(), model = forge.anAlphabeticalString(), brand = forge.anAlphabeticalString(), - type = forge.aValueFrom(ResourceEvent.DeviceType::class.java), + type = forge.aValueFrom(ResourceEvent.DeviceType::class.java) ), context = ResourceEvent.Context( additionalProperties = mutableMapOf()