Skip to content

Commit bf7e7da

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

File tree

5 files changed

+33
-30
lines changed

5 files changed

+33
-30
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ import android.graphics.drawable.Drawable
1111
import android.view.View
1212
import android.widget.ImageView
1313

14+
/**
15+
* A collection of view utility functions for resolving absolute
16+
* positions, clipping bounds, and other useful data for
17+
* image views operations.
18+
*/
1419
object ImageViewUtils {
20+
/**
21+
* Resolves the absolute position on the screen of the given [View].
22+
* @param view: the [View].
23+
* @return the [Rect] representing the absolute position of the view.
24+
*/
1525
fun resolveParentRectAbsPosition(view: View): Rect {
1626
val coords = IntArray(2)
1727
// this will always have size >= 2
@@ -29,6 +39,14 @@ object ImageViewUtils {
2939
)
3040
}
3141

42+
/**
43+
* Calculates the clipping [Rect] of the given child [Rect] using its parent [Rect] and
44+
* the screen density.
45+
* @param parentRect: the parent [Rect].
46+
* @param childRect: the child [Rect].
47+
* @param density: the screen density.
48+
* @return the clipping [Rect].
49+
*/
3250
fun calculateClipping(parentRect: Rect, childRect: Rect, density: Float): Rect {
3351
val left = if (childRect.left < parentRect.left) {
3452
parentRect.left - childRect.left
@@ -58,6 +76,12 @@ object ImageViewUtils {
5876
)
5977
}
6078

79+
/**
80+
* Resolves the [Drawable] content [Rect] using the given [ImageView] scale type.
81+
* @param imageView: the [ImageView].
82+
* @param drawable: the [Drawable].
83+
* @return the resolved content [Rect].
84+
*/
6185
fun resolveContentRectWithScaling(
6286
imageView: ImageView,
6387
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>()

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

-24
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.mockito.kotlin.any
3333
import org.mockito.kotlin.argumentCaptor
3434
import org.mockito.kotlin.doAnswer
3535
import org.mockito.kotlin.mock
36-
import org.mockito.kotlin.never
3736
import org.mockito.kotlin.verify
3837
import org.mockito.kotlin.whenever
3938
import org.mockito.quality.Strictness
@@ -372,29 +371,6 @@ internal class DrawableUtilsTest {
372371
assertThat(displayMetricsCaptor.firstValue).isEqualTo(mockDisplayMetrics)
373372
}
374373

375-
@Test
376-
fun `M uses original drawable W createBitmapOfApproxSizeFromDrawable`() {
377-
// Given
378-
whenever(mockDrawable.intrinsicWidth).thenReturn(1)
379-
whenever(mockDrawable.intrinsicHeight).thenReturn(1)
380-
381-
// When
382-
testedDrawableUtils.createBitmapOfApproxSizeFromDrawable(
383-
drawable = mockDrawable,
384-
drawableWidth = mockDrawable.intrinsicWidth,
385-
drawableHeight = mockDrawable.intrinsicHeight,
386-
displayMetrics = mockDisplayMetrics,
387-
config = mockConfig,
388-
bitmapCreationCallback = mockBitmapCreationCallback
389-
)
390-
391-
// Then
392-
verify(mockDrawable).setBounds(any(), any(), any(), any())
393-
verify(mockDrawable).draw(any())
394-
verify(mockSecondDrawable, never()).setBounds(any(), any(), any(), any())
395-
verify(mockSecondDrawable, never()).draw(any())
396-
}
397-
398374
@Test
399375
fun `M return scaled bitmap W createScaledBitmap()`(
400376
@Mock mockScaledBitmap: Bitmap

0 commit comments

Comments
 (0)