Skip to content

Commit f602b9b

Browse files
Minor improvements to unit tests
1 parent be663eb commit f602b9b

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

dd-sdk-android-internal/src/main/java/com/datadog/android/internal/utils/ImageViewUtils.kt

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import android.view.View
1212
import android.widget.ImageView
1313

1414
object ImageViewUtils {
15+
/**
16+
* Resolves the absolute position on the screen of the given [View].
17+
* @param view: the [View].
18+
* @return the [Rect] representing the absolute position of the view.
19+
*/
1520
fun resolveParentRectAbsPosition(view: View): Rect {
1621
val coords = IntArray(2)
1722
// this will always have size >= 2
@@ -29,6 +34,14 @@ object ImageViewUtils {
2934
)
3035
}
3136

37+
/**
38+
* Calculates the clipping [Rect] of the given child [Rect] using its parent [Rect] and
39+
* the screen density.
40+
* @param parentRect: the parent [Rect].
41+
* @param childRect: the child [Rect].
42+
* @param density: the screen density.
43+
* @return the clipping [Rect].
44+
*/
3245
fun calculateClipping(parentRect: Rect, childRect: Rect, density: Float): Rect {
3346
val left = if (childRect.left < parentRect.left) {
3447
parentRect.left - childRect.left
@@ -58,6 +71,12 @@ object ImageViewUtils {
5871
)
5972
}
6073

74+
/**
75+
* Resolves the [Drawable] content [Rect] using the given [ImageView] scale type.
76+
* @param imageView: the [ImageView].
77+
* @param drawable: the [Drawable].
78+
* @return the resolved content [Rect].
79+
*/
6180
fun resolveContentRectWithScaling(
6281
imageView: ImageView,
6382
drawable: Drawable

features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/utils/RectExt.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ internal fun Rect.toWireframeClip(): MobileSegment.WireframeClip {
1616
this.left.toLong(),
1717
this.right.toLong()
1818
)
19-
}
19+
}

features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapper.kt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import androidx.annotation.UiThread
1111
import com.datadog.android.api.InternalLogger
1212
import com.datadog.android.internal.utils.ImageViewUtils
1313
import com.datadog.android.internal.utils.densityNormalized
14-
import com.datadog.android.sessionreplay.SessionReplay
1514
import com.datadog.android.sessionreplay.internal.utils.toWireframeClip
1615
import com.datadog.android.sessionreplay.model.MobileSegment
1716
import com.datadog.android.sessionreplay.recorder.MappingContext

features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/resources/DefaultImageWireframeHelperTest.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,8 @@ internal class DefaultImageWireframeHelperTest {
891891
customResourceIdCacheKey = null,
892892
asyncJobStatusCallback = mockAsyncJobStatusCallback
893893
)
894-
wireframes[0] as MobileSegment.Wireframe.ImageWireframe
894+
895+
assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)
895896

896897
// Then
897898
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()
@@ -939,7 +940,8 @@ internal class DefaultImageWireframeHelperTest {
939940
customResourceIdCacheKey = null,
940941
asyncJobStatusCallback = mockAsyncJobStatusCallback
941942
)
942-
wireframes[0] as MobileSegment.Wireframe.ImageWireframe
943+
944+
assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)
943945

944946
// Then
945947
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()
@@ -1270,7 +1272,8 @@ internal class DefaultImageWireframeHelperTest {
12701272
customResourceIdCacheKey = null,
12711273
asyncJobStatusCallback = mockAsyncJobStatusCallback
12721274
)
1273-
wireframes[0] as MobileSegment.Wireframe.ImageWireframe
1275+
1276+
assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)
12741277

12751278
// Then
12761279
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()
@@ -1318,7 +1321,8 @@ internal class DefaultImageWireframeHelperTest {
13181321
customResourceIdCacheKey = null,
13191322
asyncJobStatusCallback = mockAsyncJobStatusCallback
13201323
)
1321-
wireframes[0] as MobileSegment.Wireframe.ImageWireframe
1324+
1325+
assertThat(wireframes[0]).isInstanceOf(MobileSegment.Wireframe.ImageWireframe::class.java)
13221326

13231327
// Then
13241328
val argumentCaptor = argumentCaptor<ResourceResolverCallback>()

0 commit comments

Comments
 (0)