-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
2,198 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/tracking/BundleExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.rum.tracking | ||
|
||
import android.os.Bundle | ||
|
||
internal const val ARGUMENT_TAG = "view.arguments" | ||
|
||
/** | ||
* Converts this bundle into a Map of attributes to be included in a RUM View event. | ||
*/ | ||
fun Bundle?.convertToRumViewAttributes(): Map<String, Any?> { | ||
if (this == null) return emptyMap() | ||
|
||
val attributes = mutableMapOf<String, Any?>() | ||
|
||
keySet().forEach { | ||
// TODO RUM-503 Bundle#get is deprecated, but there is no replacement for it. | ||
// Issue is opened in the Google Issue Tracker. | ||
@Suppress("DEPRECATION") | ||
attributes["$ARGUMENT_TAG.$it"] = get(it) | ||
} | ||
|
||
return attributes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...ures/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/tracking/BundleExtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.datadog.android.rum.tracking | ||
|
||
import android.os.Bundle | ||
import com.datadog.android.rum.utils.forge.Configurator | ||
import fr.xgouchet.elmyr.Forge | ||
import fr.xgouchet.elmyr.junit5.ForgeConfiguration | ||
import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.api.extension.Extensions | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.junit.jupiter.MockitoSettings | ||
import org.mockito.quality.Strictness | ||
|
||
@Extensions( | ||
ExtendWith(ForgeExtension::class), | ||
ExtendWith(MockitoExtension::class) | ||
) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
@ForgeConfiguration(Configurator::class) | ||
class BundleExtTest { | ||
@Test | ||
fun `M return empty map W convertToRumViewAttributes() {null bundle}`() { | ||
// Given | ||
val bundle: Bundle? = null | ||
|
||
// When | ||
val result = bundle.convertToRumViewAttributes() | ||
|
||
// Then | ||
|
||
assertThat(result).isEmpty() | ||
} | ||
|
||
@Test | ||
fun `M return empty map W convertToRumViewAttributes() {empty bundle}`() { | ||
// Given | ||
val bundle = Bundle() | ||
|
||
// When | ||
val result = bundle.convertToRumViewAttributes() | ||
|
||
// Then | ||
|
||
assertThat(result).isEmpty() | ||
} | ||
|
||
@Test | ||
fun `M return map with String attributes W convertToRumViewAttributes() {bundle}`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val expectedAttributes = mutableMapOf<String, Any?>() | ||
val bundle = Bundle() | ||
repeat(forge.aSmallInt()) { | ||
val key = forge.anAlphabeticalString() | ||
val value = forge.aNullable { aString() } | ||
bundle.putString(key, value) | ||
expectedAttributes["view.arguments.$key"] = value | ||
} | ||
|
||
// When | ||
val result = bundle.convertToRumViewAttributes() | ||
|
||
// Then | ||
assertThat(result).isEqualTo(expectedAttributes) | ||
} | ||
|
||
@Test | ||
fun `M return map with Int attributes W convertToRumViewAttributes() {bundle}`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val expectedAttributes = mutableMapOf<String, Any?>() | ||
val bundle = Bundle() | ||
repeat(forge.aSmallInt()) { | ||
val key = forge.anAlphabeticalString() | ||
val value = forge.anInt() | ||
bundle.putInt(key, value) | ||
expectedAttributes["view.arguments.$key"] = value | ||
} | ||
|
||
// When | ||
val result = bundle.convertToRumViewAttributes() | ||
|
||
// Then | ||
assertThat(result).isEqualTo(expectedAttributes) | ||
} | ||
} |
Oops, something went wrong.