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

Update dependency org.robolectric:robolectric to v4.9 #1483

Merged
merged 4 commits into from Sep 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 22 additions & 28 deletions coil-base/src/test/java/coil/drawable/CrossfadeDrawableTest.kt
@@ -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
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