1
0
Fork 0
fenix/app/src/test/java/org/mozilla/fenix/ext/DrawableTest.kt

45 lines
1.3 KiB
Kotlin
Raw Normal View History

package org.mozilla.fenix.ext
import org.mozilla.fenix.TestApplication
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import android.graphics.drawable.Drawable
import android.graphics.Rect
import android.graphics.Canvas
import android.graphics.ColorFilter
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class DrawableTest {
@Test
fun testSetBounds() {
val drawable = TestDrawable()
assertFalse(drawable.boundsChanged)
val size = 10
drawable.setBounds(size)
assertTrue(drawable.boundsChanged)
val returnRec = drawable.copyBounds()
assertTrue(returnRec.contains(0, 0, -10, 10))
}
2019-09-12 20:14:34 +02:00
private class TestDrawable : Drawable() {
var boundsChanged: Boolean = false
2019-09-12 20:14:34 +02:00
override fun getOpacity(): Int {
return 0
}
override fun draw(canvas: Canvas) {}
override fun setAlpha(alpha: Int) {}
override fun setColorFilter(cf: ColorFilter) {}
2019-09-12 20:14:34 +02:00
override fun onBoundsChange(bounds: Rect) {
boundsChanged = true
super.onBoundsChange(bounds)
}
}
}