Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-2494 Use View hashcode as unique identifier for mapped Wireframe #1037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ internal abstract class BaseWireframeMapper<T : View, S : MobileSegment.Wirefram
WireframeMapper<T, S> {

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<View>().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<View>()
whenever(mockRoot.id).thenReturn(View.NO_ID)
mockRoot
aMockView<View>()
}

// When
Expand Down