diff --git a/library/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapper.kt b/library/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapper.kt index 0341cca25e..cf1a722f5a 100644 --- a/library/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapper.kt +++ b/library/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapper.kt @@ -14,7 +14,9 @@ internal abstract class BaseWireframeMapper { protected fun resolveViewId(view: View): Long { - return if (view.id != View.NO_ID) view.id.toLong() else view.hashCode().toLong() + // we will use the System.identityHashcode in here which always returns the default + // hashcode value whether or not a child class overrides this. + return System.identityHashCode(view).toLong() } protected fun colorAndAlphaAsStringHexa(color: Int, alphaAsHexa: Long): String { diff --git a/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/ForgeExt.kt b/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/ForgeExt.kt index 30c5547b8f..935089c3f9 100644 --- a/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/ForgeExt.kt +++ b/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/ForgeExt.kt @@ -29,7 +29,6 @@ internal fun Forge.aMockViewWithChildren( level, maxLevel ) - whenever(mockViewGroup.id).thenReturn(currentLevel * 10 + i) whenever(mockViewGroup.getChildAt(i)).thenReturn(mockChildGroup) } return mockViewGroup diff --git a/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapperTest.kt b/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapperTest.kt index 66e468dab9..533ae804a1 100644 --- a/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapperTest.kt +++ b/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/BaseWireframeMapperTest.kt @@ -30,7 +30,7 @@ internal abstract class BaseWireframeMapperTest { val x = coordinates[0].densityNormalized(fakePixelDensity).toLong() val y = coordinates[1].densityNormalized(fakePixelDensity).toLong() return MobileSegment.Wireframe.ShapeWireframe( - id.toLong(), + System.identityHashCode(this).toLong(), x = x, y = y, width = width.toLong().densityNormalized(fakePixelDensity), @@ -44,7 +44,7 @@ internal abstract class BaseWireframeMapperTest { val x = coordinates[0].densityNormalized(fakePixelDensity).toLong() val y = coordinates[1].densityNormalized(fakePixelDensity).toLong() return MobileSegment.Wireframe.TextWireframe( - id.toLong(), + System.identityHashCode(this).toLong(), x = x, y = y, text = resolveTextValue(this), diff --git a/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ViewWireframeMapperTest.kt b/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ViewWireframeMapperTest.kt index 2920b5d616..376db919e0 100644 --- a/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ViewWireframeMapperTest.kt +++ b/library/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ViewWireframeMapperTest.kt @@ -62,28 +62,10 @@ internal class ViewWireframeMapperTest : BaseWireframeMapperTest() { } @Test - fun `M default to View hashcode W map() { View and id = NO_ID}`(forge: Forge) { - // Given - val mockView: View = forge.aMockView().apply { - whenever(id).thenReturn(View.NO_ID) - // we cannot mock the hashcode method as it is final - } - - // When - val shapeWireframe = testedWireframeMapper.map(mockView, fakePixelDensity) - - // Then - val expectedWireframe = mockView.toShapeWireframe().copy(id = mockView.hashCode().toLong()) - assertThat(shapeWireframe).isEqualTo(expectedWireframe) - } - - @Test - fun `M use the View hashcode for Wireframe id W produce() { id is not valid }`(forge: Forge) { + fun `M use the View hashcode for Wireframe id W produce()`(forge: Forge) { // Given val mockViews = forge.aList(size = forge.anInt(min = 10, max = 20)) { - val mockRoot = aMockView() - whenever(mockRoot.id).thenReturn(View.NO_ID) - mockRoot + aMockView() } // When