Skip to content

Commit

Permalink
Update dependency org.robolectric:robolectric to v4.9 (#1483)
Browse files Browse the repository at this point in the history
* Update dependency org.robolectric:robolectric to v4.9

* Delete robolectric.properties.

* Docs.

* Fix tests.

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Colin White <colin@colinwhite.me>
  • Loading branch information
renovate[bot] and colinrtwhite authored Sep 30, 2022
1 parent 6ac3596 commit 0cdcb59
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
50 changes: 22 additions & 28 deletions coil-base/src/test/java/coil/drawable/CrossfadeDrawableTest.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package coil.drawable

import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import androidx.core.graphics.createBitmap
import androidx.test.core.app.ApplicationProvider
import coil.size.Scale
import coil.util.createBitmap
import coil.util.toDrawable
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

@RunWith(RobolectricTestRunner::class)
class CrossfadeDrawableTest {
Expand Down Expand Up @@ -162,37 +163,22 @@ class CrossfadeDrawableTest {
}

@Test
fun `alpha change should not change alpha of original start drawable`() {
fun `start and end drawables are mutated`() {
val startDrawable = TestBitmapDrawable(100, 100)
val endDrawable = TestBitmapDrawable(100, 100)
assertEquals(0, startDrawable.alpha)
assertFalse(startDrawable.mutated)
assertFalse(endDrawable.mutated)

val crossfadeDrawable = CrossfadeDrawable(startDrawable, endDrawable)
crossfadeDrawable.alpha = 255
crossfadeDrawable.draw(Canvas())

assertEquals(0, startDrawable.alpha)
}

@Test
fun `alpha change should not change alpha of original end drawable`() {
val startDrawable = TestBitmapDrawable(100, 100)
val endDrawable = TestBitmapDrawable(100, 100)
assertEquals(0, endDrawable.alpha)

val crossfadeDrawable = CrossfadeDrawable(startDrawable, endDrawable)
crossfadeDrawable.alpha = 255
crossfadeDrawable.stop()
crossfadeDrawable.draw(Canvas())

assertEquals(0, endDrawable.alpha)
CrossfadeDrawable(startDrawable, endDrawable)
assertTrue(startDrawable.mutated)
assertTrue(endDrawable.mutated)
}

@Test
fun `preferExactIntrinsicSize=false`() {
val drawable1 = CrossfadeDrawable(
start = ColorDrawable(),
end = createBitmap().toDrawable(context),
end = createBitmap(100, 100).toDrawable(context),
preferExactIntrinsicSize = false
)

Expand All @@ -201,7 +187,7 @@ class CrossfadeDrawableTest {

val drawable2 = CrossfadeDrawable(
start = null,
end = createBitmap().toDrawable(context),
end = createBitmap(100, 100).toDrawable(context),
preferExactIntrinsicSize = false
)

Expand All @@ -213,7 +199,7 @@ class CrossfadeDrawableTest {
fun `preferExactIntrinsicSize=true`() {
val drawable1 = CrossfadeDrawable(
start = ColorDrawable(),
end = createBitmap().toDrawable(context),
end = createBitmap(100, 100).toDrawable(context),
preferExactIntrinsicSize = true
)

Expand All @@ -222,7 +208,7 @@ class CrossfadeDrawableTest {

val drawable2 = CrossfadeDrawable(
start = null,
end = createBitmap().toDrawable(context),
end = createBitmap(100, 100).toDrawable(context),
preferExactIntrinsicSize = true
)

Expand All @@ -234,15 +220,23 @@ class CrossfadeDrawableTest {
private val width: Int,
private val height: Int
) : ColorDrawable() {
var mutated = false
private set

override fun getIntrinsicWidth() = width
override fun getIntrinsicHeight() = height
override fun mutate() = super.mutate().also { mutated = true }
}

private inner class TestBitmapDrawable(
private val width: Int,
private val height: Int
) : BitmapDrawable(context.resources, createBitmap()) {
) : BitmapDrawable(context.resources, createBitmap(width, height)) {
var mutated = false
private set

override fun getIntrinsicWidth() = width
override fun getIntrinsicHeight() = height
override fun mutate() = super.mutate().also { mutated = true }
}
}
1 change: 0 additions & 1 deletion coil-test/src/main/resources/robolectric.properties

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ okhttp-mockwebserver = { module = "com.squareup.okhttp3:mockwebserver", version.
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
okio-fakefilesystem = { module = "com.squareup.okio:okio-fakefilesystem", version.ref = "okio" }

robolectric = "org.robolectric:robolectric:4.8.2"
robolectric = "org.robolectric:robolectric:4.9"

svg = "com.caverock:androidsvg-aar:1.4"

Expand Down

0 comments on commit 0cdcb59

Please sign in to comment.